@@ -48,21 +48,52 @@ const ALLOWED_SETTINGS = new Set(
4848 keys ( SITE_SETTINGS_CONF ) . concat ( keys ( SITE_SETTINGS_EXTRAS ) ) ,
4949) ;
5050
51- function getSettingsRows ( table : string ) : Record < string , any > {
52- const rows = listRows ( table ) ;
51+ function getProcessedSettings ( table : string ) : Record < string , any > {
52+ const rows = listRows ( table ) as { name ?: string ; value ?: any } [ ] ;
53+ const allRaw : Record < string , any > = { } ;
54+ for ( const { name, value } of rows ) {
55+ if ( name ) allRaw [ name ] = value ;
56+ }
57+
5358 const out : Record < string , any > = { } ;
54- for ( const row of rows ) {
55- const { name, value } = row as { name ?: string ; value ?: any } ;
59+
60+ for ( const { name, value } of rows ) {
5661 if ( ! name || ! ALLOWED_SETTINGS . has ( name ) ) continue ;
57- out [ name ] = value ;
62+ const spec = SITE_SETTINGS_CONF [ name ] ?? SITE_SETTINGS_EXTRAS [ name ] ;
63+ if ( typeof spec ?. to_val === "function" ) {
64+ out [ name ] = spec . to_val ( value , allRaw ) ;
65+ } else {
66+ out [ name ] = value ;
67+ }
5868 }
69+
70+ // fill defaults for missing fields
71+ for ( const config of [ SITE_SETTINGS_CONF , SITE_SETTINGS_EXTRAS ] ) {
72+ for ( const name in config ) {
73+ if ( ! ALLOWED_SETTINGS . has ( name ) ) continue ;
74+ if ( out [ name ] != null ) continue ;
75+ const spec = ( config as any ) [ name ] ;
76+ const fallback =
77+ typeof spec ?. to_val === "function"
78+ ? spec . to_val ( spec . default , allRaw )
79+ : spec . default ;
80+ if (
81+ ( typeof fallback === "string" && fallback === "" ) ||
82+ ( Array . isArray ( fallback ) && fallback . length === 0 )
83+ ) {
84+ continue ;
85+ }
86+ out [ name ] = fallback ;
87+ }
88+ }
89+
5990 return out ;
6091}
6192
6293export async function getCustomizePayload ( ) : Promise < CustomizePayload > {
6394 const configuration : Record < string , any > = {
6495 ...DEFAULT_CONFIGURATION ,
65- ...getSettingsRows ( "server_settings" ) ,
96+ ...getProcessedSettings ( "server_settings" ) ,
6697 } ;
6798
6899 return {
0 commit comments