"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(),
  };
};

