118 lines
7.3 KiB
TypeScript
118 lines
7.3 KiB
TypeScript
import api from './client';
|
|
import type {
|
|
BasicSummary,
|
|
AccountBulkSelection,
|
|
AccountBulkTagRequest,
|
|
HuyaAccountItem,
|
|
HuyaAccountSummary,
|
|
HuyaAutoRegisterBatch,
|
|
HuyaAutoRegisterRequest,
|
|
HuyaAutoRegisterRetryRequest,
|
|
HuyaConfig,
|
|
HuyaCookieItem,
|
|
HuyaCookieImportResult,
|
|
HuyaGoodsItem,
|
|
HuyaPasswordAccountImportResult,
|
|
HuyaPasswordLoginBatchResult,
|
|
HuyaPasswordLoginRequest,
|
|
HuyaPasswordLoginResult,
|
|
HuyaPasswordLoginSelectedRequest,
|
|
HuyaRechargeGoodsItem,
|
|
HuyaRegisterSuccessLog,
|
|
HuyaSmsCodeRequest,
|
|
HuyaSmsCodeResult,
|
|
HuyaSmsLoginRequest,
|
|
HuyaSmsLoginResult,
|
|
HuyaTaskBatchRequest,
|
|
HuyaTaskBatchResult,
|
|
HuyaTaskItem,
|
|
MessageCountResponse,
|
|
MessageDeletedResponse,
|
|
MessageResponse,
|
|
PageParams,
|
|
PaginatedResponse,
|
|
TaskSummary,
|
|
} from './types';
|
|
|
|
export const huyaApi = {
|
|
taskTypes: () => api.get<Record<string, string>, Record<string, string>>('/huya/task-types'),
|
|
listAccounts: (params?: { assigned_only?: boolean; tag?: string; has_cookie?: boolean; include_cookie?: boolean }) =>
|
|
api.get<HuyaAccountItem[], HuyaAccountItem[]>('/huya/accounts', { params }),
|
|
listAccountsPaged: (params: PageParams & { assigned_only?: boolean; tag?: string; has_cookie?: boolean; include_cookie?: boolean }) =>
|
|
api.get<PaginatedResponse<HuyaAccountItem>, PaginatedResponse<HuyaAccountItem>>('/huya/accounts', { params }),
|
|
accountsSummary: () => api.get<HuyaAccountSummary, HuyaAccountSummary>('/huya/accounts/summary'),
|
|
importCookies: (text: string, tag: string = '') =>
|
|
api.post<HuyaCookieImportResult, HuyaCookieImportResult>('/huya/accounts/import-cookies', { text, tag }),
|
|
importPasswordAccounts: (text: string, tag: string = '') =>
|
|
api.post<HuyaPasswordAccountImportResult, HuyaPasswordAccountImportResult>('/huya/accounts/import-passwords', { text, tag }),
|
|
passwordLogin: (data: HuyaPasswordLoginRequest) =>
|
|
api.post<HuyaPasswordLoginResult, HuyaPasswordLoginResult>('/huya/accounts/password-login', data),
|
|
passwordLoginSelected: (data: HuyaPasswordLoginSelectedRequest) =>
|
|
api.post<HuyaPasswordLoginBatchResult, HuyaPasswordLoginBatchResult>('/huya/accounts/password-login/selected', data),
|
|
smsCode: (data: HuyaSmsCodeRequest) =>
|
|
api.post<HuyaSmsCodeResult, HuyaSmsCodeResult>('/huya/accounts/sms-code', data, { timeout: 120000 }),
|
|
smsLogin: (data: HuyaSmsLoginRequest) =>
|
|
api.post<HuyaSmsLoginResult, HuyaSmsLoginResult>('/huya/accounts/sms-login', data, { timeout: 120000 }),
|
|
startAutoRegister: (data: HuyaAutoRegisterRequest) =>
|
|
api.post<HuyaAutoRegisterBatch, HuyaAutoRegisterBatch>('/huya/register/batches', data),
|
|
listAutoRegisterBatches: (limit = 50) =>
|
|
api.get<HuyaAutoRegisterBatch[], HuyaAutoRegisterBatch[]>('/huya/register/batches', { params: { limit } }),
|
|
getAutoRegisterBatch: (batchId: string) =>
|
|
api.get<HuyaAutoRegisterBatch, HuyaAutoRegisterBatch>(`/huya/register/batches/${batchId}`),
|
|
stopAutoRegisterBatch: (batchId: string) =>
|
|
api.post<MessageResponse, MessageResponse>(`/huya/register/batches/${batchId}/stop`),
|
|
retryAutoRegisterBatch: (batchId: string, data?: HuyaAutoRegisterRetryRequest) =>
|
|
api.post<HuyaAutoRegisterBatch, HuyaAutoRegisterBatch>(`/huya/register/batches/${batchId}/retry`, data || {}),
|
|
exportAutoRegisterBatch: (batchId: string) =>
|
|
api.get<Blob, Blob>(`/huya/register/batches/${batchId}/export`, { responseType: 'blob' }),
|
|
listRegisterSuccessLogs: (params?: { batch_id?: string; tag?: string; limit?: number }) =>
|
|
api.get<HuyaRegisterSuccessLog[], HuyaRegisterSuccessLog[]>('/huya/register/success-logs', { params }),
|
|
exportRegisterSuccessLogs: (params?: { batch_id?: string; tag?: string; limit?: number }) =>
|
|
api.get<Blob, Blob>('/huya/register/success-logs/export', { responseType: 'blob', params }),
|
|
stopBatch: (batchId: string) =>
|
|
api.post<MessageResponse, MessageResponse>(`/huya/stop/${batchId}`),
|
|
assign: (id: number, assigned_to: number | null) =>
|
|
api.put<MessageResponse, MessageResponse>(`/huya/accounts/${id}/assign`, { assigned_to }),
|
|
batchAssign: (account_ids: number[], assigned_to: number | null) =>
|
|
api.post<MessageCountResponse, MessageCountResponse>('/huya/accounts/batch-assign', { account_ids, assigned_to }),
|
|
assignmentsSummary: () =>
|
|
api.get<{ support_users: { id: number; username: string; assigned_count: number }[]; unassigned_count: number }, { support_users: { id: number; username: string; assigned_count: number }[]; unassigned_count: number }>('/huya/accounts/assignments/summary'),
|
|
setTag: (id: number, tag: string) =>
|
|
api.put<MessageResponse, MessageResponse>(`/huya/accounts/${id}/tag`, { tag }),
|
|
batchTag: (account_ids: number[], tag: string) =>
|
|
api.put<MessageCountResponse, MessageCountResponse>('/huya/accounts/batch-tag', { account_ids, tag }),
|
|
batchTagSelection: (data: AccountBulkTagRequest) =>
|
|
api.put<MessageCountResponse, MessageCountResponse>('/huya/accounts/batch-tag-selection', data),
|
|
listTags: () => api.get<string[], string[]>('/huya/accounts/tags/list'),
|
|
deleteAccount: (id: number) => api.delete<MessageResponse, MessageResponse>(`/huya/accounts/${id}`),
|
|
deleteAccounts: (accountIds: number[]) =>
|
|
api.delete<MessageDeletedResponse, MessageDeletedResponse>('/huya/accounts/batch', { params: { account_ids: accountIds.join(',') } }),
|
|
deleteAccountsSelection: (data: AccountBulkSelection) =>
|
|
api.post<MessageDeletedResponse, MessageDeletedResponse>('/huya/accounts/batch-delete', data),
|
|
listCookies: () => api.get<HuyaCookieItem[], HuyaCookieItem[]>('/huya/cookies'),
|
|
listCookiesPaged: (params: PageParams & { include_cookie?: boolean }) =>
|
|
api.get<PaginatedResponse<HuyaCookieItem>, PaginatedResponse<HuyaCookieItem>>('/huya/cookies', { params }),
|
|
cookiesSummary: () => api.get<BasicSummary, BasicSummary>('/huya/cookies/summary'),
|
|
getCookie: (id: number) => api.get<HuyaCookieItem, HuyaCookieItem>(`/huya/cookies/${id}`),
|
|
exportCookies: (format?: string) => api.get<Blob, Blob>('/huya/cookies/export', { responseType: 'blob', params: format ? { format } : {} }),
|
|
deleteCookie: (id: number) => api.delete<MessageResponse, MessageResponse>(`/huya/cookies/${id}`),
|
|
deleteCookies: (accountIds: number[]) =>
|
|
api.delete<MessageDeletedResponse, MessageDeletedResponse>('/huya/cookies/batch', { params: { account_ids: accountIds.join(',') } }),
|
|
getConfig: () => api.get<HuyaConfig, HuyaConfig>('/huya/config'),
|
|
updateConfig: (data: Partial<HuyaConfig>) => api.put<HuyaConfig, HuyaConfig>('/huya/config', data),
|
|
listGoods: () => api.get<HuyaGoodsItem[], HuyaGoodsItem[]>('/huya/goods'),
|
|
listRechargeGoods: () => api.get<HuyaRechargeGoodsItem[], HuyaRechargeGoodsItem[]>('/huya/recharge-goods'),
|
|
createTasks: (data: HuyaTaskBatchRequest) =>
|
|
api.post<HuyaTaskBatchResult, HuyaTaskBatchResult>('/huya/tasks/batch', data),
|
|
listTasks: (batchId?: string) =>
|
|
api.get<HuyaTaskItem[], HuyaTaskItem[]>('/huya/tasks', {
|
|
// 列表轮询默认不带 base64 小程序码,避免每次 1MB+ 流量。
|
|
params: batchId ? { batch_id: batchId, include_images: false } : { include_images: false },
|
|
}),
|
|
tasksSummary: () => api.get<TaskSummary, TaskSummary>('/huya/tasks/summary'),
|
|
getTask: (taskId: number) =>
|
|
api.get<HuyaTaskItem, HuyaTaskItem>(`/huya/tasks/${taskId}`),
|
|
cleanupOrphans: () =>
|
|
api.post<{ message: string; cleaned: number; success: boolean }, { message: string; cleaned: number; success: boolean }>('/huya/tasks/cleanup-orphans'),
|
|
};
|