Signed-off-by: Innei <i@innei.in>
This commit is contained in:
Innei
2024-09-20 21:38:22 +08:00
parent 185ea0fd7b
commit 3bf9d9ea22
4 changed files with 278 additions and 63 deletions
+2 -1
View File
@@ -5,6 +5,7 @@ import { useFeatureFlagEnabled } from "posthog-js/react"
import { jotaiStore } from "~/lib/jotai"
import type { FeatureKeys } from "~/modules/ab/atoms"
import { debugFeaturesAtom, enableDebugOverrideAtom, IS_DEBUG_ENV } from "~/modules/ab/atoms"
import { abPayloadFallback } from "~/modules/ab/fallback"
export const useAb = (feature: FeatureKeys) => {
const isEnableDebugOverrides = useAtomValue(enableDebugOverrideAtom)
@@ -32,5 +33,5 @@ export const isAbEnabled = (feature: FeatureKeys) => {
}
export const getAbValue = (feature: FeatureKeys) => {
return PostHog.getFeatureFlagPayload(feature)
return PostHog.getFeatureFlagPayload(feature) || abPayloadFallback[feature]
}
+3 -2
View File
@@ -11,10 +11,11 @@ export const getImageProxyUrl = ({
width: number
height: number
}) => {
const abValue = getAbValue("Image_Proxy_V2")
if (isAbEnabled("Image_Proxy_V2")) {
return `${getAbValue("Image_Proxy_V2")}?url=${encodeURIComponent(url)}&width=${width}&height=${height}`
return `${abValue}?url=${encodeURIComponent(url)}&width=${width}&height=${height}`
} else {
return `${getAbValue("Image_Proxy_V2")}/unsafe/fit-in/${width}x${height}/${encodeURIComponent(url)}`
return `${abValue}/unsafe/fit-in/${width}x${height}/${encodeURIComponent(url)}`
}
}
+5
View File
@@ -0,0 +1,5 @@
import type { FeatureKeys } from "./atoms"
export const abPayloadFallback: Record<FeatureKeys, string> = {
Image_Proxy_V2: "https://thumbor.follow.is",
}