| 1 | import type { AccountGroupItem, AccountListData, CreateChannelAccountParams, SocialAccount, SortRankRequest } from './account.types' |
| 2 | import http from '@/utils/request' |
| 3 | |
| 4 | // Source: account.ts |
| 5 | function buildArrayQueryUrl(path: string, key: string, values: string[]) { |
| 6 | const query = new URLSearchParams() |
| 7 | values.forEach(value => query.append(key, value)) |
| 8 | return `${path}?${query.toString()}` |
| 9 | } |
| 10 | |
| 11 | /** |
| 12 | * 创建账号 |
| 13 | * 仅支持插件授权平台创建账号 |
| 14 | */ |
| 15 | export function createChannelAccountApi(data: CreateChannelAccountParams) { |
| 16 | return http.post<SocialAccount>('v2/channels/accounts', data) |
| 17 | } |
| 18 | |
| 19 | /** |
| 20 | * 账号列表 |
| 21 | */ |
| 22 | export function getAccountListApi(silent = false) { |
| 23 | return http.get<AccountListData>('v2/channels/accounts', undefined, silent) |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * 账号详情 |
| 28 | */ |
| 29 | export function getAccountDetailApi(id: string) { |
| 30 | return http.get<SocialAccount>(`v2/channels/accounts/${id}`) |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * 账号数据 |
| 35 | */ |
| 36 | export function refreshAccountFansApi(id: string) { |
| 37 | return http.get(`v2/channels/accounts/${encodeURIComponent(id)}/analytics`) |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * 删除账号 |
| 42 | */ |
| 43 | export function deleteAccountApi(id: string) { |
| 44 | return http.delete<boolean>(`v2/channels/accounts/${id}`) |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * 创建账号分组 |
| 49 | */ |
| 50 | export function createAccountGroupApi(data: Partial<AccountGroupItem>) { |
| 51 | return http.post<AccountGroupItem>('v2/channels/account-groups', data) |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * 更新账号分组 |
| 56 | */ |
| 57 | export function updateAccountGroupApi(data: Partial<AccountGroupItem>) { |
| 58 | const { id, ...payload } = data |
| 59 | return http.patch<AccountGroupItem>(`v2/channels/account-groups/${id}`, payload) |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * 删除账号分组 |
| 64 | */ |
| 65 | export function deleteAccountGroupApi(ids: string[]) { |
| 66 | return http.delete<boolean>(buildArrayQueryUrl('v2/channels/account-groups', 'ids', ids)) |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * 账号分组列表 |
| 71 | */ |
| 72 | export function getAccountGroupApi() { |
| 73 | return http.get<AccountGroupItem[]>('v2/channels/account-groups') |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * 更新分组排序 |
| 78 | * @param data 排序数据 |
| 79 | * @returns 排序更新结果 |
| 80 | */ |
| 81 | export async function apiUpdateAccountGroupSortRank(data: SortRankRequest) { |
| 82 | const results = await Promise.all( |
| 83 | data.list.map(item => http.patch(`v2/channels/account-groups/${item.id}`, { rank: item.rank })), |
| 84 | ) |
| 85 | |
| 86 | const failedResult = results.find(result => result?.code !== 0) |
| 87 | return failedResult ?? { code: 0, data: true, message: '', url: '' } |
| 88 | } |
| 89 |