@ -1,10 +1,22 @@
import { KNOWN_CONFIG_KEYS , KnownConfigKey , KnownConfigValue } from "#server/service/config/registry" ;
import { KNOWN_CONFIG_KEYS } from "#server/service/config/registry" ;
import type { KnownConfigKey , KnownConfigValue } from "#server/service/config/registry" ;
const PUBLIC_GLOBAL_CONFIG_KEYS = [ "siteName" , "allowRegister" ] as const satisfies readonly KnownConfigKey [ ] ;
const SECRET_MASKED_GLOBAL_CONFIG_KEYS = new Set < KnownConfigKey > ( [ "commentSmtpPass" ] ) ;
export default defineWrappedResponseHandler ( async ( event ) = > {
export default defineWrappedResponseHandler ( async ( event ) = > {
const user = await event . context . auth . getCurrent ( ) ;
const isAdmin = user ? . role === "admin" ;
const keys : readonly KnownConfigKey [ ] = isAdmin ? KNOWN_CONFIG_KEYS : PUBLIC_GLOBAL_CONFIG_KEYS ;
const entries = await Promise . all (
const entries = await Promise . all (
KNOWN_CONFIG_KEYS . map ( async ( key ) = > {
keys . map ( async ( key ) = > {
const value = await event . context . config . getGlobal ( key ) ;
const value = await event . context . config . getGlobal ( key ) ;
return [ key , value ] as const satisfies [ KnownConfigKey , KnownConfigValue < KnownConfigKey > ] ;
const safeValue =
SECRET_MASKED_GLOBAL_CONFIG_KEYS . has ( key )
? ""
: value ;
return [ key , safeValue ] as const satisfies [ KnownConfigKey , KnownConfigValue < KnownConfigKey > ] ;
} ) ,
} ) ,
) ;
) ;