51 lines
3.0 KiB
TypeScript
51 lines
3.0 KiB
TypeScript
import api from './client';
|
|
import type {
|
|
DouyuConfig,
|
|
DouyuGoodsItem,
|
|
DouyuRechargeChannel,
|
|
DouyuTaskAccountItem,
|
|
DouyuTaskBatchRequest,
|
|
DouyuTaskBatchResult,
|
|
DouyuTaskItem,
|
|
DouyuXpdGoodsItem,
|
|
MessageResponse,
|
|
PageParams,
|
|
PaginatedResponse,
|
|
} from './types';
|
|
|
|
export const douyuApi = {
|
|
taskTypes: () => api.get<Record<string, string>, Record<string, string>>('/douyu/task-types'),
|
|
listAccounts: (params?: { search?: string; tag?: string; ids?: string }) =>
|
|
api.get<DouyuTaskAccountItem[], DouyuTaskAccountItem[]>('/douyu/accounts', { params }),
|
|
listAccountsPaged: (params: PageParams & { ids?: string; tag?: string }) =>
|
|
api.get<PaginatedResponse<DouyuTaskAccountItem>, PaginatedResponse<DouyuTaskAccountItem>>('/douyu/accounts', { params }),
|
|
listAccountIds: (params?: { search?: string; tag?: string }) =>
|
|
api.get<{ account_ids: number[]; total: number }, { account_ids: number[]; total: number }>('/douyu/accounts/ids', { params }),
|
|
getConfig: () => api.get<DouyuConfig, DouyuConfig>('/douyu/config'),
|
|
getRechargeChannel: () => api.get<DouyuRechargeChannel, DouyuRechargeChannel>('/douyu/recharge-channel'),
|
|
updateConfig: (data: Partial<DouyuConfig>) => api.put<DouyuConfig, DouyuConfig>('/douyu/config', data),
|
|
listGoods: () => api.get<DouyuGoodsItem[], DouyuGoodsItem[]>('/douyu/goods'),
|
|
listEsportsGoods: () => api.get<DouyuGoodsItem[], DouyuGoodsItem[]>('/douyu/esports-goods'),
|
|
listPeaceGoods: () => api.get<DouyuXpdGoodsItem[], DouyuXpdGoodsItem[]>('/douyu/xpd-goods'),
|
|
createTasks: (data: DouyuTaskBatchRequest) =>
|
|
api.post<DouyuTaskBatchResult, DouyuTaskBatchResult>('/douyu/tasks/batch', data),
|
|
listTasks: (handbookScope: 'elite' | 'esports' | 'peace', batchId?: string) =>
|
|
api.get<DouyuTaskItem[], DouyuTaskItem[]>('/douyu/tasks', {
|
|
params: { handbook_scope: handbookScope, ...(batchId ? { batch_id: batchId } : {}) },
|
|
}),
|
|
listWorkbenchAccounts: (handbookScope: 'elite' | 'esports' | 'peace') =>
|
|
api.get<{ account_ids: number[]; configured: boolean }, { account_ids: number[]; configured: boolean }>('/douyu/workbench-accounts', {
|
|
params: { handbook_scope: handbookScope },
|
|
}),
|
|
updateWorkbenchAccounts: (handbookScope: 'elite' | 'esports' | 'peace', accountIds: number[]) =>
|
|
api.put<{ account_ids: number[]; success: boolean }, { account_ids: number[]; success: boolean }>(
|
|
'/douyu/workbench-accounts', { handbook_scope: handbookScope, account_ids: accountIds },
|
|
),
|
|
listTasksPaged: (params: PageParams & { batch_id?: string; include_detail?: boolean }) =>
|
|
api.get<PaginatedResponse<DouyuTaskItem>, PaginatedResponse<DouyuTaskItem>>('/douyu/tasks', { params }),
|
|
getTask: (taskId: number) => api.get<DouyuTaskItem, DouyuTaskItem>(`/douyu/tasks/${taskId}`),
|
|
cleanupOrphans: () =>
|
|
api.post<{ message: string; cleaned: number; success: boolean }, { message: string; cleaned: number; success: boolean }>('/douyu/tasks/cleanup-orphans'),
|
|
stopBatch: (batchId: string) => api.post<MessageResponse, MessageResponse>(`/douyu/stop/${batchId}`),
|
|
};
|