2026-04-03 00:39:15 +08:00
|
|
|
import type { StoredPlatformState } from "../platforms";
|
|
|
|
|
|
|
|
|
|
import type { AdapterContext, PlatformAdapter, PlatformPublishResult } from "./types";
|
2026-04-03 17:48:30 +08:00
|
|
|
import { baijiahaoAdapter } from "./baijiahao";
|
|
|
|
|
import { bilibiliAdapter } from "./bilibili";
|
|
|
|
|
import { dongchediAdapter } from "./dongchedi";
|
|
|
|
|
import { jianshuAdapter } from "./jianshu";
|
|
|
|
|
import { juejinAdapter } from "./juejin";
|
|
|
|
|
import { qiehaoAdapter } from "./qiehao";
|
|
|
|
|
import { smzdmAdapter } from "./smzdm";
|
|
|
|
|
import { sohuhaoAdapter } from "./sohuhao";
|
|
|
|
|
import { toutiaohaoAdapter } from "./toutiaohao";
|
|
|
|
|
import { wangyihaoAdapter } from "./wangyihao";
|
|
|
|
|
import { weixinGzhAdapter } from "./weixin_gzh";
|
2026-04-03 00:39:15 +08:00
|
|
|
import { zhihuAdapter } from "./zhihu";
|
2026-04-03 17:48:30 +08:00
|
|
|
import { zolAdapter } from "./zol";
|
2026-04-03 00:39:15 +08:00
|
|
|
|
2026-04-03 17:48:30 +08:00
|
|
|
const adapters = new Map<string, PlatformAdapter>(
|
|
|
|
|
[
|
|
|
|
|
zhihuAdapter,
|
|
|
|
|
toutiaohaoAdapter,
|
|
|
|
|
baijiahaoAdapter,
|
|
|
|
|
sohuhaoAdapter,
|
|
|
|
|
qiehaoAdapter,
|
|
|
|
|
jianshuAdapter,
|
|
|
|
|
bilibiliAdapter,
|
|
|
|
|
juejinAdapter,
|
|
|
|
|
wangyihaoAdapter,
|
|
|
|
|
smzdmAdapter,
|
|
|
|
|
weixinGzhAdapter,
|
|
|
|
|
zolAdapter,
|
|
|
|
|
dongchediAdapter,
|
|
|
|
|
].map((adapter) => [adapter.platformId, adapter]),
|
|
|
|
|
);
|
2026-04-03 00:39:15 +08:00
|
|
|
|
|
|
|
|
export function getPlatformAdapter(platformId: string): PlatformAdapter | undefined {
|
|
|
|
|
return adapters.get(platformId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function detectPlatformState(platform: StoredPlatformState): Promise<StoredPlatformState> {
|
|
|
|
|
const adapter = getPlatformAdapter(platform.platform_id);
|
|
|
|
|
if (!adapter) {
|
|
|
|
|
return platform;
|
|
|
|
|
}
|
|
|
|
|
return adapter.detect(platform);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function publishViaAdapter(platformId: string, context: AdapterContext): Promise<PlatformPublishResult | null> {
|
|
|
|
|
const adapter = getPlatformAdapter(platformId);
|
|
|
|
|
if (!adapter) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return adapter.publish(context);
|
|
|
|
|
}
|