| 1 | import type { ChannelAccountAuthStart, ChannelAccountAuthStatus, ChannelCreatePublishFlowParams, ChannelOAuthLoginStart, ChannelPlatformListOptions, ChannelPublicPublishRecordItem, ChannelPublishFlowVo, ChannelPublishRecordItem, ChannelPublishRecordListVo, ChannelPublishRecordQueryParams, ChannelPublishTaskActionVo, ChannelPublishUserActionVo, ChannelWorkAnalyticsVo, ChannelWorkQueryParams, PlatformMetadataVo, StartChannelAccountAuthParams, StartChannelOAuthLoginParams } from './channel.types' |
| 2 | import type { PlatType } from '@/app/config/platConfig' |
| 3 | import http, { request } from '@/utils/request' |
| 4 | |
| 5 | // Source: channelAuth.ts |
| 6 | /** |
| 7 | * 开始平台授权 |
| 8 | * 生成平台 OAuth 授权 URL |
| 9 | */ |
| 10 | export function startChannelAccountAuthApi( |
| 11 | platform: PlatType, |
| 12 | params?: StartChannelAccountAuthParams, |
| 13 | ) { |
| 14 | return request<ChannelAccountAuthStart>({ |
| 15 | url: `v2/channels/accounts/auth/${platform}`, |
| 16 | method: 'GET', |
| 17 | params: { |
| 18 | callbackUrl: params?.callbackUrl, |
| 19 | redirectUri: params?.redirectUri, |
| 20 | groupId: params?.groupId, |
| 21 | }, |
| 22 | credentials: 'include', |
| 23 | }) |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * 查询授权状态 |
| 28 | * 轮询平台授权 Session 状态 |
| 29 | */ |
| 30 | export function getChannelAccountAuthStatusApi(platform: PlatType, sessionId: string) { |
| 31 | return request<ChannelAccountAuthStatus>({ |
| 32 | url: `v2/channels/accounts/auth/${platform}/status/${sessionId}`, |
| 33 | method: 'GET', |
| 34 | silent: true, |
| 35 | }) |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * 开始平台 OAuth 登录 |
| 40 | * 生成平台 OAuth 登录授权 URL。 |
| 41 | */ |
| 42 | export function startChannelOAuthLoginApi( |
| 43 | platform: PlatType, |
| 44 | params?: StartChannelOAuthLoginParams, |
| 45 | ) { |
| 46 | return request<ChannelOAuthLoginStart>({ |
| 47 | url: `v2/channels/oauth/${platform}`, |
| 48 | method: 'GET', |
| 49 | params: { |
| 50 | redirectUri: params?.redirectUri, |
| 51 | inviteCode: params?.inviteCode, |
| 52 | }, |
| 53 | }) |
| 54 | } |
| 55 | |
| 56 | // Source: channelPlatforms.ts |
| 57 | /** |
| 58 | * 获取所有平台元数据 |
| 59 | * 返回已注册平台的元数据列表,包括展示名、logo、能力声明等 |
| 60 | */ |
| 61 | export function getChannelPlatformsApi(options?: ChannelPlatformListOptions) { |
| 62 | return http.get<PlatformMetadataVo[]>('v2/channels/platforms', undefined, true, { |
| 63 | ...(options?.fresh ? { cache: 'no-store' } : {}), |
| 64 | }) |
| 65 | } |
| 66 | |
| 67 | // Source: channelPublish.ts |
| 68 | function encodePathSegment(value: string) { |
| 69 | return encodeURIComponent(value) |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * 创建发布 Flow |
| 74 | * 创建多平台发布 flow,一次请求可生成多个单平台任务 |
| 75 | */ |
| 76 | export function createChannelPublishFlowApi(data: ChannelCreatePublishFlowParams) { |
| 77 | return http.post<ChannelPublishFlowVo>('v2/channels/publish/flows', data) |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * 获取 Flow 详情 |
| 82 | * 根据 flowId 获取发布 flow 聚合信息 |
| 83 | */ |
| 84 | export function getChannelPublishFlowApi(flowId: string) { |
| 85 | return http.get<ChannelPublishFlowVo>(`v2/channels/publish/flows/${flowId}`) |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * 获取发布历史 |
| 90 | * 分页获取用户发布历史记录 |
| 91 | */ |
| 92 | export function getChannelPublishRecordsApi(params?: ChannelPublishRecordQueryParams) { |
| 93 | return http.get<ChannelPublishRecordListVo>('v2/channels/publish/records', params) |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * 获取发布记录详情 |
| 98 | * 根据记录 ID 获取发布记录详情 |
| 99 | */ |
| 100 | export function getChannelPublishRecordApi(recordId: string) { |
| 101 | return http.get<ChannelPublishRecordItem>(`v2/channels/publish/records/${encodePathSegment(recordId)}`) |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * 获取发布记录用户操作信息 |
| 106 | * 获取抖音等待用户操作发布记录的 App scheme 和短链接 |
| 107 | */ |
| 108 | export function getChannelPublishUserActionApi(recordId: string) { |
| 109 | return http.get<ChannelPublishUserActionVo>(`v2/channels/publish/records/${encodePathSegment(recordId)}/user-action`, undefined, true) |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * 公开查询发布记录 |
| 114 | * 根据记录 ID 公开查询发布状态、作品链接等基础信息 |
| 115 | */ |
| 116 | export function getChannelPublicPublishRecordApi(recordId: string) { |
| 117 | return http.get<ChannelPublicPublishRecordItem>(`v2/channels/publish/records/public/${encodePathSegment(recordId)}`, undefined, true) |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * 删除发布记录 |
| 122 | * 删除当前用户的终态本地发布记录,不删除平台作品 |
| 123 | */ |
| 124 | export function deleteChannelPublishRecordApi(recordId: string) { |
| 125 | return http.delete<void>(`v2/channels/publish/records/${encodePathSegment(recordId)}`) |
| 126 | } |
| 127 | |
| 128 | /** |
| 129 | * 立即发布 |
| 130 | * 将定时任务调整为立即发布 |
| 131 | */ |
| 132 | export function publishChannelTaskNowApi(taskId: string) { |
| 133 | return http.post<ChannelPublishTaskActionVo>(`v2/channels/publish/tasks/${encodePathSegment(taskId)}/publish-now`) |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * 重试发布任务 |
| 138 | * 重试当前用户失败的发布任务 |
| 139 | */ |
| 140 | export function retryChannelPublishTaskApi(taskId: string) { |
| 141 | return http.post<ChannelPublishTaskActionVo>(`v2/channels/publish/tasks/${encodePathSegment(taskId)}/retry`) |
| 142 | } |
| 143 | |
| 144 | /** |
| 145 | * 取消发布任务 |
| 146 | * 取消指定的发布任务 |
| 147 | */ |
| 148 | export function cancelChannelPublishTaskApi(taskId: string) { |
| 149 | return http.delete<ChannelPublishTaskActionVo>(`v2/channels/publish/tasks/${encodePathSegment(taskId)}`) |
| 150 | } |
| 151 | |
| 152 | /** |
| 153 | * 修改发布时间 |
| 154 | * 修改待发布任务的发布时间 |
| 155 | */ |
| 156 | export function updateChannelPublishAtApi(taskId: string, publishAt: string) { |
| 157 | return http.patch<ChannelPublishTaskActionVo>(`v2/channels/publish/tasks/${encodePathSegment(taskId)}/publish-at`, { publishAt }) |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * 获取作品数据 |
| 162 | * 获取指定作品的分析数据 |
| 163 | */ |
| 164 | export function getChannelWorkAnalyticsApi( |
| 165 | platform: PlatType, |
| 166 | platformWorkId: string, |
| 167 | params?: Pick<ChannelWorkQueryParams, 'accountId'>, |
| 168 | ) { |
| 169 | return http.get<ChannelWorkAnalyticsVo>( |
| 170 | `v2/channels/works/${platform}/${encodePathSegment(platformWorkId)}/analytics`, |
| 171 | params, |
| 172 | true, |
| 173 | ) |
| 174 | } |
| 175 |