Files
geo/apps/desktop-client/src/main/adapters/toutiao.ts
T
root 162abdc97c
Backend CI / Backend (push) Has been cancelled
Frontend CI / Frontend (push) Failing after 1m39s
chore(frontend): introduce prettier + eslint and prune unused code
- Add Prettier 3 with prettier-plugin-organize-imports (sorts/removes unused imports)
- Add ESLint 10 flat config with typescript-eslint + eslint-plugin-vue + eslint-config-prettier
- Add root scripts: format, format:check, lint, lint:fix
- Reformat 257 files across admin-web, ops-web, desktop-client, packages
- Remove unused locals/exports flagged by --noUnusedLocals/--noUnusedParameters
- Fix duplicate localTabLabel key, surrogate-pair regex u-flag, NBSP literal in regex
- Skip server/ (Go) and apps/browser-extension/ (deprecated per ADR)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-01 20:39:09 +08:00

79 lines
2.1 KiB
TypeScript

import type { JsonValue } from '@geo/shared-types'
import { publishToutiaoArticle } from '../../../../../packages/publisher-platforms/src/toutiao'
import type { PublishAdapter } from './base'
import { fetchImageBlob, normalizeArticleHtml, sessionFetchJson, uploadHtmlImages } from './common'
function buildResultPayload(
articleId: string,
mediaName: string,
externalManageUrl: string,
externalArticleUrl: string | null,
): Record<string, JsonValue> {
return {
platform: 'toutiaohao',
media_name: mediaName,
external_article_id: articleId,
external_manage_url: externalManageUrl,
external_article_url: externalArticleUrl,
publish_type: 'publish',
}
}
export const toutiaoAdapter: PublishAdapter = {
platform: 'toutiaohao',
executionMode: 'session',
async publish(context) {
context.reportProgress('toutiao.normalize_html')
const html = normalizeArticleHtml(context.article)
const result = await publishToutiaoArticle(
{
title: context.article.title,
html,
coverAssetUrl: context.article.cover_asset_url,
publishType: 'publish',
},
{
fetchJson: (input, init) => sessionFetchJson(context.session, input, init),
fetchImageBlob,
uploadHtmlImages,
reportProgress(stage) {
context.reportProgress(`toutiao.${stage}`)
},
},
)
if (!result.success) {
const summary =
result.code === 'toutiaohao_not_logged_in'
? '头条号登录态失效,无法执行发布。'
: result.code === 'article_content_empty'
? '文章内容为空,无法推送到头条号。'
: result.message || '头条号发布失败。'
return {
status: 'failed',
summary,
error: {
code: result.code,
message: result.message,
},
}
}
const payload = buildResultPayload(
result.articleId,
result.mediaName,
result.externalManageUrl,
result.externalArticleUrl,
)
return {
status: 'succeeded',
payload,
summary: '头条号发布成功。',
}
},
}