chore(comment): 注释改为英文

This commit is contained in:
dayjoy
2025-09-30 14:27:53 +08:00
parent 2651bd1373
commit 2341e36aa9
11 changed files with 41 additions and 45 deletions

View File

@@ -5,8 +5,7 @@ interface RequestOptions extends RequestInit {
}
/**
* 统一的fetch请求封装
* 自动添加Authorization头部
* Unified fetch wrapper that adds auth and group headers
*/
export const apiRequest = async <T = any>(
endpoint: string,
@@ -17,34 +16,34 @@ export const apiRequest = async <T = any>(
const url = endpoint;
// 准备请求头
// Prepare request headers
const headers: Record<string, string> = {
'Content-Type': 'application/json',
...options.headers,
};
// 如果有authToken添加Authorization头
// Attach Authorization header if token exists
if (authToken) {
headers.authorization = `Bearer ${authToken}`;
}
// 如果有groupId添加groupId头
// Attach groupId header if present
if (groupId) {
headers.groupId = groupId;
}
// 发起请求
// Fire request
const response = await fetch(url, {
...options,
headers,
});
// 处理响应
// Handle non-2xx
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
// 尝试解析JSON如果失败则返回响应对象
// Try to parse JSON; fallback to raw response
try {
return await response.json();
} catch {
@@ -52,7 +51,7 @@ export const apiRequest = async <T = any>(
}
};
// 便捷的HTTP方法封装
// Convenience HTTP helpers
export const api = {
get: <T = any>(endpoint: string, options?: RequestOptions): Promise<ApiResponse<T>> =>
apiRequest<ApiResponse<T>>(endpoint, { ...options, method: 'GET' }),

View File

@@ -12,7 +12,7 @@ export type UserInfo = {
}
/**
* 获取当前用户的信息
* Get current user information
*/
export const getUserInfo = async (): Promise<UserInfo | null> => {
const res = await api.get<UserInfo>('/api/user/info');
@@ -20,7 +20,7 @@ export const getUserInfo = async (): Promise<UserInfo | null> => {
};
/**
* 获取群组内所有用户的信息
* Get all users in the current group
*/
export const getGroupMembers = async (): Promise<UserInfo[]> => {
const res = await api.get<UserInfo[]>('/api/group/members');