134dd063c3
- 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.
47 lines
1.5 KiB
TypeScript
47 lines
1.5 KiB
TypeScript
import type { StoredPlatformState } from "../platforms";
|
|
|
|
import { connectedPlatform, disconnectedPlatform, fetchJson, unsupportedPublishResult } from "./common";
|
|
import type { AdapterContext, PlatformAdapter, PlatformPublishResult } from "./types";
|
|
|
|
type JuejinProfileResponse = {
|
|
data?: {
|
|
bui_user?: {
|
|
user_id?: string;
|
|
screen_name?: string;
|
|
avatar_large?: string;
|
|
avatar_url?: string;
|
|
};
|
|
};
|
|
};
|
|
|
|
async function detectJuejin(platform: StoredPlatformState): Promise<StoredPlatformState> {
|
|
try {
|
|
const response = await fetchJson<JuejinProfileResponse>("https://api.juejin.cn/user_api/v1/user/get_profile", {
|
|
method: "POST",
|
|
headers: {
|
|
"content-type": "application/json",
|
|
accept: "application/json",
|
|
},
|
|
body: "{}",
|
|
});
|
|
|
|
const user = response.data?.bui_user;
|
|
if (!user?.user_id || !user.screen_name) {
|
|
return disconnectedPlatform(platform, "未检测到掘金登录态");
|
|
}
|
|
return connectedPlatform(platform, user.user_id, user.screen_name, user.avatar_url ?? user.avatar_large ?? null);
|
|
} catch (error) {
|
|
return disconnectedPlatform(platform, error instanceof Error ? error.message : "掘金登录检测失败");
|
|
}
|
|
}
|
|
|
|
async function publishJuejin(): Promise<PlatformPublishResult> {
|
|
return unsupportedPublishResult("掘金");
|
|
}
|
|
|
|
export const juejinAdapter: PlatformAdapter = {
|
|
platformId: "juejin",
|
|
detect: detectJuejin,
|
|
publish: (_context: AdapterContext) => publishJuejin(),
|
|
};
|