From d5053d1bcb92418ae648c46899135e4fffec219a Mon Sep 17 00:00:00 2001 From: Ou Date: Fri, 1 Nov 2024 19:46:37 +0800 Subject: [PATCH] feat: better image proxy --- server/sources/toutiao.ts | 2 +- server/utils/proxy.ts | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/server/sources/toutiao.ts b/server/sources/toutiao.ts index 0a21780..957ef0b 100644 --- a/server/sources/toutiao.ts +++ b/server/sources/toutiao.ts @@ -22,7 +22,7 @@ export default defineSource(async () => { title: k.Title, url: `https://www.toutiao.com/trending/${k.ClusterIdStr}/`, extra: { - icon: k.LabelUri?.url && proxyPicture(k.LabelUri.url), + icon: k.LabelUri?.url && proxyPicture(k.LabelUri.url, "encodeBase64URL"), }, } }) diff --git a/server/utils/proxy.ts b/server/utils/proxy.ts index 94c63cf..8e4c2a4 100644 --- a/server/utils/proxy.ts +++ b/server/utils/proxy.ts @@ -1,3 +1,4 @@ -export function proxyPicture(url: string) { - return `/api/proxy/img.png?url=${encodeBase64URL(url)}` +export function proxyPicture(url: string, type: "encodeURIComponent" | "encodeBase64URL" = "encodeURIComponent") { + const encoded = type === "encodeBase64URL" ? encodeBase64URL(url) : encodeURIComponent(url) + return `/api/proxy/img.png?url=${encoded}` }