@@ -238,6 +238,8 @@ const isDataSaved = ref(false);
238238const regeneratingFieldsStatus = ref <Record <string , Record <string , boolean >>>({});
239239const overwriteExistingValues = ref <boolean >(false );
240240
241+ const listOfImageThatWasNotGeneratedPerRecord = ref <Record <string , string []>>({});
242+
241243const openDialog = async () => {
242244 window .addEventListener (' beforeunload' , beforeUnloadHandler );
243245 if (props .meta .askConfirmationBeforeGenerating ) {
@@ -544,6 +546,14 @@ async function saveData() {
544546 if (! value ) {
545547 continue ;
546548 }
549+ if (! overwriteExistingValues .value ) {
550+ const imageURL = selected .value .find (rec => rec [primaryKey ] === item [primaryKey ])[key ];
551+ const originalImageUrl = listOfImageThatWasNotGeneratedPerRecord .value [item [primaryKey ]][key ].originalImage ;
552+ if (originalImageUrl === imageURL ) {
553+ reqData .find (rec => rec [primaryKey ] === item [primaryKey ])[key ] = undefined ;
554+ continue ;
555+ }
556+ }
547557 const p = uploadImage (value , item [primaryKey ], key ).then (result => {
548558 item [key ] = result ;
549559 });
@@ -553,7 +563,6 @@ async function saveData() {
553563 }
554564 await Promise .all (imagesToUpload );
555565 }
556-
557566 const res = await callAdminForthApi ({
558567 path: ` /plugin/${props .meta .pluginInstanceId }/update_fields ` ,
559568 method: ' POST' ,
@@ -729,7 +738,14 @@ async function runAiAction({
729738 for (const [key, value] of Object .entries (carouselSaveImages .value [index ])) {
730739 if (props .meta .outputImageFields ?.includes (key )) {
731740 carouselSaveImages .value [index ][key ] = [jobResponse .job .result [key ]];
732- }
741+ if (jobResponse .job .recordMeta ?.[` ${key }_meta ` ]) {
742+ carouselSaveImages .value [index ][key ] = [jobResponse .job .recordMeta [` ${key }_meta ` ].originalImage ];
743+ if (! listOfImageThatWasNotGeneratedPerRecord .value [recordId ]) {
744+ listOfImageThatWasNotGeneratedPerRecord .value [recordId ] = [];
745+ }
746+ listOfImageThatWasNotGeneratedPerRecord .value [recordId ][key ] = jobResponse .job .recordMeta [` ${key }_meta ` ];
747+ }
748+ }
733749 }
734750 }
735751 // marking that we received response for this record
0 commit comments