Support multi-screenshot calibration and cached shop context

This commit is contained in:
2026-08-11 17:43:32 +03:00
parent f87a65bb04
commit cf1cb41f04
8 changed files with 507 additions and 84 deletions
+17 -1
View File
@@ -1,6 +1,6 @@
import { defineConfig, loadEnv } from "vite";
const MAX_BATCH_BYTES = 512 * 1024;
const MAX_BATCH_BYTES = 96 * 1024;
export async function forwardMarketBatch(body, { url, token, fetchImpl = fetch }) {
if (!url || !token) return new Response("Market import is not configured", { status: 503 });
@@ -8,9 +8,19 @@ export async function forwardMarketBatch(body, { url, token, fetchImpl = fetch }
method: "POST",
headers: { Authorization: `Bearer ${token}`, "Content-Type": "application/json" },
body,
redirect: "error",
signal: AbortSignal.timeout(15_000),
});
}
export function rejectNonLocalRequest(request) {
const rawContentType = request.headers["content-type"];
const contentType = typeof rawContentType === "string" ? rawContentType.split(";", 1)[0].trim().toLowerCase() : "";
if (contentType !== "application/json") return 415;
const host = typeof request.headers.host === "string" ? request.headers.host : "";
return request.headers.origin === `http://${host}` ? null : 403;
}
function marketImportProxy(options) {
return {
name: "market-import-proxy",
@@ -21,6 +31,12 @@ function marketImportProxy(options) {
response.end();
return;
}
const rejection = rejectNonLocalRequest(request);
if (rejection) {
response.statusCode = rejection;
response.end();
return;
}
try {
const body = await readBody(request);