diff --git a/apps/main/src/window.ts b/apps/main/src/window.ts index c126860c6..47282cdc6 100644 --- a/apps/main/src/window.ts +++ b/apps/main/src/window.ts @@ -3,7 +3,7 @@ import { fileURLToPath } from "node:url" import { is } from "@electron-toolkit/utils" import { callWindowExpose } from "@follow/shared/bridge" -import { imageRefererMatches } from "@follow/shared/image" +import { IMAGE_PROXY_URL, imageRefererMatches } from "@follow/shared/image" import type { BrowserWindowConstructorOptions } from "electron" import { BrowserWindow, screen, shell } from "electron" @@ -124,15 +124,9 @@ export function createWindow( } window.webContents.session.webRequest.onBeforeSendHeaders((details, callback) => { - const trueUrl = - process.env["VITE_IMGPROXY_URL"] && details.url.startsWith(process.env["VITE_IMGPROXY_URL"]) - ? decodeURIComponent( - details.url.replace( - new RegExp(`^${process.env["VITE_IMGPROXY_URL"]}/unsafe/\\d+x\\d+/`), - "", - ), - ) - : details.url + const trueUrl = details.url.startsWith(IMAGE_PROXY_URL) + ? new URL(details.url).searchParams.get("url") || details.url + : details.url const refererMatch = imageRefererMatches.find((item) => item.url.test(trueUrl)) callback({ requestHeaders: { diff --git a/apps/renderer/src/lib/img-proxy.ts b/apps/renderer/src/lib/img-proxy.ts index 45c470013..33244f8e9 100644 --- a/apps/renderer/src/lib/img-proxy.ts +++ b/apps/renderer/src/lib/img-proxy.ts @@ -1,6 +1,8 @@ -import { imageRefererMatches, webpCloudPublicServicesMatches } from "@follow/shared/image" - -import { getAbValue, isAbEnabled } from "~/hooks/biz/useAb" +import { + IMAGE_PROXY_URL, + imageRefererMatches, + webpCloudPublicServicesMatches, +} from "@follow/shared/image" export const getImageProxyUrl = ({ url, @@ -11,12 +13,7 @@ export const getImageProxyUrl = ({ width: number height: number }) => { - const abValue = getAbValue("Image_Proxy_V2") - if (isAbEnabled("Image_Proxy_V2")) { - return `${abValue}?url=${encodeURIComponent(url)}&width=${width}&height=${height}` - } else { - return `${abValue}/unsafe/fit-in/${width}x${height}/${encodeURIComponent(url)}` - } + return `${IMAGE_PROXY_URL}?url=${encodeURIComponent(url)}&width=${width}&height=${height}` } export const replaceImgUrlIfNeed = (url?: string) => { diff --git a/packages/shared/src/image.ts b/packages/shared/src/image.ts index df690ed33..1d7207303 100644 --- a/packages/shared/src/image.ts +++ b/packages/shared/src/image.ts @@ -1,3 +1,5 @@ +export const IMAGE_PROXY_URL = "https://webp.follow.is" + export const imageRefererMatches = [ { url: /^https:\/\/\w+\.sinaimg.cn/,