Keep research search recoverable and isolate browser checks [skip ci]
This commit is contained in:
Vendored
+18
-2
@@ -2,7 +2,7 @@
|
||||
// in a disposable Next dev copy; no real accounts, .env files or OAuth services.
|
||||
import { createServer } from "node:http";
|
||||
import { createHash, randomBytes } from "node:crypto";
|
||||
import { cp, mkdtemp, rm, symlink } from "node:fs/promises";
|
||||
import { cp, mkdtemp, readFile, rm, symlink } from "node:fs/promises";
|
||||
import { createRequire } from "node:module";
|
||||
import { join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
@@ -10,11 +10,14 @@ import { spawn } from "node:child_process";
|
||||
|
||||
const root = fileURLToPath(new URL("../../", import.meta.url));
|
||||
const origin = "http://localhost:17323";
|
||||
const snapshot = JSON.parse(await readFile(join(root, "src/data/papers.json"), "utf8"));
|
||||
const sessions = new Set(), grants = new Map();
|
||||
let meFailure = false, logoutFailure = false, verified = false;
|
||||
let counts = {};
|
||||
let paperStatus = 0, paperMalformed = false;
|
||||
function reset() {
|
||||
sessions.clear(); grants.clear(); meFailure = false; logoutFailure = false; verified = false;
|
||||
paperStatus = 0; paperMalformed = false;
|
||||
counts = { exchange: 0, verified: 0, logout: 0, google: 0, slack: 0 };
|
||||
}
|
||||
reset();
|
||||
@@ -42,8 +45,21 @@ const server = createServer(async (req, res) => {
|
||||
if (data.expire) sessions.clear();
|
||||
if (typeof data.meFailure === "boolean") meFailure = data.meFailure;
|
||||
if (typeof data.logoutFailure === "boolean") logoutFailure = data.logoutFailure;
|
||||
if ([0, 400, 429, 503, 504].includes(data.paperStatus)) paperStatus = data.paperStatus;
|
||||
if (typeof data.paperMalformed === "boolean") paperMalformed = data.paperMalformed;
|
||||
return reply(res, 200, {});
|
||||
}
|
||||
if (url.pathname.startsWith("/projects/thesisly/research/papers/")) {
|
||||
const paper = snapshot.papers.find(p => p.id === url.pathname.split("/").at(-1));
|
||||
return reply(res, paper ? 200 : 404, paper || { error: "not_found" });
|
||||
}
|
||||
if (url.pathname === "/projects/thesisly/research/papers") {
|
||||
if (paperStatus) return reply(res, paperStatus, { error: "synthetic research failure" });
|
||||
if (paperMalformed) return reply(res, 200, { unexpected: true });
|
||||
const page = Number(url.searchParams.get("page") || 1), pageSize = Number(url.searchParams.get("pageSize") || 8);
|
||||
// Fixture transport data, not an implementation of Core search semantics.
|
||||
return reply(res, 200, { items: snapshot.papers.slice((page - 1) * pageSize, page * pageSize), total: snapshot.papers.length, page, pageSize, topics: [...new Set(snapshot.papers.flatMap(p => p.topics))] });
|
||||
}
|
||||
const match = /^\/projects\/thesisly\/auth\/([a-z-]+)$/.exec(url.pathname);
|
||||
if (!match) return reply(res, 404, { error: "not_found" });
|
||||
const action = match[1];
|
||||
@@ -111,7 +127,7 @@ try {
|
||||
await new Promise((resolve, reject) => { server.once("error", reject); server.listen(17324, "localhost", resolve); });
|
||||
const require = createRequire(import.meta.url);
|
||||
child = spawn(process.execPath, [require.resolve("next/dist/bin/next"), "dev", "--hostname", "localhost", "--port", "17323"], {
|
||||
cwd: directory, stdio: "inherit", env: { ...process.env, FOUNDRY_PROJECT: "thesisly", FOUNDRY_API_ORIGIN: "http://localhost:17324", APP_ORIGIN: origin, PAPER_API_ORIGIN: "", NEXT_TELEMETRY_DISABLED: "1" },
|
||||
cwd: directory, stdio: "inherit", env: { ...process.env, FOUNDRY_PROJECT: "thesisly", FOUNDRY_API_ORIGIN: "http://localhost:17324", APP_ORIGIN: origin, PAPER_API_ORIGIN: process.env.THESISLY_PAPER_MODE === "sample" ? "" : "http://localhost:17324/projects/thesisly/research/", NEXT_TELEMETRY_DISABLED: "1" },
|
||||
});
|
||||
child.once("exit", code => { if (!closing) void close(code || 1); });
|
||||
} catch (error) { console.error(error.message); await close(1); }
|
||||
|
||||
Reference in New Issue
Block a user