// 抓图:灌库 + TOS 后,现有页面的真数据+真图效果
import { chromium } from "playwright";
import { mkdirSync } from "node:fs";
const BASE = "http://127.0.0.1:5180";
const API = "http://127.0.0.1:8010";
const OUT = process.argv[2] || "shots-data";
mkdirSync(OUT, { recursive: true });
const token = (await (await fetch(`${API}/api/auth/login/`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ username: "airshelf", password: "Restraint2026" }) })).json()).token;
const pages = [["dashboard", "/dashboard"], ["products", "/products"], ["library", "/library"]];
const browser = await chromium.launch();
const ctx = await browser.newContext({ viewport: { width: 1440, height: 900 }, deviceScaleFactor: 1 });
await ctx.addInitScript((t) => localStorage.setItem("airshelf_token", t), token);
const page = await ctx.newPage();
for (const [name, route] of pages) {
  await page.goto(BASE + route, { waitUntil: "networkidle", timeout: 30000 });
  await page.waitForTimeout(1800);
  await page.screenshot({ path: `${OUT}/${name}.png`, fullPage: true });
  console.log("shot", name);
}
await browser.close();
console.log("DONE ->", OUT);
