fix(POSTV1-02): 修复便携网页静态资源类型
Dada P0-A isolated Windows CI / validate-and-package (push) Waiting to run
Dada P0-A isolated Windows CI / validate-and-package (push) Waiting to run
This commit is contained in:
+20
-1
@@ -1,6 +1,6 @@
|
||||
import { randomBytes, randomUUID } from "node:crypto";
|
||||
import { createReadStream, existsSync, readFileSync } from "node:fs";
|
||||
import { resolve } from "node:path";
|
||||
import { extname, resolve } from "node:path";
|
||||
|
||||
import {
|
||||
AccountDeletionCompleteRequestSchema,
|
||||
@@ -218,6 +218,24 @@ import type { ManagedStorage } from "./managed-storage.js";
|
||||
import { PrivateContentError, PrivateContentService } from "./private-content.js";
|
||||
import { assertSafeAdminDiagnostics, assertSafeAdminServicesStorage } from "./admin-state.js";
|
||||
|
||||
const productAssetContentTypes: Readonly<Record<string, string>> = {
|
||||
".css": "text/css; charset=utf-8",
|
||||
".jpeg": "image/jpeg",
|
||||
".jpg": "image/jpeg",
|
||||
".js": "text/javascript; charset=utf-8",
|
||||
".json": "application/json; charset=utf-8",
|
||||
".mjs": "text/javascript; charset=utf-8",
|
||||
".png": "image/png",
|
||||
".svg": "image/svg+xml",
|
||||
".webp": "image/webp",
|
||||
".woff": "font/woff",
|
||||
".woff2": "font/woff2",
|
||||
};
|
||||
|
||||
function productAssetContentType(path: string) {
|
||||
return productAssetContentTypes[extname(path).toLowerCase()] ?? "application/octet-stream";
|
||||
}
|
||||
|
||||
const defaultBootstrap: BootstrapResponse = {
|
||||
app_version: "0.0.0",
|
||||
dependencies: [],
|
||||
@@ -923,6 +941,7 @@ export async function createApp(options: CreateAppOptions = {}) {
|
||||
const relativePath = decodeURIComponent(request.url.split("?", 1)[0]!.slice("/assets/".length));
|
||||
const assetPath = resolve(productWebRoot, "assets", relativePath);
|
||||
if (!assetPath.startsWith(resolve(productWebRoot, "assets")) || !existsSync(assetPath)) return reply.code(404).send();
|
||||
reply.type(productAssetContentType(assetPath));
|
||||
return reply.send(readFileSync(assetPath));
|
||||
});
|
||||
app.get("/support-gate.css", { schema: { hide: true } }, async (_request, reply) => {
|
||||
|
||||
Reference in New Issue
Block a user