@@ -368,7 +368,7 @@ export default class VariantEntries extends VariantAdapter<VariantHttpClient<Imp
368368 * @param variantEntry - The entry variant to update.
369369 */
370370 updateFileFields ( variantEntry : VariantEntryStruct ) {
371- const setValue = ( currentObj : VariantEntryStruct , keys : Array < string > ) => {
371+ const setValue = ( currentObj : VariantEntryStruct , keys : string [ ] ) => {
372372 if ( ! currentObj || keys . length === 0 ) return ;
373373
374374 const [ firstKey , ...restKeys ] = keys ;
@@ -380,21 +380,30 @@ export default class VariantEntries extends VariantAdapter<VariantHttpClient<Imp
380380 } else if ( currentObj && typeof currentObj === 'object' ) {
381381 if ( firstKey in currentObj ) {
382382 if ( keys . length === 1 ) {
383- currentObj [ firstKey ] = { uid : currentObj [ firstKey ] , filename : 'dummy.jpeg' } ;
383+ // Check if the current property is already an object with uid and filename
384+ const existingValue = currentObj [ firstKey ] ;
385+
386+ if (
387+ ! existingValue ||
388+ ( typeof existingValue === 'object' && existingValue . uid && existingValue . filename )
389+ ) {
390+ currentObj [ firstKey ] = { uid : existingValue . uid , filename : 'dummy.jpeg' } ;
391+ } else {
392+ currentObj [ firstKey ] = { uid : currentObj [ firstKey ] , filename : 'dummy.jpeg' } ;
393+ }
384394 } else {
385395 setValue ( currentObj [ firstKey ] , restKeys ) ;
386396 }
387397 }
388398 }
389399 } ;
390400
391- const pathsToUpdate = variantEntry ?. _metadata ?. references
392- . filter ( ( ref : any ) => ref . _content_type_uid === 'sys_assets' )
393- . map ( ( ref : any ) => ref . path ) ;
401+ const pathsToUpdate =
402+ variantEntry ?. _metadata ?. references
403+ ?. filter ( ( ref : any ) => ref . _content_type_uid === 'sys_assets' )
404+ . map ( ( ref : any ) => ref . path ) || [ ] ;
394405
395- if ( pathsToUpdate ) {
396- pathsToUpdate . forEach ( ( path : string ) => setValue ( variantEntry , path . split ( '.' ) ) ) ;
397- }
406+ pathsToUpdate . forEach ( ( path : string ) => setValue ( variantEntry , path . split ( '.' ) ) ) ;
398407 }
399408
400409 /**
@@ -406,7 +415,11 @@ export default class VariantEntries extends VariantAdapter<VariantHttpClient<Imp
406415 */
407416 async publishVariantEntries ( batch : VariantEntryStruct [ ] , entryUid : string , content_type : string ) {
408417 const allPromise = [ ] ;
409- log ( this . config , `Publishing variant entries for entry uid '${ entryUid } ' of Content Type '${ content_type } '` , 'info' ) ;
418+ log (
419+ this . config ,
420+ `Publishing variant entries for entry uid '${ entryUid } ' of Content Type '${ content_type } '` ,
421+ 'info' ,
422+ ) ;
410423 for ( let [ , variantEntry ] of entries ( batch ) ) {
411424 const variantEntryUID = variantEntry . uid ;
412425 const oldVariantUid = variantEntry . _variant . _uid || '' ;
0 commit comments