fix: stable image proxy utils

This commit is contained in:
Stephen Zhou 2025-11-21 16:43:05 +08:00
parent 4b482fc78e
commit 5e0f2a09b5
No known key found for this signature in database
1 changed files with 20 additions and 13 deletions

View File

@ -4,6 +4,7 @@ import {
getImageProxyUrl as getImageProxyUrlUtils,
replaceImgUrlIfNeed as replaceImgUrlIfNeedUtils,
} from "@follow/utils/img-proxy"
import { useCallback } from "react"
import { useServerConfigs } from "~/atoms/server-configs"
@ -19,22 +20,28 @@ export const useCanUseImageProxy = () => {
export const useReplaceImgUrlIfNeed = () => {
const canUseProxy = useCanUseImageProxy()
return (url?: string) => {
return replaceImgUrlIfNeedUtils({
url,
inBrowser: WEB_BUILD,
canUseProxy,
})
}
return useCallback(
(url?: string) => {
return replaceImgUrlIfNeedUtils({
url,
inBrowser: WEB_BUILD,
canUseProxy,
})
},
[canUseProxy],
)
}
export const useGetImageProxyUrl = () => {
const canUseProxy = useCanUseImageProxy()
return (params: Omit<Parameters<typeof getImageProxyUrlUtils>[0], "canUseProxy">) => {
return getImageProxyUrlUtils({
canUseProxy,
...params,
})
}
return useCallback(
(params: Omit<Parameters<typeof getImageProxyUrlUtils>[0], "canUseProxy">) => {
return getImageProxyUrlUtils({
canUseProxy,
...params,
})
},
[canUseProxy],
)
}