From 1a611e7e2896544bdeae61e9ea1add33b2c78677 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B4=AE=E7=94=9F=EF=BC=88=E5=AD=90=E8=99=9A=EF=BC=89?= <2234839456@qq.com> Date: Wed, 8 Apr 2026 15:41:39 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E8=A1=8C=E4=B8=8B=E8=BD=BD=20llrt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app.ts | 13 ++++++++++++- package.json | 1 + pnpm-lock.yaml | 9 +++++++++ scripts/build-backend.ts | 9 +++++++++ 4 files changed, 31 insertions(+), 1 deletion(-) diff --git a/backend/app.ts b/backend/app.ts index f64d5ac..fac7915 100644 --- a/backend/app.ts +++ b/backend/app.ts @@ -109,7 +109,18 @@ const fontApiMiddleware: cMiddleware = async (req, res, next) => { } const path = `font/${font}`; const fontType = path.split(".").pop() as "ttf"; - const oldFontBuffer = new Uint8Array(await readFile(path)).buffer; + let oldFontBuffer: ArrayBuffer; + try { + oldFontBuffer = new Uint8Array(await readFile(path)).buffer; + } catch { + return { + req, + res: new Response(`Font not found: ${font}`, { + status: 404, + headers: { "Content-Type": "text/plain; charset=utf-8" }, + }), + }; + } const outType = "ttf"; const newFont = await fontSubset(oldFontBuffer, text, { diff --git a/package.json b/package.json index a71d557..9709c14 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "@types/node": "^25.5.2", "tsup": "^8.5.1", "typescript": "^6.0.2", + "undici": "^8.0.2", "vite": "^8.0.7", "vite-plugin-solid": "^2.11.12" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 984cfd3..851fcae 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -30,6 +30,9 @@ importers: typescript: specifier: ^6.0.2 version: 6.0.2 + undici: + specifier: ^8.0.2 + version: 8.0.2 vite: specifier: ^8.0.7 version: 8.0.7(@types/node@25.5.2)(esbuild@0.27.7) @@ -982,6 +985,10 @@ packages: undici-types@7.18.2: resolution: {integrity: sha512-AsuCzffGHJybSaRrmr5eHr81mwJU3kjw6M+uprWvCXiNeN9SOGwQ3Jn8jb8m3Z6izVgknn1R0FTCEAP2QrLY/w==} + undici@8.0.2: + resolution: {integrity: sha512-B9MeU5wuFhkFAuNeA19K2GDFcQXZxq33fL0nRy2Aq30wdufZbyyvxW3/ChaeipXVfy/wUweZyzovQGk39+9k2w==} + engines: {node: '>=22.19.0'} + update-browserslist-db@1.2.3: resolution: {integrity: sha512-Js0m9cx+qOgDxo0eMiFGEueWztz+d4+M3rGlmKPT+T4IS/jP4ylw3Nwpu6cpTTP8R1MAC1kF4VbdLt3ARf209w==} hasBin: true @@ -1845,6 +1852,8 @@ snapshots: undici-types@7.18.2: {} + undici@8.0.2: {} + update-browserslist-db@1.2.3(browserslist@4.28.2): dependencies: browserslist: 4.28.2 diff --git a/scripts/build-backend.ts b/scripts/build-backend.ts index 2870f06..ed6dbc6 100644 --- a/scripts/build-backend.ts +++ b/scripts/build-backend.ts @@ -10,6 +10,15 @@ import { mkdir, writeFile, rm } from "node:fs/promises"; import { arch, platform } from "node:os"; import { dirname, join } from "node:path"; import { fileURLToPath } from "node:url"; +import { EnvHttpProxyAgent, setGlobalDispatcher } from "undici"; + +/** 自动读取 http_proxy/https_proxy 环境变量配置全局代理 */ +const proxyUrl = process.env.https_proxy || process.env.HTTPS_PROXY + || process.env.http_proxy || process.env.HTTP_PROXY; +if (proxyUrl) { + setGlobalDispatcher(new EnvHttpProxyAgent()); + console.log(`Using proxy: ${proxyUrl}`); +} const __dirname = dirname(fileURLToPath(import.meta.url)); const ROOT_DIR = join(__dirname, "..");