chore(comment): 注释改为英文
This commit is contained in:
@@ -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' }),
|
||||
|
||||
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user