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

@@ -20,20 +20,20 @@ import type { IMeta, CustomAPIMeta } from './types';
export interface ApiLike<T, K, O = unknown, B extends boolean = false> {
(req: T, option?: O extends object ? IOptions & O : IOptions): Promise<K>;
meta: IMeta;
/** fork 一份实例,该实例具有可中止请求的能力 */
/** Fork an instance that has the ability to abort requests */
withAbort: () => CancelAbleApi<T, K, O, B>;
}
export interface CancelAbleApi<T, K, O = unknown, B extends boolean = false>
extends ApiLike<T, K, O, B> {
// 中止请求
// abort request
abort: () => void;
// 是否是取消
// Is it cancelled?
isAborted: () => boolean;
}
/**
* 自定义构建 api 方法
* Custom build API method
* @param meta
* @param cancelable
* @param useCustom
@@ -56,7 +56,7 @@ export function createAPI<T extends {}, K, O = unknown, B extends boolean = fals
option = { ...(option || {}), ...customOption };
// 这里可以使用传进来的 req 作为默认映射,减少需要在 customAPI 中,需要手动绑定的情况
// Here, you can use the incoming req as the default mapping to reduce the need for manual binding in the customAPI
if (useCustom) {
const mappingKeys: string[] = Object.keys(meta.reqMapping)
.map(key => meta.reqMapping[key])
@@ -98,12 +98,12 @@ export function createAPI<T extends {}, K, O = unknown, B extends boolean = fals
function abort() {
/**
* 这里加上 pending 状态的原因是abortController.signal 的状态值只受控于 abortController.abort() 方法;
* 不管请求是否完成或者异常,只要调用 abortController.abort(), abortController.signal.aborted 必定为 true
* 这样不好判断请求是否真 aborted
* The reason for adding the pending state here is that the state value of abortController.signal is only controlled by the abortController.abort () method;
* No matter whether the request is completed or abnormal, as long as abortController.abort () is called, abortController.signal.aborted must be true.
* This makes it difficult to determine whether the request is really aborted.
*
* 这里改为,只有在请求 pending 的情况下,可执行 abort()
* isAborted === true 时,请求异常必定是因为手动 abort 导致的
* This is changed to abort () only if the request is pending.
* When isAborted === true, the request exception must be caused by manual abort
*/
if (pending === true && cancelable && abortController) {
abortController.abort();
@@ -128,7 +128,7 @@ export function createAPI<T extends {}, K, O = unknown, B extends boolean = fals
}
/**
* 一些非泛化的接口,可以使用改方法构建,方便统一管理接口
* Some non-generalized interfaces can be built using modified methods to facilitate unified management of interfaces
* @param customAPIMeta
* @param cancelable
* @returns

View File

@@ -30,11 +30,11 @@ export interface IMeta {
type Fields = string[];
export interface IHttpRpcMapping {
path?: Fields; // path参数
query?: Fields; // query参数
body?: Fields; // body 参数
header?: Fields; // header 参数
status_code?: Fields; // http状态码
path?: Fields; // path parameter
query?: Fields; // query parameters
body?: Fields; // Body parameters
header?: Fields; // header parameter
status_code?: Fields; // HTTP status code
cookie?: Fields; // cookie
entire_body?: Fields;
raw_body?: Fields;

View File

@@ -27,22 +27,22 @@ export interface ServiceConfig {
} & Omit<IdlConfig, 'clientFactory'>;
}
export interface IdlConfig {
// client 工厂方法,要求返回一个 fetchClient 函数,使用 meta 总的信息,可实现灵活的 client 配置
// The client factory method requires a fetchClient function to be returned, which uses the meta total information to achieve flexible client configuration
clientFactory?: (
meta: IMeta,
) => (uri: string, init: RequestInit, opt: any) => any;
// uri 前缀,如果 client 中设置了,这里可以不设置
// URI prefix, if set in client, you can leave it unset here
uriPrefix?: string;
getParams?: (key: string) => string;
// 服务级别的配置
// Service level configuration
services?: ServiceConfig;
// 开发时,如果本地校验失败,这里可回调,通常是弹 toast
// During development, if the local verification fails, it can be called back here, usually by playing toast.
onVerifyReqError?: (message: string, ctx: any) => void;
}
export interface IOptions {
config?: IdlConfig;
// 透传 request options 的选项
// Passthrough request options
requestOptions?: Record<string, any>;
[key: string]: any;
}
@@ -52,7 +52,7 @@ export interface PathPrams<T> {
}
export function getConfig(service: string, method: string): IdlConfig {
// 手动注册的配置优先级比全局变量高
// Manually registered configuration takes precedence over global variables
let config: IdlConfig | undefined = configCenter.getConfig(service);
if (!config) {
config = {};
@@ -137,7 +137,7 @@ export function normalizeRequest(
);
const { uriPrefix = '', clientFactory } = config;
if (!clientFactory) {
// todo 这里考虑给个默认的 client防止某些公共 package 在一些异常情况下使用
// Todo here considers giving a default client to prevent some public packages from being used in some abnormal cases
throw new Error('Lack of clientFactory config');
}
let uri = uriPrefix + apiUri;
@@ -149,11 +149,11 @@ export function normalizeRequest(
: 'application/json';
if (option?.requestOptions?.headers) {
headers = { ...headers, ...option.requestOptions.headers };
// 合并了 header,可删除
// Merged headers, can be deleted
delete option.requestOptions.headers;
}
if (meta.reqMapping.query && meta.reqMapping.query.length > 0) {
// 这里默认 skipNulls网关后端需要忽略 null
// The default here is skipNulls, and the gateway backend needs to ignore null.
uri = `${uri}?${qs.stringify(getValue(req, meta.reqMapping.query), {
skipNulls: true,
arrayFormat: 'comma',
@@ -168,7 +168,7 @@ export function normalizeRequest(
if (meta.reqMapping.entire_body && meta.reqMapping.entire_body.length > 0) {
if (meta.reqMapping.entire_body.length === 1) {
// 默认处理为 json ,如有其他场景需要支持,后需要再支持
// The default processing is json. If there are other scenarios that need to be supported, they need to be supported later.
requestOption.body = req[meta.reqMapping.entire_body[0]];
} else {
throw new Error('idl invalid entire_body should be only one filed');
@@ -203,7 +203,7 @@ export function normalizeRequest(
};
}
// 旧版的 ferry 中,即使 idl 没有声明body也需要加一个 空的 body
// In the old version of ferry, even if idl does not declare body, you need to add an empty body.
if (
!requestOption.body &&
['POST', 'PUT', 'PATCH'].includes(