From d4afd8401983f5dd74234fe55ce87a4d834c84f0 Mon Sep 17 00:00:00 2001 From: Jesse Wierzbinski Date: Fri, 14 Feb 2025 18:16:07 +0100 Subject: [PATCH] refactor(media): :bug: Use hono/proxy in media proxy --- api/media/proxy/:id.ts | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/api/media/proxy/:id.ts b/api/media/proxy/:id.ts index d2089f03..736390c3 100644 --- a/api/media/proxy/:id.ts +++ b/api/media/proxy/:id.ts @@ -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; + }); }), );