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 文档同步口径。
65 lines
1.7 KiB
TypeScript
65 lines
1.7 KiB
TypeScript
import {
|
|
fetchToutiaoMediaSnapshot,
|
|
publishToutiaoArticle,
|
|
} from "../../../../packages/publisher-platforms/src/toutiao";
|
|
|
|
import type { StoredPlatformState } from "../platforms";
|
|
|
|
import {
|
|
connectedPlatform,
|
|
disconnectedPlatform,
|
|
fetchImageBlob,
|
|
fetchJson,
|
|
manageUrlResult,
|
|
normalizeArticleHtml,
|
|
uploadHtmlImages,
|
|
} from "./common";
|
|
import type { AdapterContext, PlatformAdapter } from "./types";
|
|
|
|
async function detectToutiaohao(platform: StoredPlatformState): Promise<StoredPlatformState> {
|
|
try {
|
|
const media = await fetchToutiaoMediaSnapshot(fetchJson);
|
|
if (!media?.platformUid || !media.screenName) {
|
|
return disconnectedPlatform(platform, "未检测到头条号登录态");
|
|
}
|
|
return connectedPlatform(platform, media.platformUid, media.screenName, media.avatarUrl);
|
|
} catch (error) {
|
|
return disconnectedPlatform(platform, error instanceof Error ? error.message : "头条号登录检测失败");
|
|
}
|
|
}
|
|
|
|
async function publishToutiaohao(context: AdapterContext) {
|
|
const result = await publishToutiaoArticle(
|
|
{
|
|
title: context.article.title,
|
|
html: normalizeArticleHtml(context.article),
|
|
coverAssetUrl: context.article.cover_asset_url,
|
|
publishType: context.article.publish_type,
|
|
},
|
|
{
|
|
fetchJson,
|
|
fetchImageBlob,
|
|
uploadHtmlImages,
|
|
},
|
|
);
|
|
|
|
if (!result.success) {
|
|
throw new Error(result.message);
|
|
}
|
|
|
|
return manageUrlResult(
|
|
true,
|
|
result.status,
|
|
result.articleId,
|
|
result.externalManageUrl,
|
|
result.message,
|
|
result.externalArticleUrl,
|
|
);
|
|
}
|
|
|
|
export const toutiaohaoAdapter: PlatformAdapter = {
|
|
platformId: "toutiaohao",
|
|
detect: detectToutiaohao,
|
|
publish: publishToutiaohao,
|
|
};
|