feat: secure image proxy in plan

This commit is contained in:
Stephen Zhou
2025-11-19 21:54:29 +08:00
parent 8c655f2a2f
commit f207cc328d
11 changed files with 68 additions and 7 deletions
@@ -1,5 +1,4 @@
import { nextFrame } from "@follow/utils/dom"
import { getImageProxyUrl } from "@follow/utils/img-proxy"
import { cn } from "@follow/utils/utils"
import { ErrorBoundary } from "@sentry/react"
import { useForceUpdate } from "motion/react"
@@ -9,6 +8,7 @@ import { memo, use, useEffect, useMemo, useRef, useState } from "react"
import { Blurhash, BlurhashCanvas } from "react-blurhash"
import { useEventCallback } from "usehooks-ts"
import { getImageProxyUrl } from "~/lib/img-proxy"
import { saveImageDimensionsToDb } from "~/store/image/db"
import { useMediaContainerWidth, usePreviewMedia } from "./hooks"
@@ -1,9 +1,23 @@
import { WEB_BUILD } from "@follow/shared/constants"
import { replaceImgUrlIfNeed as replaceImgUrlIfNeedUtils } from "@follow/utils/img-proxy"
import { role as getUserRole } from "@follow/store/user/getters"
import {
getImageProxyUrl as getImageProxyUrlUtils,
replaceImgUrlIfNeed as replaceImgUrlIfNeedUtils,
} from "@follow/utils/img-proxy"
export const replaceImgUrlIfNeed = (url?: string) => {
return replaceImgUrlIfNeedUtils({
url,
inBrowser: WEB_BUILD,
userRole: getUserRole(),
})
}
export const getImageProxyUrl = (
params: Omit<Parameters<typeof getImageProxyUrlUtils>[0], "userRole">,
) => {
return getImageProxyUrlUtils({
...params,
userRole: getUserRole(),
})
}
@@ -1,10 +1,10 @@
import { useEntry } from "@follow/store/entry/hooks"
import { getImageProxyUrl } from "@follow/utils/img-proxy"
import { cn } from "@follow/utils/utils"
import { useMemo } from "react"
import { usePreviewMedia } from "~/components/ui/media/hooks"
import { Media } from "~/components/ui/media/Media"
import { getImageProxyUrl } from "~/lib/img-proxy"
import { jotaiStore } from "~/lib/jotai"
import { socialMediaContentWidthAtom } from "../atoms/social-media-content-width"
@@ -2,13 +2,14 @@
import { PlatformIcon } from "@follow/components/ui/platform-icon/index.jsx"
import type { FeedModel } from "@follow/store/feed/types"
import { getBackgroundGradient } from "@follow/utils/color"
import { getImageProxyUrl } from "@follow/utils/img-proxy"
import { cn, getUrlIcon } from "@follow/utils/utils"
import * as AvatarPrimitive from "@radix-ui/react-avatar"
import { m } from "motion/react"
import type { ReactNode } from "react"
import { useMemo } from "react"
import { getImageProxyUrl } from "~/lib/img-proxy"
const { Avatar, AvatarFallback, AvatarImage } = AvatarPrimitive
// Size-responsive border radius utility function
+2 -1
View File
@@ -1,5 +1,5 @@
import { createBuildSafeHeaders } from "@follow/utils/headers"
import { getImageProxyUrl, IMAGE_PROXY_URL } from "@follow/utils/img-proxy"
import { IMAGE_PROXY_URL } from "@follow/utils/img-proxy"
import ImageEditor from "@react-native-community/image-editor"
import * as FileSystem from "expo-file-system"
import type { ImageProps, ImageSource } from "expo-image"
@@ -8,6 +8,7 @@ import * as Sharing from "expo-sharing"
import { useCallback } from "react"
import { Image } from "react-native"
import { getImageProxyUrl } from "@/src/lib/img-proxy"
import { isAndroid, isNative } from "@/src/lib/platform"
import { proxyEnv } from "@/src/lib/proxy-env"
import { toast } from "@/src/lib/toast"
+23
View File
@@ -0,0 +1,23 @@
import { role as getUserRole } from "@follow/store/user/getters"
import {
getImageProxyUrl as getImageProxyUrlUtils,
replaceImgUrlIfNeed as replaceImgUrlIfNeedUtils,
} from "@follow/utils/img-proxy"
export const getImageProxyUrl = (
params: Omit<Parameters<typeof getImageProxyUrlUtils>[0], "userRole">,
) => {
return getImageProxyUrlUtils({
...params,
userRole: getUserRole(),
})
}
export const replaceImgUrlIfNeed = (
params: Omit<Parameters<typeof replaceImgUrlIfNeedUtils>[0], "userRole">,
) => {
return replaceImgUrlIfNeedUtils({
...params,
userRole: getUserRole(),
})
}
+1
View File
@@ -583,6 +583,7 @@
"plan.features.MAX_SUBSCRIPTIONS": "Feed Subscriptions",
"plan.features.PRIORITY_SUPPORT": "Priority Support",
"plan.features.PRIVATE_SUBSCRIPTION": "Private Subscriptions",
"plan.features.SECURE_IMAGE_PROXY": "Secure Image Proxy",
"privacy.privacy": "Privacy",
"privacy.terms": "Terms",
"profile.avatar.cropInstructions": "Drag the crop area to adjust your avatar",
+1
View File
@@ -578,6 +578,7 @@
"plan.features.MAX_SUBSCRIPTIONS": "フィードサブスクリプション",
"plan.features.PRIORITY_SUPPORT": "優先サポート",
"plan.features.PRIVATE_SUBSCRIPTION": "プライベートサブスクリプション",
"plan.features.SECURE_IMAGE_PROXY": "セキュア画像プロキシ",
"privacy.privacy": "プライバシー",
"privacy.terms": "利用規約",
"profile.avatar.cropInstructions": "ドラッグしてトリミングエリアを調整します",
+1
View File
@@ -577,6 +577,7 @@
"plan.features.MAX_SUBSCRIPTIONS": "订阅源数量",
"plan.features.PRIORITY_SUPPORT": "优先支持",
"plan.features.PRIVATE_SUBSCRIPTION": "私有订阅",
"plan.features.SECURE_IMAGE_PROXY": "安全图片代理",
"privacy.privacy": "隐私政策",
"privacy.terms": "服务条款",
"profile.avatar.cropInstructions": "拖动裁剪区域以调整头像",
+1
View File
@@ -583,6 +583,7 @@
"plan.features.MAX_SUBSCRIPTIONS": "訂閱源數量",
"plan.features.PRIORITY_SUPPORT": "優先支援",
"plan.features.PRIVATE_SUBSCRIPTION": "私有訂閱",
"plan.features.SECURE_IMAGE_PROXY": "安全圖片代理",
"privacy.privacy": "隱私政策",
"privacy.terms": "服務條款",
"profile.avatar.cropInstructions": "拖曳裁切區域以調整你的頭像",
+20 -2
View File
@@ -1,5 +1,10 @@
export const IMAGE_PROXY_URL = "https://webp.follow.is"
const canUseImageProxy = (userRole?: string | null): boolean => {
if (!userRole) return false
return userRole === "plus" || userRole === "pro"
}
export const imageRefererMatches = [
{
url: /^https:\/\/\w+\.sinaimg\.cn/,
@@ -40,15 +45,28 @@ export const getImageProxyUrl = ({
url,
width,
height,
userRole,
}: {
url: string
width?: number
height?: number
userRole?: string | null
}) => {
if (!canUseImageProxy(userRole)) {
return url
}
return `${IMAGE_PROXY_URL}?url=${encodeURIComponent(url)}&width=${width ? Math.round(width) : ""}&height=${height ? Math.round(height) : ""}`
}
export const replaceImgUrlIfNeed = ({ url, inBrowser }: { url?: string; inBrowser?: boolean }) => {
export const replaceImgUrlIfNeed = ({
url,
inBrowser,
userRole,
}: {
url?: string
inBrowser?: boolean
userRole?: string | null
}) => {
if (!url) return url
for (const rule of webpCloudPublicServicesMatches) {
@@ -59,7 +77,7 @@ export const replaceImgUrlIfNeed = ({ url, inBrowser }: { url?: string; inBrowse
for (const rule of imageRefererMatches) {
if ((inBrowser || rule.force) && rule.url.test(url)) {
return getImageProxyUrl({ url, width: 0, height: 0 })
return getImageProxyUrl({ url, width: 0, height: 0, userRole })
}
}
return url