@@ -49,14 +49,15 @@ const extractSettingsForGroup = (settings: any, groupName: string) => {
4949 if ( groupName === 'image_moderation' && rawData ) {
5050 const processedData : any = { } ;
5151
52- // Map unprefixed fields to prefixed ones that the form expects
52+ // Map backend fields to prefixed ones that the form expects
53+ // Based on the actual backend response, backend sends both prefixed and unprefixed versions
5354 const imageModerationMappings : Record < string , string [ ] > = {
54- 'image_moderation_api' : [ 'image_moderation_api' , 'api' ] ,
55+ 'image_moderation_api' : [ 'image_moderation_api' ] ,
5556 'image_moderation_check_interval' : [ 'image_moderation_check_interval_seconds' , 'check_interval_seconds' ] ,
5657 'image_moderation_concurrency' : [ 'image_moderation_concurrency' , 'concurrency' ] ,
5758 'image_moderation_enabled' : [ 'image_moderation_enabled' , 'enabled' ] ,
5859 'image_moderation_mode' : [ 'image_moderation_mode' , 'mode' ] ,
59- 'image_moderation_temp_dir' : [ 'image_moderation_temp_dir' , 'temp_dir' ] ,
60+ 'image_moderation_temp_dir' : [ 'image_moderation_temp_dir' ] ,
6061 'image_moderation_threshold' : [ 'image_moderation_threshold' , 'threshold' ] ,
6162 'image_moderation_timeout' : [ 'image_moderation_timeout_seconds' , 'timeout_seconds' ]
6263 } ;
@@ -131,6 +132,66 @@ const extractSettingsForGroup = (settings: any, groupName: string) => {
131132 return processedData ;
132133 }
133134
135+ // Handle wallet field name mapping
136+ if ( groupName === 'wallet' && rawData ) {
137+ const processedData : any = { } ;
138+
139+ // Map backend field names to frontend field names
140+ const walletMappings : Record < string , string > = {
141+ 'wallet_name' : 'name' ,
142+ 'wallet_api_key' : 'key' // Backend sends 'key', frontend expects 'wallet_api_key'
143+ } ;
144+
145+ // Apply field mappings
146+ Object . entries ( walletMappings ) . forEach ( ( [ frontendKey , backendKey ] ) => {
147+ if ( rawData [ backendKey ] !== undefined ) {
148+ processedData [ frontendKey ] = rawData [ backendKey ] ;
149+ }
150+ } ) ;
151+
152+ console . log ( `Processed ${ groupName } data:` , processedData ) ;
153+ return processedData ;
154+ }
155+
156+ // Handle general settings field name mapping
157+ if ( groupName === 'general' && rawData ) {
158+ const processedData : any = { } ;
159+
160+ // General settings come from both server and relay sections
161+ // We need to access both sections from the root settings
162+ const relayData = settings ?. relay || { } ;
163+
164+ // Map backend field names to frontend field names
165+ // Some fields come from server section, others from relay section
166+ const generalMappings : Record < string , { section : string ; field : string } > = {
167+ 'port' : { section : 'server' , field : 'port' } ,
168+ 'private_key' : { section : 'relay' , field : 'private_key' } ,
169+ 'service_tag' : { section : 'relay' , field : 'service_tag' } ,
170+ 'relay_stats_db' : { section : 'server' , field : 'stats_db' } ,
171+ 'proxy' : { section : 'server' , field : 'proxy' } , // May not exist
172+ 'demo_mode' : { section : 'server' , field : 'demo' } ,
173+ 'web' : { section : 'server' , field : 'web' }
174+ } ;
175+
176+ // Apply field mappings
177+ Object . entries ( generalMappings ) . forEach ( ( [ frontendKey , mapping ] ) => {
178+ const sourceData = mapping . section === 'relay' ? relayData : rawData ;
179+ if ( sourceData [ mapping . field ] !== undefined ) {
180+ processedData [ frontendKey ] = sourceData [ mapping . field ] ;
181+ } else {
182+ // Set default values for missing fields
183+ if ( frontendKey === 'relay_stats_db' ) {
184+ processedData [ frontendKey ] = '' ; // Default empty
185+ } else if ( frontendKey === 'proxy' ) {
186+ processedData [ frontendKey ] = false ; // Default false
187+ }
188+ }
189+ } ) ;
190+
191+ console . log ( `Processed ${ groupName } data:` , processedData ) ;
192+ return processedData ;
193+ }
194+
134195 // Handle relay info field name mapping
135196 if ( groupName === 'relay_info' && rawData ) {
136197 const processedData : any = { } ;
@@ -208,10 +269,23 @@ const buildNestedUpdate = (groupName: string, data: any) => {
208269 } ;
209270
210271 case 'wallet' :
272+ // Reverse the field mapping for saving
273+ const backendWalletData : any = { } ;
274+ const walletFieldMappings : Record < string , string > = {
275+ 'name' : 'wallet_name' ,
276+ 'key' : 'wallet_api_key'
277+ } ;
278+
279+ Object . entries ( walletFieldMappings ) . forEach ( ( [ backendKey , frontendKey ] ) => {
280+ if ( data [ frontendKey ] !== undefined ) {
281+ backendWalletData [ backendKey ] = data [ frontendKey ] ;
282+ }
283+ } ) ;
284+
211285 return {
212286 settings : {
213287 external_services : {
214- wallet : data
288+ wallet : backendWalletData
215289 }
216290 }
217291 } ;
@@ -253,11 +327,42 @@ const buildNestedUpdate = (groupName: string, data: any) => {
253327 } ;
254328
255329 case 'general' :
256- return {
257- settings : {
258- server : data
259- }
330+ // Reverse the field mapping for saving
331+ // General settings need to be split between server and relay sections
332+ const serverData : any = { } ;
333+ const relayData : any = { } ;
334+
335+ const generalFieldMappings : Record < string , { section : string ; field : string } > = {
336+ 'port' : { section : 'server' , field : 'port' } ,
337+ 'private_key' : { section : 'relay' , field : 'private_key' } ,
338+ 'service_tag' : { section : 'relay' , field : 'service_tag' } ,
339+ 'stats_db' : { section : 'server' , field : 'relay_stats_db' } ,
340+ 'proxy' : { section : 'server' , field : 'proxy' } ,
341+ 'demo' : { section : 'server' , field : 'demo_mode' } , // Frontend 'demo_mode' -> backend 'demo'
342+ 'web' : { section : 'server' , field : 'web' }
260343 } ;
344+
345+ Object . entries ( generalFieldMappings ) . forEach ( ( [ backendField , mapping ] ) => {
346+ const frontendField = mapping . field ;
347+ if ( data [ frontendField ] !== undefined ) {
348+ if ( mapping . section === 'server' ) {
349+ serverData [ backendField ] = data [ frontendField ] ;
350+ } else {
351+ relayData [ backendField ] = data [ frontendField ] ;
352+ }
353+ }
354+ } ) ;
355+
356+ // Return nested structure with both server and relay sections
357+ const result : any = { settings : { } } ;
358+ if ( Object . keys ( serverData ) . length > 0 ) {
359+ result . settings . server = serverData ;
360+ }
361+ if ( Object . keys ( relayData ) . length > 0 ) {
362+ result . settings . relay = relayData ;
363+ }
364+
365+ return result ;
261366
262367 default :
263368 console . warn ( `Unknown settings group for save: ${ groupName } ` ) ;
0 commit comments