返回 AiToEarn
threads.api.ts
根目录 / project / aitoearn-web / src / api / platforms / threads.api.ts
1 import type { ThreadsLocationItem, ThreadsLocationsResponse } from './threads.types'
2 import type { PublishOptionValueItem, PublishOptionValuesVo } from '@/api/channels/channel.types'
3 import http from '@/utils/request'
4
5 const THREADS_LOCATION_FIELD = 'location_id'
6
7 function getThreadsLocationOptionValuesUrl(accountId: string) {
8 return `v2/channels/accounts/${encodeURIComponent(accountId)}/publish-options/${THREADS_LOCATION_FIELD}/values`
9 }
10
11 function mapPublishOptionItemToThreadsLocation(item: PublishOptionValueItem): ThreadsLocationItem {
12 return {
13 id: item.value,
14 label: item.label,
15 description: item.description,
16 }
17 }
18
19 /**
20 * 获取Threads位置列表
21 * @param accountId 账户ID
22 * @param keyword 搜索关键词
23 * @returns Threads 位置选项
24 */
25 export function apiGetThreadsLocations(accountId: string, keyword: string) {
26 return http
27 .get<PublishOptionValuesVo>(getThreadsLocationOptionValuesUrl(accountId), { keyword })
28 .then((response): ThreadsLocationsResponse | null => {
29 if (!response)
30 return response
31
32 return {
33 ...response,
34 data: response.code === 0
35 ? response.data.items.map(mapPublishOptionItemToThreadsLocation)
36 : [],
37 }
38 })
39 }
40
40 lines TYPESCRIPT