refactor(media): 🐛 Use hono/proxy in media proxy
Some checks failed
CodeQL Scan / Analyze (javascript-typescript) (push) Failing after 38s
Build Docker Images / lint (push) Successful in 28s
Build Docker Images / check (push) Failing after 5m26s
Build Docker Images / tests (push) Failing after 6s
Build Docker Images / build (server, Dockerfile, ${{ github.repository_owner }}/server) (push) Has been skipped
Build Docker Images / build (worker, Worker.Dockerfile, ${{ github.repository_owner }}/worker) (push) Has been skipped
Deploy Docs to GitHub Pages / build (push) Failing after 14s
Mirror to Codeberg / Mirror (push) Failing after 0s
Deploy Docs to GitHub Pages / Deploy (push) Has been skipped
Nix Build / check (push) Failing after 32m28s

This commit is contained in:
Jesse Wierzbinski 2025-02-14 18:16:07 +01:00
parent 3fe9926fcf
commit d4afd84019
No known key found for this signature in database

View file

@ -1,5 +1,6 @@
import { apiRoute } from "@/api";
import { createRoute, z } from "@hono/zod-openapi";
import { proxy } from "hono/proxy";
import type { ContentfulStatusCode, StatusCode } from "hono/utils/http-status";
import { ApiError } from "~/classes/errors/api-error";
import { config } from "~/packages/config-manager";
@ -53,10 +54,7 @@ export default apiRoute((app) =>
);
}
const media = await fetch(id, {
headers: {
"Accept-Encoding": "br",
},
const media = await proxy(id, {
// @ts-expect-error Proxy is a Bun-specific feature
proxy: config.http.proxy.address,
});
@ -84,10 +82,8 @@ export default apiRoute((app) =>
media.headers.get("Content-Type") || "application/octet-stream",
"Content-Length": media.headers.get("Content-Length") || "0",
"Content-Security-Policy": "",
"Content-Encoding": "",
// Real filename
"Content-Disposition": `inline; filename="${realFilename}"`,
// biome-ignore lint/suspicious/noExplicitAny: Hono doesn't type this response so this has a TS error
}) as any;
});
}),
);