Files
geo/apps/browser-extension/src/adapters/wangyihao.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

39 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 WangyiInfoResponse = {
data?: {
mediaInfo?: {
userId?: string | number;
tname?: string;
icon?: string;
};
};
};
async function detectWangyihao(platform: StoredPlatformState): Promise<StoredPlatformState> {
try {
const response = await fetchJson<WangyiInfoResponse>("https://mp.163.com/wemedia/info.do").catch(() => null);
const media = response?.data?.mediaInfo;
const uid = media?.userId != null ? String(media.userId) : "";
if (!uid || !media?.tname) {
return disconnectedPlatform(platform, "未检测到网易号登录态");
}
return connectedPlatform(platform, uid, media.tname, media.icon ?? null);
} catch (error) {
return disconnectedPlatform(platform, error instanceof Error ? error.message : "网易号登录检测失败");
}
}
async function publishWangyihao(): Promise<PlatformPublishResult> {
return unsupportedPublishResult("网易号");
}
export const wangyihaoAdapter: PlatformAdapter = {
platformId: "wangyihao",
detect: detectWangyihao,
publish: (_context: AdapterContext) => publishWangyihao(),
};