39 lines
1.3 KiB
TypeScript
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(),
|
||
|
|
};
|