diff --git a/server/api/proxy.ts b/server/api/proxy.ts new file mode 100644 index 0000000..633d81c --- /dev/null +++ b/server/api/proxy.ts @@ -0,0 +1,14 @@ +export default defineEventHandler(async (event) => { + const img = getQuery(event).img + if (img) { + const url = decodeURIComponent(img as string) + return sendProxy(event, url, { + headers: { + "Access-Control-Allow-Origin": "*", + "Access-Control-Allow-Credentials": "*", + "Access-Control-Allow-Methods": "GET, HEAD, POST, PUT, OPTIONS", + "Access-Control-Allow-Headers": "*", + }, + }) + } +}) diff --git a/server/sources/weibo.ts b/server/sources/weibo.ts index 43a85c3..cbc786e 100644 --- a/server/sources/weibo.ts +++ b/server/sources/weibo.ts @@ -36,7 +36,7 @@ export default defineSource(async () => { id: k.num, title: k.word, extra: { - icon: k.icon, + icon: k.icon && `/api/proxy?img=${encodeURIComponent(k.icon)}`, }, url: `https://s.weibo.com/weibo?q=${encodeURIComponent(keyword)}`, mobileUrl: `https://m.weibo.cn/search?containerid=231522type%3D1%26q%3D${encodeURIComponent(keyword)}&_T_WM=16922097837&v_p=42`, diff --git a/server/sources/zhihu.ts b/server/sources/zhihu.ts index 1e5eb80..da8be1e 100644 --- a/server/sources/zhihu.ts +++ b/server/sources/zhihu.ts @@ -30,7 +30,7 @@ export default defineSource({ id: k.target.id, title: k.target.title, extra: { - icon: k.card_label?.night_icon, + icon: k.card_label?.night_icon && `/api/proxy?img=${encodeURIComponent(k.card_label?.night_icon)}`, }, url: `https://www.zhihu.com/question/${k.target.id}`, }