diff --git a/backend/app.ts b/backend/app.ts index b654582..ab23543 100644 --- a/backend/app.ts +++ b/backend/app.ts @@ -314,12 +314,12 @@ async function handleFontSubset(req: Request, res: Response) { }; } - /** LLRT 不支持 wasm,默认 ttf;Node.js 默认 woff2(体积更小) */ + /** 默认 ttf(兼容性最好);LLRT 不支持 wasm 只能用 ttf */ const isLlrt = release_name === "llrt"; const outTypeParam = params.get("outType") || ""; const outType = (outTypeParam === "woff2" || outTypeParam === "ttf") ? (isLlrt && outTypeParam === "woff2" ? "ttf" : outTypeParam) - : (isLlrt ? "ttf" : "woff2"); + : "ttf"; const newFont = await fontSubset(oldFontBuffer, text, { outType: outType, @@ -337,7 +337,7 @@ async function handleFontSubset(req: Request, res: Response) { status: 200, headers: { "Content-Type": contentTypes[outType] || "font/ttf", - "Cache-Control": "public, max-age=31536000, immutable", + "Cache-Control": "public, max-age=86400", }, }), }; diff --git a/package.json b/package.json index 848beda..a01672a 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "@types/node": "^25.5.2", "@xmldom/xmldom": "^0.9.9", "jsdom": "^29.0.2", + "pngjs": "^7.0.0", "puppeteer": "^24.40.0", "skia-canvas": "^3.0.8", "tsup": "^8.5.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8da2935..af6c8ca 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -24,6 +24,9 @@ importers: jsdom: specifier: ^29.0.2 version: 29.0.2 + pngjs: + specifier: ^7.0.0 + version: 7.0.0 puppeteer: specifier: ^24.40.0 version: 24.40.0(typescript@6.0.2) @@ -1279,6 +1282,10 @@ packages: pkg-types@1.3.1: resolution: {integrity: sha512-/Jm5M4RvtBFVkKWRu2BLUTNP8/M2a+UwuAX+ae4770q1qVGtfjG+WTCupoZixokjmHiry8uI+dlY8KXYV5HVVQ==} + pngjs@7.0.0: + resolution: {integrity: sha512-LKWqWJRhstyYo9pGvgor/ivk2w94eSjE3RGVuzLGlr3NmD8bf7RcYGze1mNdEHRP6TRP6rMuDHk5t44hnTRyow==} + engines: {node: '>=14.19.0'} + postcss-load-config@6.0.1: resolution: {integrity: sha512-oPtTM4oerL+UXmx+93ytZVN82RrlY/wPUV8IeDxFrzIjXOLF1pN+EmKPLbubvKHT2HC20xXsCAH2Z+CKV6Oz/g==} engines: {node: '>= 18'} @@ -2790,6 +2797,8 @@ snapshots: mlly: 1.8.2 pathe: 2.0.3 + pngjs@7.0.0: {} + postcss-load-config@6.0.1(postcss@8.5.9): dependencies: lilconfig: 3.1.3 diff --git a/基准测试.test.ts b/基准测试.test.ts index 4ae1839..7774461 100644 --- a/基准测试.test.ts +++ b/基准测试.test.ts @@ -19,6 +19,7 @@ import { createServer, type Server, type IncomingMessage, type ServerResponse } import { performance } from "node:perf_hooks"; import puppeteer, { type Page } from "puppeteer"; import { fontSubset } from "./backend/font_util/font.js"; +import { PNG } from "pngjs"; const BENCHMARK_DIR = "benchmark_results"; const ROUNDS = 10; @@ -46,7 +47,7 @@ function createFontServer(): Promise<{ server: Server; port: number }> {