11
This commit is contained in:
@@ -6,6 +6,7 @@ const {
|
|||||||
LOGIN_URLS,
|
LOGIN_URLS,
|
||||||
closePublishBrowser,
|
closePublishBrowser,
|
||||||
} = require("./publish_browser.js");
|
} = require("./publish_browser.js");
|
||||||
|
const DOUYIN_HOME_URL = "https://creator.douyin.com/creator-micro/home";
|
||||||
|
|
||||||
const LOGIN_SELECTORS = {
|
const LOGIN_SELECTORS = {
|
||||||
douyin: ["#header-avatar", ".creator-avatar", 'input[type="file"]'],
|
douyin: ["#header-avatar", ".creator-avatar", 'input[type="file"]'],
|
||||||
@@ -61,6 +62,45 @@ async function resolveUid(page) {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function resolveDouyinLabel(page) {
|
||||||
|
try {
|
||||||
|
await page.goto(DOUYIN_HOME_URL, {
|
||||||
|
waitUntil: "domcontentloaded",
|
||||||
|
timeout: 60000,
|
||||||
|
});
|
||||||
|
await delay(2000);
|
||||||
|
} catch {
|
||||||
|
/* ignore */
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const text = await page.$eval(
|
||||||
|
'[class^="unique_id-"], [class*=" unique_id-"]',
|
||||||
|
(el) => (el.textContent || "").trim(),
|
||||||
|
);
|
||||||
|
const m = String(text).match(/抖音号[::]\s*([a-zA-Z0-9._-]+)/);
|
||||||
|
if (m?.[1]) return m[1];
|
||||||
|
} catch {
|
||||||
|
/* ignore */
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const fallback = await page.evaluate(() => {
|
||||||
|
const all = Array.from(document.querySelectorAll("div,span,p"));
|
||||||
|
const node = all.find((el) =>
|
||||||
|
/抖音号[::]/.test((el.textContent || "").trim()),
|
||||||
|
);
|
||||||
|
return (node?.textContent || "").trim();
|
||||||
|
});
|
||||||
|
const m = String(fallback).match(/抖音号[::]\s*([a-zA-Z0-9._-]+)/);
|
||||||
|
if (m?.[1]) return m[1];
|
||||||
|
} catch {
|
||||||
|
/* ignore */
|
||||||
|
}
|
||||||
|
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
globalThis.__nodejsMain = async function main(params) {
|
globalThis.__nodejsMain = async function main(params) {
|
||||||
const p = params || {};
|
const p = params || {};
|
||||||
const platform = String(p.platform || "").trim();
|
const platform = String(p.platform || "").trim();
|
||||||
@@ -82,6 +122,7 @@ globalThis.__nodejsMain = async function main(params) {
|
|||||||
if (await checkLoggedIn(page, platform)) {
|
if (await checkLoggedIn(page, platform)) {
|
||||||
const cookies = await page.cookies();
|
const cookies = await page.cookies();
|
||||||
const resolvedUid = await resolveUid(page);
|
const resolvedUid = await resolveUid(page);
|
||||||
|
let douyinId = "";
|
||||||
let nickname = "";
|
let nickname = "";
|
||||||
try {
|
try {
|
||||||
nickname = await page.$eval(
|
nickname = await page.$eval(
|
||||||
@@ -101,11 +142,15 @@ globalThis.__nodejsMain = async function main(params) {
|
|||||||
} catch {
|
} catch {
|
||||||
avatar = "";
|
avatar = "";
|
||||||
}
|
}
|
||||||
|
if (platform === "douyin") {
|
||||||
|
douyinId = await resolveDouyinLabel(page);
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
message: "登录成功",
|
message: "登录成功",
|
||||||
nickname: nickname || "已登录用户",
|
nickname: douyinId || nickname || "已登录用户",
|
||||||
uid: resolvedUid || `user_${Date.now()}`,
|
uid: douyinId || resolvedUid || `user_${Date.now()}`,
|
||||||
|
label: douyinId || nickname || "已登录用户",
|
||||||
avatar,
|
avatar,
|
||||||
cookies,
|
cookies,
|
||||||
};
|
};
|
||||||
|
|||||||
32
scripts/nodejs/publish_open.js
Normal file
32
scripts/nodejs/publish_open.js
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
const { newPublishPage, LOGIN_URLS } = require("./publish_browser.js");
|
||||||
|
|
||||||
|
const OPEN_URLS = {
|
||||||
|
douyin: "https://creator.douyin.com/creator-micro/content/upload",
|
||||||
|
kuaishou: "https://cp.kuaishou.com/article/publish/video",
|
||||||
|
shipin: "https://channels.weixin.qq.com/post/list",
|
||||||
|
xiaohongshu: "https://creator.xiaohongshu.com/publish/publish",
|
||||||
|
};
|
||||||
|
|
||||||
|
globalThis.__nodejsMain = async function main(params) {
|
||||||
|
const p = params || {};
|
||||||
|
const platform = String(p.platform || "").trim();
|
||||||
|
const accountId = p.accountId || null;
|
||||||
|
const cookies = Array.isArray(p.cookies) ? p.cookies : [];
|
||||||
|
const targetUrl = OPEN_URLS[platform] || LOGIN_URLS[platform];
|
||||||
|
|
||||||
|
if (!targetUrl) {
|
||||||
|
return { success: false, message: `不支持的平台: ${platform}` };
|
||||||
|
}
|
||||||
|
|
||||||
|
const page = await newPublishPage(platform, accountId, cookies);
|
||||||
|
await page.goto(targetUrl, { waitUntil: "domcontentloaded", timeout: 60000 });
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: "已打开平台页面",
|
||||||
|
url: page.url(),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
Reference in New Issue
Block a user