import { FileResult } from "@entity-access/server-pages/dist/Content.js"; import Page from "@entity-access/server-pages/dist/Page.js"; import { fileURLToPath } from "url"; import { dirname, join } from "path"; import { readFile } from "fs/promises"; export default class extends Page { async run() { const [ packageName, ... packagePath] = this.childPath; if (!/(ffmpeg|core-mt|util)/i.test(packageName)) { return this.notFound(); } const path = dirname(fileURLToPath(import.meta.resolve("@ffmpeg/" + packageName))); const filePath = join(path, packagePath.join("/")); // this.response.setHeader("Cross-Origin-Opener-Policy", "same-origin"); // this.response.setHeader("Cross-Origin-Embedder-Policy", "require-corp"); this.cacheControl = "public, max-age=86000, immutable"; if (packagePath.pop().endsWith(".js")) { const body = await readFile(filePath, "utf-8"); return this.content({ body, compress: true, contentType: "text/javascript" }); } return new FileResult(filePath); } }