Files
live-hub-py/web/frontend/src/api/weibo.ts
T

107 lines
3.4 KiB
TypeScript

import api from './client';
import type {
MessageResponse,
PaginatedResponse,
WeiboAccountItem,
WeiboBindQrResult,
WeiboExchangeRecordsResult,
WeiboExchangeResult,
WeiboMallListResult,
WeiboPaymentStatusResult,
WeiboPointHistoryResult,
WeiboRechargeOrderResult,
WeiboImportResult,
} from './types';
export const weiboApi = {
listAccounts: (params: {
search?: string;
bind_status?: string;
enabled?: boolean;
page: number;
page_size: number;
}) =>
api.get<PaginatedResponse<WeiboAccountItem>, PaginatedResponse<WeiboAccountItem>>(
'/weibo/accounts',
{ params },
),
getAccount: (accountId: number) =>
api.get<WeiboAccountItem, WeiboAccountItem>(`/weibo/accounts/${accountId}`),
importCookies: (text: string, tag = '') =>
api.post<WeiboImportResult, WeiboImportResult>('/weibo/accounts/import-cookies', {
text,
tag,
}),
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: 120000 },
),
refreshAccount: (accountId: number) =>
api.post<WeiboAccountItem, WeiboAccountItem>(
`/weibo/accounts/${accountId}/refresh`,
),
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: 30000 },
),
deleteAccount: (accountId: number) =>
api.delete<MessageResponse, MessageResponse>(`/weibo/accounts/${accountId}`),
};