a617d39a4a
SaaS 侧人工审核后才创建 publish job,desktop 不再做二次审核:移除 manual/waiting_user/parked/from_parked 状态机与 LeaseFromParked 查询, desktop client 只执行发布并新增"发布管理"页(待发布队列 / 历史 / 再次 发送)。同时抽离 @geo/publisher-platforms 共享适配器包、新增 Redis-based desktop_presence 与 publish_record_support,刷新 admin-web 发布弹窗与 媒体库;plan A / spec 文档同步口径。
86 lines
2.1 KiB
TypeScript
86 lines
2.1 KiB
TypeScript
import {
|
|
publishToutiaoArticle,
|
|
} from "../../../../../packages/publisher-platforms/src/toutiao";
|
|
import type { JsonValue } from "@geo/shared-types";
|
|
|
|
import {
|
|
fetchImageBlob,
|
|
normalizeArticleHtml,
|
|
sessionFetchJson,
|
|
uploadHtmlImages,
|
|
} from "./common";
|
|
import type { PublishAdapter } from "./base";
|
|
|
|
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: "头条号发布成功。",
|
|
};
|
|
},
|
|
};
|