| 1 | import type { SocialAccount } from '@/api/accounts/account.types' |
| 2 | import { PlatType } from '@/app/config/platConfig' |
| 3 | import { PubType } from '@/app/config/publishConfig' |
| 4 | import { getPlatformInfoSync } from '@/store/platformMetadata' |
| 5 | import { parseTopicString } from '@/utils/common' |
| 6 | |
| 7 | /** |
| 8 | * 创建假账号以复用 PubParmasTextarea 组件 |
| 9 | * 使用固定的 TikTok 平台(影响上传限制配置) |
| 10 | */ |
| 11 | export function createFakeAccount(): SocialAccount { |
| 12 | const fakeId = `material-fake-${Date.now()}` |
| 13 | return { |
| 14 | id: fakeId, |
| 15 | type: PlatType.Tiktok, |
| 16 | uid: fakeId, |
| 17 | avatar: '', |
| 18 | nickname: '素材账号', |
| 19 | status: 1, |
| 20 | fansCount: 0, |
| 21 | readCount: 0, |
| 22 | likeCount: 0, |
| 23 | collectCount: 0, |
| 24 | forwardCount: 0, |
| 25 | commentCount: 0, |
| 26 | workCount: 0, |
| 27 | income: 0, |
| 28 | rank: 1, |
| 29 | groupId: '', |
| 30 | loginTime: new Date().toISOString(), |
| 31 | createTime: new Date().toISOString(), |
| 32 | updateTime: new Date().toISOString(), |
| 33 | lastStatsTime: new Date().toISOString(), |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | function normalizeTopicText(topic: string) { |
| 38 | return topic.replace(/^#+/, '').trim() |
| 39 | } |
| 40 | |
| 41 | function getTopicKey(topic: string) { |
| 42 | return normalizeTopicText(topic).toLowerCase() |
| 43 | } |
| 44 | |
| 45 | export function appendMaterialTopicsToDescription(description: string, topics?: string[]) { |
| 46 | if (!topics?.length) |
| 47 | return description |
| 48 | |
| 49 | const { topics: descriptionTopics } = parseTopicString(description) |
| 50 | const existingTopicKeys = new Set(descriptionTopics.map(getTopicKey)) |
| 51 | const appendedTopicKeys = new Set<string>() |
| 52 | const topicText = topics |
| 53 | .flatMap((topic) => { |
| 54 | const topicLabel = normalizeTopicText(topic) |
| 55 | const topicKey = getTopicKey(topicLabel) |
| 56 | if (!topicLabel || existingTopicKeys.has(topicKey) || appendedTopicKeys.has(topicKey)) |
| 57 | return [] |
| 58 | |
| 59 | appendedTopicKeys.add(topicKey) |
| 60 | return [`#${topicLabel}`] |
| 61 | }) |
| 62 | .join(' ') |
| 63 | |
| 64 | if (!topicText) |
| 65 | return description.trim() |
| 66 | |
| 67 | return `${description}\n${topicText}`.trim() |
| 68 | } |
| 69 | |
| 70 | export function getMaterialUploadPlatType(selectedPlatforms: PlatType[]) { |
| 71 | const mediaPlatform = selectedPlatforms.find((platType) => { |
| 72 | const pubTypes = getPlatformInfoSync(platType)?.pubTypes |
| 73 | return pubTypes?.has(PubType.ImageText) && pubTypes.has(PubType.VIDEO) |
| 74 | }) ?? selectedPlatforms.find((platType) => { |
| 75 | const pubTypes = getPlatformInfoSync(platType)?.pubTypes |
| 76 | return pubTypes?.has(PubType.ImageText) || pubTypes?.has(PubType.VIDEO) |
| 77 | }) |
| 78 | |
| 79 | return mediaPlatform ?? selectedPlatforms[0] ?? PlatType.Tiktok |
| 80 | } |
| 81 |