chore: 清理临时脚本
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -1,66 +0,0 @@
|
|||||||
// 验证「拍照入库」界面:登录 → 进 scan → 模拟选图 → 点选 → 截图
|
|
||||||
import fs from "node:fs";
|
|
||||||
import { ensureBrowser, attach, navigate, evaluate } from "./collector/cdp.mjs";
|
|
||||||
|
|
||||||
const BASE = "http://127.0.0.1:8000";
|
|
||||||
const b64 = fs.readFileSync("./_scan_b64.txt", "utf8").trim();
|
|
||||||
|
|
||||||
const launch = await ensureBrowser({ headless: true, port: 9333, profileDir: "./data/_shot_profile", startUrl: "about:blank" });
|
|
||||||
const { cdp } = await attach(9333);
|
|
||||||
|
|
||||||
try {
|
|
||||||
await cdp.send("Emulation.setDeviceMetricsOverride", { width: 1440, height: 950, deviceScaleFactor: 1, mobile: false });
|
|
||||||
await navigate(cdp, `${BASE}/workbench#scan`);
|
|
||||||
await new Promise((r) => setTimeout(r, 1200));
|
|
||||||
|
|
||||||
// 登录(用演示账号拿 token,直接塞进 localStorage)
|
|
||||||
const lg = await evaluate(cdp, `(async () => {
|
|
||||||
const r = await fetch("${BASE}/api/auth/wx-login", {method:"POST", headers:{"Content-Type":"application/json"}, body: JSON.stringify({code:"demo"})});
|
|
||||||
const j = await r.json();
|
|
||||||
if (!j.ok) return {err: j.error};
|
|
||||||
localStorage.setItem("ql_token", j.data.token);
|
|
||||||
const kids = j.data.children || [];
|
|
||||||
if (kids[0]) localStorage.setItem("ql_child", kids[0].id);
|
|
||||||
return {n: kids.length, kid: kids[0] && kids[0].nickname};
|
|
||||||
})()`, { awaitPromise: true });
|
|
||||||
console.log("login:", JSON.stringify(lg));
|
|
||||||
|
|
||||||
await navigate(cdp, `${BASE}/workbench#scan`);
|
|
||||||
await new Promise((r) => setTimeout(r, 1500));
|
|
||||||
|
|
||||||
// 造一个 File 走 onScanFile,等价于用户点「选照片」
|
|
||||||
const split = await evaluate(cdp, `(async () => {
|
|
||||||
const bin = atob("${b64}");
|
|
||||||
const u8 = new Uint8Array(bin.length);
|
|
||||||
for (let i = 0; i < bin.length; i++) u8[i] = bin.charCodeAt(i);
|
|
||||||
const f = new File([u8], "page.jpg", {type: "image/jpeg"});
|
|
||||||
await onScanFile(f);
|
|
||||||
return {blocks: SCAN.blocks.length, draft: !!SCAN.draft, hint: document.getElementById("scanHint").textContent};
|
|
||||||
})()`, { awaitPromise: true });
|
|
||||||
console.log("detect:", JSON.stringify(split));
|
|
||||||
|
|
||||||
// 点选前三块里第一块,看按钮是否可用
|
|
||||||
const probe = await evaluate(cdp, `(async () => {
|
|
||||||
const r = await api("/api/papers/scan/detect", {method:"POST", body:{image_b64:"${b64}", filename:"p.jpg"}}).then(v=>v).catch(e=>"ERR:"+(e&&e.message));
|
|
||||||
return typeof r === "string" ? r : {blocks: (r.blocks||[]).length};
|
|
||||||
})()`, { awaitPromise: true });
|
|
||||||
console.log("probe:", JSON.stringify(probe).slice(0, 300));
|
|
||||||
const picked = await evaluate(cdp, `(() => {
|
|
||||||
toggleBox(0);
|
|
||||||
return {picks: SCAN.picks.slice(), btn: document.getElementById("scanImport").textContent,
|
|
||||||
disabled: document.getElementById("scanImport").disabled,
|
|
||||||
boxes: document.querySelectorAll(".scan-box").length,
|
|
||||||
onCount: document.querySelectorAll(".scan-box.on").length};
|
|
||||||
})()`, {});
|
|
||||||
console.log("pick:", JSON.stringify(picked));
|
|
||||||
|
|
||||||
await evaluate(cdp, `document.querySelector(".scroll") && (document.querySelector(".scroll").scrollTop = 0);`, {});
|
|
||||||
const shot = await cdp.send("Page.captureScreenshot", { format: "png" });
|
|
||||||
fs.writeFileSync("./prototype/workbench/preview-scan.png", Buffer.from(shot.data, "base64"));
|
|
||||||
console.log("shot saved");
|
|
||||||
} catch (e) {
|
|
||||||
console.error("FAIL", e && (e.stack || e.message));
|
|
||||||
} finally {
|
|
||||||
if (!launch.reused) await cdp.send("Browser.close").catch(() => {});
|
|
||||||
cdp.close();
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user