76 lines
2.8 KiB
TypeScript
76 lines
2.8 KiB
TypeScript
import api from './index';
|
|
|
|
export interface LoginResult {
|
|
access_token: string;
|
|
token_type: string;
|
|
role: string;
|
|
username: string;
|
|
permissions: string[];
|
|
}
|
|
|
|
export interface UserInfo {
|
|
id: number;
|
|
username: string;
|
|
role: string;
|
|
is_active: boolean;
|
|
remark: string;
|
|
permissions: string[];
|
|
}
|
|
|
|
export const authApi = {
|
|
login: (username: string, password: string) =>
|
|
api.post<any, LoginResult>('/auth/login', { username, password }),
|
|
|
|
me: () => api.get<any, any>('/auth/me'),
|
|
|
|
logout: () => api.post<any, any>('/auth/logout'),
|
|
};
|
|
|
|
export const userApi = {
|
|
list: () => api.get<any, UserInfo[]>('/users'),
|
|
create: (data: { username: string; password: string; role: string; remark?: string }) =>
|
|
api.post<any, UserInfo>('/users', data),
|
|
update: (id: number, data: { password?: string; role?: string; is_active?: boolean; remark?: string }) =>
|
|
api.put<any, UserInfo>(`/users/${id}`, data),
|
|
delete: (id: number) => api.delete<any, any>(`/users/${id}`),
|
|
};
|
|
|
|
export const accountApi = {
|
|
list: (params?: { assigned_only?: boolean; tag?: string; has_cookie?: boolean }) =>
|
|
api.get<any, any[]>('/accounts', { params }),
|
|
import: (text: string) => api.post<any, any>('/accounts/import', { text }),
|
|
assign: (id: number, assigned_to: number | null) =>
|
|
api.put<any, any>(`/accounts/${id}/assign`, { assigned_to }),
|
|
batchAssign: (account_ids: number[], assigned_to: number | null) =>
|
|
api.post<any, any>('/accounts/batch-assign', { account_ids, assigned_to }),
|
|
assignmentsSummary: () =>
|
|
api.get<any, any>('/accounts/assignments/summary'),
|
|
setTag: (id: number, tag: string) =>
|
|
api.put<any, any>(`/accounts/${id}/tag`, { tag }),
|
|
batchTag: (account_ids: number[], tag: string) =>
|
|
api.put<any, any>('/accounts/batch-tag', { account_ids, tag }),
|
|
listTags: () => api.get<any, string[]>('/accounts/tags/list'),
|
|
delete: (id: number) => api.delete<any, any>(`/accounts/${id}`),
|
|
};
|
|
|
|
export const loginApi = {
|
|
createBatch: (account_ids: number[], max_geetest_retries?: number, concurrency?: number) =>
|
|
api.post<any, any>('/login/batch', { account_ids, max_geetest_retries, concurrency }),
|
|
listTasks: (batch_id?: string) =>
|
|
api.get<any, any[]>('/login/tasks', { params: batch_id ? { batch_id } : {} }),
|
|
stop: (batch_id: string) => api.post<any, any>(`/login/stop/${batch_id}`),
|
|
};
|
|
|
|
export const cookieApi = {
|
|
list: () => api.get<any, any[]>('/cookies'),
|
|
exportCsv: () => api.get('/cookies/export', { responseType: 'blob' }),
|
|
delete: (id: number) => api.delete<any, any>(`/cookies/${id}`),
|
|
};
|
|
|
|
export const proxyApi = {
|
|
get: () => api.get<any, any>('/proxy'),
|
|
update: (data: any) => api.put<any, any>('/proxy', data),
|
|
test: () => api.post<any, any>('/proxy/test'),
|
|
testWhitelist: () => api.post<any, any>('/proxy/whitelist/test'),
|
|
};
|