feat: implement browser extension for media publishing and add backend support for media management
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user