Files
geo/apps/browser-extension/src/adapters/smzdm.ts
T
root 134dd063c3 feat: Add platform adapters for various content publishing platforms
- 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.
2026-04-03 17:48:30 +08:00

36 lines
1.3 KiB
TypeScript

import type { StoredPlatformState } from "../platforms";
import { connectedPlatform, disconnectedPlatform, fetchJson, unsupportedPublishResult } from "./common";
import type { AdapterContext, PlatformAdapter, PlatformPublishResult } from "./types";
type SmzdmCurrentUser = {
smzdm_id?: string | number;
nickname?: string;
audit_nickname?: string;
avatar?: string;
};
async function detectSmzdm(platform: StoredPlatformState): Promise<StoredPlatformState> {
try {
const user = await fetchJson<SmzdmCurrentUser>("https://zhiyou.smzdm.com/user/info/jsonp_get_current").catch(() => null);
const uid = user?.smzdm_id != null ? String(user.smzdm_id) : "";
const nickname = user?.nickname || user?.audit_nickname || "";
if (!uid || !nickname) {
return disconnectedPlatform(platform, "未检测到什么值得买登录态");
}
return connectedPlatform(platform, uid, nickname, user?.avatar ?? null);
} catch (error) {
return disconnectedPlatform(platform, error instanceof Error ? error.message : "什么值得买登录检测失败");
}
}
async function publishSmzdm(): Promise<PlatformPublishResult> {
return unsupportedPublishResult("什么值得买");
}
export const smzdmAdapter: PlatformAdapter = {
platformId: "smzdm",
detect: detectSmzdm,
publish: (_context: AdapterContext) => publishSmzdm(),
};