27 lines
903 B
TypeScript
27 lines
903 B
TypeScript
|
|
import type { StoredPlatformState } from "../platforms";
|
||
|
|
|
||
|
|
import type { AdapterContext, PlatformAdapter, PlatformPublishResult } from "./types";
|
||
|
|
import { zhihuAdapter } from "./zhihu";
|
||
|
|
|
||
|
|
const adapters = new Map<string, PlatformAdapter>([[zhihuAdapter.platformId, zhihuAdapter]]);
|
||
|
|
|
||
|
|
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);
|
||
|
|
}
|