215 lines
6.9 KiB
TypeScript
215 lines
6.9 KiB
TypeScript
import api from './client';
|
|
import type {
|
|
AssignmentsSummary,
|
|
MessageResponse,
|
|
PaginatedResponse,
|
|
WeiboAccountItem,
|
|
WeiboAccountCkResult,
|
|
WeiboBatchTagResult,
|
|
WeiboBindQrResult,
|
|
WeiboExchangeRecordsResult,
|
|
WeiboExchangeResult,
|
|
WeiboForceAssignResult,
|
|
WeiboMallListResult,
|
|
WeiboPaymentStatusResult,
|
|
WeiboPointHistoryResult,
|
|
WeiboRechargeOrderResult,
|
|
WeiboImportResult,
|
|
WeiboWorkbenchMutationResult,
|
|
WeiboWorkbenchBatchImportResult,
|
|
WeiboWorkbenchTransferToCollabResult,
|
|
} from './types';
|
|
|
|
export const weiboApi = {
|
|
listAccounts: (params: {
|
|
search?: string;
|
|
tag?: string;
|
|
bind_status?: string;
|
|
enabled?: boolean;
|
|
assign_status?: string;
|
|
assigned_user_id?: number;
|
|
page: number;
|
|
page_size: number;
|
|
}) =>
|
|
api.get<PaginatedResponse<WeiboAccountItem>, PaginatedResponse<WeiboAccountItem>>(
|
|
'/weibo/accounts',
|
|
{ params },
|
|
),
|
|
listAccountIds: (params: {
|
|
search?: string;
|
|
tag?: string;
|
|
bind_status?: string;
|
|
enabled?: boolean;
|
|
assign_status?: string;
|
|
assigned_user_id?: number;
|
|
}) =>
|
|
api.get<{ account_ids: number[]; total: number }, { account_ids: number[]; total: number }>(
|
|
'/weibo/accounts/ids',
|
|
{ params },
|
|
),
|
|
getAccount: (accountId: number) =>
|
|
api.get<WeiboAccountItem, WeiboAccountItem>(`/weibo/accounts/${accountId}`),
|
|
importCookies: (
|
|
text: string,
|
|
tag = '',
|
|
updateExisting = false,
|
|
forceUpdate = false,
|
|
) =>
|
|
api.post<WeiboImportResult, WeiboImportResult>('/weibo/accounts/import-cookies', {
|
|
text,
|
|
tag,
|
|
update_existing: updateExisting,
|
|
force_update: forceUpdate,
|
|
}),
|
|
updateAccount: (
|
|
accountId: number,
|
|
data: { tag?: string; remark?: string },
|
|
) =>
|
|
api.put<WeiboAccountItem, WeiboAccountItem>(
|
|
`/weibo/accounts/${accountId}`,
|
|
data,
|
|
),
|
|
disableAccount: (accountId: number, reason = '') =>
|
|
api.post<WeiboAccountItem, WeiboAccountItem>(
|
|
`/weibo/accounts/${accountId}/disable`,
|
|
{ reason },
|
|
),
|
|
enableAccount: (accountId: number) =>
|
|
api.post<WeiboAccountItem, WeiboAccountItem>(
|
|
`/weibo/accounts/${accountId}/enable`,
|
|
undefined,
|
|
{ timeout: 600000 },
|
|
),
|
|
refreshAccount: (accountId: number) =>
|
|
api.post<WeiboAccountItem, WeiboAccountItem>(
|
|
`/weibo/accounts/${accountId}/refresh`,
|
|
),
|
|
copyAccountCk: (accountId: number) =>
|
|
api.post<WeiboAccountCkResult, WeiboAccountCkResult>(
|
|
`/weibo/accounts/${accountId}/ck/copy`,
|
|
),
|
|
batchTagAccounts: (ids: number[], tag: string) =>
|
|
api.post<WeiboBatchTagResult, WeiboBatchTagResult>(
|
|
'/weibo/accounts/batch-tag',
|
|
{ ids, tag },
|
|
),
|
|
batchAssign: (accountIds: number[], assignedTo: number | null) =>
|
|
api.post<MessageResponse, MessageResponse>('/weibo/accounts/batch-assign', {
|
|
account_ids: accountIds,
|
|
assigned_to: assignedTo,
|
|
}),
|
|
forceAssign: (
|
|
assignedTo: number,
|
|
expectedCount: number,
|
|
scope: { accountIds: number[] } | { tag: string },
|
|
) =>
|
|
api.post<WeiboForceAssignResult, WeiboForceAssignResult>(
|
|
'/weibo/assignments/force',
|
|
{
|
|
assigned_to: assignedTo,
|
|
expected_count: expectedCount,
|
|
...('accountIds' in scope
|
|
? { account_ids: scope.accountIds }
|
|
: { tag: scope.tag }),
|
|
},
|
|
),
|
|
assignmentsSummary: () =>
|
|
api.get<AssignmentsSummary, AssignmentsSummary>('/weibo/assignments/summary'),
|
|
accountTags: () =>
|
|
api.get<{ tags: string[] }, { tags: string[] }>('/weibo/accounts/tags'),
|
|
workbenchTags: () =>
|
|
api.get<{ tags: string[] }, { tags: string[] }>('/weibo/workbench/tags'),
|
|
listWorkbenchAccounts: (params: {
|
|
search?: string;
|
|
tag?: string;
|
|
bind_status?: string;
|
|
enabled?: boolean;
|
|
page: number;
|
|
page_size: number;
|
|
}) =>
|
|
api.get<PaginatedResponse<WeiboAccountItem>, PaginatedResponse<WeiboAccountItem>>(
|
|
'/weibo/workbench/accounts',
|
|
{ params },
|
|
),
|
|
listWorkbenchPool: (params: {
|
|
search?: string;
|
|
tag?: string;
|
|
page: number;
|
|
page_size: number;
|
|
}) =>
|
|
api.get<PaginatedResponse<WeiboAccountItem>, PaginatedResponse<WeiboAccountItem>>(
|
|
'/weibo/workbench/pool',
|
|
{ params },
|
|
),
|
|
addWorkbenchAccounts: (accountIds: number[]) =>
|
|
api.post<WeiboWorkbenchMutationResult, WeiboWorkbenchMutationResult>(
|
|
'/weibo/workbench/accounts',
|
|
{ account_ids: accountIds },
|
|
),
|
|
batchImportWorkbenchAccounts: (text: string, forceAddOccupied = false) =>
|
|
api.post<WeiboWorkbenchBatchImportResult, WeiboWorkbenchBatchImportResult>(
|
|
'/weibo/workbench/accounts/batch-import',
|
|
{ text, force_add_occupied: forceAddOccupied },
|
|
),
|
|
transferWorkbenchToCollab: (accountId: number) =>
|
|
api.post<
|
|
WeiboWorkbenchTransferToCollabResult,
|
|
WeiboWorkbenchTransferToCollabResult
|
|
>('/weibo/workbench/accounts/transfer-to-collab', {
|
|
account_id: accountId,
|
|
}),
|
|
removeWorkbenchAccounts: (accountIds: number[]) =>
|
|
api.post<WeiboWorkbenchMutationResult, WeiboWorkbenchMutationResult>(
|
|
'/weibo/workbench/accounts/remove',
|
|
{ account_ids: accountIds },
|
|
),
|
|
bindQrcodes: (accountId: number, channel: 'wx' | 'qq') =>
|
|
api.post<WeiboBindQrResult, WeiboBindQrResult>(
|
|
`/weibo/accounts/${accountId}/bind-qrcodes`,
|
|
undefined,
|
|
{ params: { channel }, timeout: 60000 },
|
|
),
|
|
mallList: (accountId: number) =>
|
|
api.post<WeiboMallListResult, WeiboMallListResult>(
|
|
`/weibo/accounts/${accountId}/mall-list`,
|
|
undefined,
|
|
{ timeout: 60000 },
|
|
),
|
|
exchangeGoods: (accountId: number, goodsId: number, expectedPrice: number) =>
|
|
api.post<WeiboExchangeResult, WeiboExchangeResult>(
|
|
`/weibo/accounts/${accountId}/exchange`,
|
|
{
|
|
goods_id: goodsId,
|
|
expected_price: expectedPrice,
|
|
confirm: true,
|
|
},
|
|
{ timeout: 120000 },
|
|
),
|
|
exchangeRecords: (accountId: number, page = 1, pageSize = 20) =>
|
|
api.post<WeiboExchangeRecordsResult, WeiboExchangeRecordsResult>(
|
|
`/weibo/accounts/${accountId}/exchange-records`,
|
|
undefined,
|
|
{ params: { page, page_size: pageSize }, timeout: 60000 },
|
|
),
|
|
pointHistory: (accountId: number, page = 1, pageSize = 20) =>
|
|
api.post<WeiboPointHistoryResult, WeiboPointHistoryResult>(
|
|
`/weibo/accounts/${accountId}/point-history`,
|
|
undefined,
|
|
{ params: { page, page_size: pageSize }, timeout: 60000 },
|
|
),
|
|
createRechargeOrder: (accountId: number, amountYuan: number) =>
|
|
api.post<WeiboRechargeOrderResult, WeiboRechargeOrderResult>(
|
|
`/weibo/accounts/${accountId}/recharge/orders`,
|
|
{ amount_yuan: amountYuan },
|
|
{ timeout: 120000 },
|
|
),
|
|
rechargeStatus: (accountId: number, payId: string) =>
|
|
api.post<WeiboPaymentStatusResult, WeiboPaymentStatusResult>(
|
|
`/weibo/accounts/${accountId}/recharge/status`,
|
|
{ pay_id: payId },
|
|
{ timeout: 45000 },
|
|
),
|
|
deleteAccount: (accountId: number) =>
|
|
api.delete<MessageResponse, MessageResponse>(`/weibo/accounts/${accountId}`),
|
|
};
|