You've already forked AstralRinth
forked from xxxOFFxxx/AstralRinth
* build: deploy on both environments * build: missing whitespace * build: add path filter * build: add sentry env * build: inherit secrets * remove if check * Revert "remove if check" This reverts commit b2ffe1d611269ddaf13bdbfacfdb89cd40316c29. * remove if check 2 * Fix Wrangler env * Fix Wrangler env but for real this time * Alternative method of getting URLs * Check for environment instead * Fix comment * Clickable commit * Set PREVIEW build var * Fix commit shown in comment * Fix linting errors * ) * add preview banner * prepr * prepr again * .. --------- Co-authored-by: Prospector <6166773+Prospector@users.noreply.github.com>
101 lines
2.6 KiB
TypeScript
101 lines
2.6 KiB
TypeScript
import type { CookieOptions } from '#app'
|
|
|
|
export type ProjectDisplayMode = 'list' | 'grid' | 'gallery'
|
|
export type DarkColorTheme = 'dark' | 'oled' | 'retro'
|
|
|
|
export interface NumberFlag {
|
|
min: number
|
|
max: number
|
|
}
|
|
|
|
export type BooleanFlag = boolean
|
|
|
|
export type RadioFlag = ProjectDisplayMode | DarkColorTheme
|
|
|
|
export type FlagValue = BooleanFlag /* | NumberFlag | RadioFlag */
|
|
|
|
const validateValues = <K extends PropertyKey>(flags: Record<K, FlagValue>) => flags
|
|
|
|
export const DEFAULT_FEATURE_FLAGS = validateValues({
|
|
// Developer flags
|
|
developerMode: false,
|
|
demoMode: false,
|
|
showVersionFilesInTable: false,
|
|
showAdsWithPlus: false,
|
|
alwaysShowChecklistAsPopup: true,
|
|
testTaxForm: false,
|
|
|
|
// Feature toggles
|
|
projectTypesPrimaryNav: false,
|
|
enableMedalPromotion: true,
|
|
hidePlusPromoInUserMenu: false,
|
|
oldProjectCards: true,
|
|
newProjectCards: false,
|
|
projectBackground: false,
|
|
searchBackground: false,
|
|
advancedDebugInfo: false,
|
|
showProjectPageDownloadModalServersPromo: false,
|
|
showProjectPageCreateServersTooltip: true,
|
|
showProjectPageQuickServerButton: false,
|
|
newProjectGeneralSettings: false,
|
|
newProjectEnvironmentSettings: true,
|
|
hideRussiaCensorshipBanner: false,
|
|
serverDiscovery: false,
|
|
disablePrettyProjectUrlRedirects: false,
|
|
hidePreviewBanner: false,
|
|
} as const)
|
|
|
|
export type FeatureFlag = keyof typeof DEFAULT_FEATURE_FLAGS
|
|
|
|
export type AllFeatureFlags = {
|
|
[key in FeatureFlag]: (typeof DEFAULT_FEATURE_FLAGS)[key]
|
|
}
|
|
|
|
export type PartialFeatureFlags = Partial<AllFeatureFlags>
|
|
|
|
const COOKIE_OPTIONS = {
|
|
maxAge: 60 * 60 * 24 * 365 * 10,
|
|
sameSite: 'lax',
|
|
secure: true,
|
|
httpOnly: false,
|
|
path: '/',
|
|
} satisfies CookieOptions<PartialFeatureFlags>
|
|
|
|
export const useFeatureFlags = () =>
|
|
useState<AllFeatureFlags>('featureFlags', () => {
|
|
const config = useRuntimeConfig()
|
|
|
|
const savedFlags = useCookie<PartialFeatureFlags>('featureFlags', COOKIE_OPTIONS)
|
|
|
|
if (!savedFlags.value) {
|
|
savedFlags.value = {}
|
|
}
|
|
|
|
const flags: AllFeatureFlags = JSON.parse(JSON.stringify(DEFAULT_FEATURE_FLAGS))
|
|
|
|
const overrides = config.public.featureFlagOverrides as PartialFeatureFlags
|
|
for (const key in overrides) {
|
|
if (key in flags) {
|
|
const flag = key as FeatureFlag
|
|
const value = overrides[flag] as (typeof flags)[FeatureFlag]
|
|
flags[flag] = value
|
|
}
|
|
}
|
|
|
|
for (const key in savedFlags.value) {
|
|
if (key in flags) {
|
|
const flag = key as FeatureFlag
|
|
const value = savedFlags.value[flag] as (typeof flags)[FeatureFlag]
|
|
flags[flag] = value
|
|
}
|
|
}
|
|
|
|
return flags
|
|
})
|
|
|
|
export const saveFeatureFlags = () => {
|
|
const flags = useFeatureFlags()
|
|
const cookie = useCookie<PartialFeatureFlags>('featureFlags', COOKIE_OPTIONS)
|
|
cookie.value = flags.value
|
|
}
|