chore: replace all cn comments of fe to en version by volc api (#320)

This commit is contained in:
tecvan
2025-07-31 10:32:15 +08:00
committed by GitHub
parent 716ec0cba8
commit 71f6245a01
2960 changed files with 15545 additions and 15545 deletions

View File

@@ -47,13 +47,13 @@ it('limit rate', async () => {
await vi.advanceTimersByTimeAsync(1000);
expect(request.mock.calls.length).toBe(7);
// 离开窗口
// Leave the window
await vi.advanceTimersByTimeAsync(5000);
limiter.invoke();
limiter.invoke();
limiter.invoke();
expect(request.mock.calls.length).toBe(10);
// 进入限流
// Access to limited viewership of
limiter.invoke();
await vi.advanceTimersByTimeAsync(100);
expect(request.mock.calls.length).toBe(10);

View File

@@ -15,7 +15,7 @@
*/
/**
* 检查没有遗漏的项
* Check for no missing items
*/
export const exhaustiveCheckForRecord = (_: Record<string, never>) => undefined;

View File

@@ -17,8 +17,8 @@
import { isObject } from 'lodash-es';
/**
* @param inputError 传啥都行,一般是 catch (e) 那个 e
* @param reason 多余的解释,我感觉有 eventName 了没啥用
* @param inputError can pass anything, usually catch (e) that e.
* @param reason redundant explanation, I feel there is eventName, it's useless
*/
export const getReportError = (
inputError: unknown,

View File

@@ -19,7 +19,7 @@ import bigInt, { max, min } from 'big-integer';
export const sortInt64CompareFn = (a: string, b: string) =>
bigInt(a).compare(b);
/** O(1) 遍历 */
/** O (1) Traversal */
export const getMinMax = (...nums: string[]) => {
const num = nums.at(0);
if (num === undefined) {

View File

@@ -27,7 +27,7 @@ export const typeSafeJsonParse = (
};
/**
* 泛型类型标注可能需要使用 type 声明,
* Generic type annotations may require the use of type declarations.
* refer: https://github.com/microsoft/TypeScript/issues/15300.
*/
export const typeSafeJsonParseEnhanced = <T>({
@@ -39,12 +39,12 @@ export const typeSafeJsonParseEnhanced = <T>({
str: string;
onParseError: (error: Error) => void;
/**
* 实现一个类型校验,返回是否通过(boolean);实际上还是靠自觉.
* 可以单独定义, 也可以写作内联 function, 但是注意返回值标注为 predicate,
* Implement a type check that returns whether it passes (boolean); in fact, it depends on self-awareness.
* It can be defined separately or written as an internal connection function, but note that the return value is marked as predicate,
* refer: https://github.com/microsoft/TypeScript/issues/38390.
*/
verifyStruct: (sth: unknown) => sth is T;
/** 错误原因: 校验崩溃; 校验未通过 */
/** Error cause: validation crashed; validation failed */
onVerifyError: (error: Error) => void;
}): T | null => {
const res = typeSafeJsonParse(str, onParseError);

View File

@@ -17,9 +17,9 @@
import { type Text, type Link, type Parent, type Image } from 'mdast';
import { isObject, isUndefined } from 'lodash-es';
/**
* 将markdown转为纯文本
* @param markdown Markdown文本
* @returns string 纯文本
* Convert markdown to plain text
* @param markdown Markdown text
* @Returns string plain text
*/
export const getTextFromAst = (ast: unknown): string => {
if (isParent(ast)) {

View File

@@ -19,18 +19,18 @@ import { sleep } from './async';
type Fn<ARGS extends unknown[], Ret = unknown> = (...args: ARGS) => Ret;
/**
* 限流器,对于被限流的异步方法进行以下形式的限流:
* 1. 在 timeWindow 内的前 limit 个请求不做限制,立即发送
* 2. timeWindow 内超过 limit 个请求后,对每个请求依次添加 onLimitDelay 毫秒的延迟
* Limit viewership of asynchronous methods with limited viewership of the form:
* 1. The first limited requests in timeWindow are not limited and sent immediately
* 2. After more than the limit of requests in timeWindow, add onLimitDelay millisecond delay to each request in turn
*
* 注意是排队添加,形如 invoke: [1(0ms), 2(0ms), 3(0ms), 4(0ms)]; limit: [1(0ms), 2(0ms), 3(100ms), 4(200ms)]
* Note that the queue is added, as invoked: [1 (0ms), 2 (0ms), 3 (0ms), 4 (0ms) ]; limit: [1 (0ms), 2 (0ms), 3 (100ms), 4 (200ms) ]
*
* 另注:这个设计遭到了猛烈抨击,认为 debounce 可以代替掉,实现过于复杂,但是考虑:
* 1. 支持列表双向加载的拉取,简单使用 debounce 可能导致请求某侧丢失;添加延时可以保证不丢失请求
* 2. 列表拉取一旦出现死循环,可能导致恶性问题,如密集地对服务端接口的高频访问
* Another note: This design has been slammed, arguing that debounce can be replaced and the implementation is too complex, but consider:
* 1. Support the pull of the list loaded in both directions. Simple use of debounce may cause the request to be lost on one side; adding a delay can ensure that the request is not lost
* 2. Once the list is pulled, it may lead to malignant problems, such as dense high-frequency access to the server level interface
*
* 以上场景通常不应出现,所以 limit 设计也只是对极端场景的兜底,上层 UI 错误理应得到妥善解决
* TODO: wlt - 补充 testcase
* The above scenarios should not usually appear, so the limited design is only a cover for extreme scenarios, and the upper UI errors should be properly resolved
* TODO: wlt - supplementary testcase
*/
export class RateLimit<ARGS extends unknown[], Ret> {
constructor(

View File

@@ -15,7 +15,7 @@
*/
/**
* 非线上环境阻塞;构建后仅做异常输出和异步抛出错误
* Off-line environment blocking; only exception output and asynchronous errors are thrown after build
*/
export const safeAsyncThrow = (e: string) => {
const err = new Error(`[chat-area] ${e}`);

View File

@@ -13,8 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- 不知道为啥 unknown 不行,会导致类型转换失败
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- I don't know why unknown doesn't work, it will cause type conversion to fail
export type MakeValueUndefinable<T extends Record<string, any>> = {
[k in keyof T]: T[k] | undefined;
};

View File

@@ -17,8 +17,8 @@
import { isUndefined, omitBy } from 'lodash-es';
/**
* zustand update 辅助方法,检查入参对象,丢弃 value 为 undefined 的项.
* zustand 自身没有过滤逻辑,如果类型没有问题,可能意外地将项目置为 undefined
* Zustand updates helper methods, checking imported parameter objects, discarding items with undefined values.
* Zustand itself has no filtering logic. If there is no problem with the type, it may accidentally set the item to an undefined value
*/
export const updateOnlyDefined = <T extends Record<string, unknown>>(
updater: (sth: T) => void,