45 lines
1.4 KiB
JavaScript
45 lines
1.4 KiB
JavaScript
"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(),
|
||
};
|
||
};
|
||
|