Files
yaoyaoai/scripts/nodejs/publish_open.js
949036910@qq.com 0b93813b68 11
2026-06-03 22:12:20 +08:00

45 lines
1.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"use strict";
const {
newLoginPageKeepOpen,
detachLoginBrowser,
bringPageToFront,
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}` };
}
globalThis.__native?.emitProgress?.("正在打开浏览器…");
const page = await newLoginPageKeepOpen(platform, accountId, cookies, targetUrl);
const cur = page.url();
if (!cur || cur === "about:blank" || !cur.includes("://")) {
await page.goto(targetUrl, { waitUntil: "domcontentloaded", timeout: 60000 });
}
await bringPageToFront(page);
// 断开 Puppeteer保留 detached Chrome 窗口Node 退出后不关浏览器)
await detachLoginBrowser(platform, accountId);
return {
success: true,
message: "已打开平台页面",
url: page.url(),
};
};