55 lines
3.3 KiB
TypeScript
55 lines
3.3 KiB
TypeScript
import api from './client';
|
|
import type {
|
|
HuyaAccountItem,
|
|
HuyaConfig,
|
|
HuyaCookieItem,
|
|
HuyaCookieImportResult,
|
|
HuyaGoodsItem,
|
|
HuyaPasswordLoginRequest,
|
|
HuyaPasswordLoginResult,
|
|
HuyaRechargeGoodsItem,
|
|
HuyaTaskBatchRequest,
|
|
HuyaTaskBatchResult,
|
|
HuyaTaskItem,
|
|
MessageCountResponse,
|
|
MessageDeletedResponse,
|
|
MessageResponse,
|
|
} 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 }) =>
|
|
api.get<HuyaAccountItem[], HuyaAccountItem[]>('/huya/accounts', { params }),
|
|
importCookies: (text: string, tag: string = '') =>
|
|
api.post<HuyaCookieImportResult, HuyaCookieImportResult>('/huya/accounts/import-cookies', { text, tag }),
|
|
passwordLogin: (data: HuyaPasswordLoginRequest) =>
|
|
api.post<HuyaPasswordLoginResult, HuyaPasswordLoginResult>('/huya/accounts/password-login', data),
|
|
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 }),
|
|
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(',') } }),
|
|
listCookies: () => api.get<HuyaCookieItem[], HuyaCookieItem[]>('/huya/cookies'),
|
|
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', { params: batchId ? { batch_id: batchId } : {} }),
|
|
};
|