Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🌐 chore: translate non-English comments to English in utils/server (#10057)

LobeHub Botd17b07fda9be
diff --git a/packages/utils/src/server/auth.ts b/packages/utils/src/server/auth.ts
index 1f8981df8fa..496ff0ad971 100644
--- a/packages/utils/src/server/auth.ts
+++ b/packages/utils/src/server/auth.ts
@@ -29,9 +29,9 @@ export const getUserAuth = async () => {
};
/**
- * 从授权头中提取 Bearer Token
- * @param authHeader - 授权头 (例如 "Bearer xxx")
- * @returns Bearer Token 或 null(如果授权头无效或不存在)
+ * Extract Bearer Token from authorization header
+ * @param authHeader - Authorization header (e.g. "Bearer xxx")
+ * @returns Bearer Token or null (if authorization header is invalid or does not exist)
*/
export const extractBearerToken = (authHeader?: string | null): string | null => {
if (!authHeader) return null;
@@ -51,9 +51,9 @@ export const extractBearerToken = (authHeader?: string | null): string | null =>
};
/**
- * 从 Oidc-Auth header 中提取 JWT token
- * @param authHeader - Oidc-Auth header 值 (例如 "Oidc-Auth xxx")
- * @returns JWT token 或 null(如果授权头无效或不存在)
+ * Extract JWT token from Oidc-Auth header
+ * @param authHeader - Oidc-Auth header value (e.g. "Oidc-Auth xxx")
+ * @returns JWT token or null (if authorization header is invalid or does not exist)
*/
export const extractOidcAuthToken = (authHeader?: string | null): string | null => {
if (!authHeader) return null;
diff --git a/packages/utils/src/server/geo.ts b/packages/utils/src/server/geo.ts
index eeaaa43728b..f78854679bd 100644
--- a/packages/utils/src/server/geo.ts
+++ b/packages/utils/src/server/geo.ts
@@ -13,19 +13,19 @@ const getLocalTime = (timeZone: string) => {
const isValidTimeZone = (timeZone: string) => {
try {
getLocalTime(timeZone);
- return true; // 如果没抛异常,说明时区有效
+ return true; // If no exception is thrown, the timezone is valid
} catch (e) {
- // 捕获到 RangeError,说明时区无效
+ // If a RangeError is caught, the timezone is invalid
if (e instanceof RangeError) {
return false;
}
- // 如果是其他错误,最好重新抛出
+ // If it's another error, better to re-throw it
throw e;
}
};
export const parseDefaultThemeFromCountry = (request: NextRequest) => {
- // 1. 从请求头中获取国家代码
+ // 1. Get country code from request headers
const geo = geolocation(request);
const countryCode =
@@ -35,22 +35,22 @@ export const parseDefaultThemeFromCountry = (request: NextRequest) => {
request.headers.get('x-zeabur-ip-country') || // Zeabur
request.headers.get('x-country-code'); // Netlify
- // 如果没有获取到国家代码,直接返回 light 主题
+ // If no country code is obtained, return light theme directly
if (!countryCode) return 'light';
- // 2. 获取国家的时区信息
+ // 2. Get timezone information for the country
const country = getCountry(countryCode);
- // 如果找不到国家信息或该国家没有时区信息,返回 light 主题
+ // If country information is not found or the country has no timezone information, return light theme
if (!country?.timezones?.length) return 'light';
const timeZone = country.timezones.find((tz) => isValidTimeZone(tz));
if (!timeZone) return 'light';
- // 3. 获取该国家的第一个 时区下的当前时间
+ // 3. Get the current time in the country's first timezone
const localTime = getLocalTime(timeZone);
- // 4. 解析小时数并确定主题
+ // 4. Parse the hour and determine the theme
const localHour = parseInt(localTime);
// console.log(
// `[theme] Country: ${countryCode}, Timezone: ${country.timezones[0]}, LocalHour: ${localHour}`,
diff --git a/packages/utils/src/server/xor.ts b/packages/utils/src/server/xor.ts
index 5c6c02bc649..29ecb2dbef6 100644
--- a/packages/utils/src/server/xor.ts
+++ b/packages/utils/src/server/xor.ts
@@ -3,15 +3,15 @@ import { ClientSecretPayload } from '@lobechat/types';
import { SECRET_XOR_KEY } from '@/const/auth';
/**
- * 将 Base64 字符串转换为 Uint8Array
+ * Convert Base64 string to Uint8Array
*/
const base64ToUint8Array = (base64: string): Uint8Array => {
- // Node.js 环境下直接使用 Buffer
+ // Use Buffer directly in Node.js environment
return Buffer.from(base64, 'base64');
};
/**
- * 对 Uint8Array 进行 XOR 运算 (与客户端的 xorProcess 函数相同)
+ * Perform XOR operation on Uint8Array (same as the client-side xorProcess function)
*/
const xorProcess = (data: Uint8Array, key: Uint8Array): Uint8Array => {
const result = new Uint8Array(data.length);
@@ -22,7 +22,7 @@ const xorProcess = (data: Uint8Array, key: Uint8Array): Uint8Array => {
};
/**
- * 将 Uint8Array 转换为字符串 (UTF-8 解码)
+ * Convert Uint8Array to string (UTF-8 decoding)
*/
const uint8ArrayToString = (arr: Uint8Array): string => {
return new TextDecoder().decode(arr);
@@ -31,13 +31,13 @@ const uint8ArrayToString = (arr: Uint8Array): string => {
export const getXorPayload = (token: string): ClientSecretPayload => {
const keyBytes = new TextEncoder().encode(SECRET_XOR_KEY);
- // 1. Base64 解码
+ // 1. Base64 decoding
const base64DecodedBytes = base64ToUint8Array(token);
- // 2. XOR 解混淆
+ // 2. XOR deobfuscation
const xorDecryptedBytes = xorProcess(base64DecodedBytes, keyBytes);
- // 3. 转换为字符串并解析 JSON
+ // 3. Convert to string and parse JSON
const decodedJsonString = uint8ArrayToString(xorDecryptedBytes);
return JSON.parse(decodedJsonString) as ClientSecretPayload;