134dd063c3
- Implemented Dongchedi adapter for user detection and publishing. - Implemented Jianshu adapter for user detection and publishing. - Implemented Juejin adapter for user detection and publishing. - Implemented Qiehao adapter for user detection and publishing. - Implemented Smzdm adapter for user detection and publishing. - Implemented Sohuhao adapter for user detection and publishing. - Implemented Toutiaohao adapter for user detection and publishing. - Implemented Wangyihao adapter for user detection and publishing. - Implemented Weixin Gzh adapter for user detection and publishing. - Implemented Zol adapter for user detection and publishing. - Added documentation for manual testing of media publishing.
55 lines
1.7 KiB
TypeScript
55 lines
1.7 KiB
TypeScript
import type { StoredPlatformState } from "../platforms";
|
|
|
|
import type { AdapterContext, PlatformAdapter, PlatformPublishResult } from "./types";
|
|
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";
|
|
import { zhihuAdapter } from "./zhihu";
|
|
import { zolAdapter } from "./zol";
|
|
|
|
const adapters = new Map<string, PlatformAdapter>(
|
|
[
|
|
zhihuAdapter,
|
|
toutiaohaoAdapter,
|
|
baijiahaoAdapter,
|
|
sohuhaoAdapter,
|
|
qiehaoAdapter,
|
|
jianshuAdapter,
|
|
bilibiliAdapter,
|
|
juejinAdapter,
|
|
wangyihaoAdapter,
|
|
smzdmAdapter,
|
|
weixinGzhAdapter,
|
|
zolAdapter,
|
|
dongchediAdapter,
|
|
].map((adapter) => [adapter.platformId, adapter]),
|
|
);
|
|
|
|
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);
|
|
}
|