From 353ec9451827e319604d00ee945c3d896d6e24e1 Mon Sep 17 00:00:00 2001 From: Ou Date: Fri, 1 Nov 2024 20:14:11 +0800 Subject: [PATCH] fix: proxy --- server/api/proxy/img.png.ts | 4 ++-- server/utils/proxy.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/server/api/proxy/img.png.ts b/server/api/proxy/img.png.ts index 9541b3a..763dbb7 100644 --- a/server/api/proxy/img.png.ts +++ b/server/api/proxy/img.png.ts @@ -1,7 +1,7 @@ export default defineEventHandler(async (event) => { - const img = getQuery(event).url + const { url: img, type = "encodeURIComponent" } = getQuery(event) if (img) { - const url = decodeBase64URL(img as string) + const url = type === "encodeURIComponent" ? encodeURIComponent(img as string) : decodeBase64URL(img as string) return sendProxy(event, url, { headers: { "Access-Control-Allow-Origin": "*", diff --git a/server/utils/proxy.ts b/server/utils/proxy.ts index 8e4c2a4..e0a0b03 100644 --- a/server/utils/proxy.ts +++ b/server/utils/proxy.ts @@ -1,4 +1,4 @@ export function proxyPicture(url: string, type: "encodeURIComponent" | "encodeBase64URL" = "encodeURIComponent") { const encoded = type === "encodeBase64URL" ? encodeBase64URL(url) : encodeURIComponent(url) - return `/api/proxy/img.png?url=${encoded}` + return `/api/proxy/img.png?type=${type}&url=${encoded}` }