Skip to content

Commit 03ab57f

Browse files
committed
fix: allow to save fields even when was image generation error
1 parent c3ac3c5 commit 03ab57f

File tree

2 files changed

+35
-30
lines changed

2 files changed

+35
-30
lines changed

custom/visionAction.vue

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ const openGenerationCarousel = ref([]);
106106
const isLoading = ref(false);
107107
const isError = ref(false);
108108
const isCriticalError = ref(false);
109+
const isImageGenerationError = ref(false);
109110
const errorMessage = ref('');
110111
const checkedCount = ref(0);
111112
@@ -289,20 +290,21 @@ async function prepareDataForSave() {
289290
.filter(item => item.isChecked === true)
290291
.map(item => item[primaryKey]);
291292
292-
const promises = [];
293-
for (const item of checkedItems) {
294-
for (const [key, value] of Object.entries(item)) {
295-
if(props.meta.outputImageFields?.includes(key)) {
296-
const p = convertImages(key, value).then(result => {
297-
item[key] = result;
298-
});
299-
300-
promises.push(p);
293+
if (isImageGenerationError.value !== true) {
294+
const promises = [];
295+
for (const item of checkedItems) {
296+
for (const [key, value] of Object.entries(item)) {
297+
if(props.meta.outputImageFields?.includes(key)) {
298+
const p = convertImages(key, value).then(result => {
299+
item[key] = result;
300+
});
301+
302+
promises.push(p);
303+
}
301304
}
302305
}
306+
await Promise.all(promises);
303307
}
304-
await Promise.all(promises);
305-
306308
return [checkedItemsIDs, checkedItems];
307309
}
308310
@@ -350,7 +352,7 @@ async function analyzeFields() {
350352
351353
console.error('Failed to analyze image(s):', res.error);
352354
isError.value = true;
353-
isCriticalError.value = true;
355+
//isCriticalError.value = true;
354356
errorMessage.value = `Failed to fetch analyze image(s). Please, try to re-run the action.`;
355357
} else {
356358
res.result.forEach((item, idx) => {
@@ -375,7 +377,7 @@ async function analyzeFields() {
375377
376378
console.error('Failed to analyze image(s):', error);
377379
isError.value = true;
378-
isCriticalError.value = true;
380+
//isCriticalError.value = true;
379381
errorMessage.value = res.error;
380382
}
381383
}
@@ -403,7 +405,7 @@ async function analyzeFieldsNoImages() {
403405
});
404406
console.error('Failed to analyze fields:', res.error);
405407
isError.value = true;
406-
isCriticalError.value = true;
408+
//isCriticalError.value = true;
407409
errorMessage.value = res.error;
408410
} else {
409411
res.result.forEach((item, idx) => {
@@ -427,7 +429,7 @@ async function analyzeFieldsNoImages() {
427429
});
428430
console.error('Failed to analyze fields:', error);
429431
isError.value = true;
430-
isCriticalError.value = true;
432+
//isCriticalError.value = true;
431433
errorMessage.value = `Failed to analyze fields. Please, try to re-run the action.`;
432434
}
433435
}
@@ -443,26 +445,28 @@ async function saveData() {
443445
try {
444446
isLoading.value = true;
445447
const [checkedItemsIDs, reqData] = await prepareDataForSave();
446-
447-
const imagesToUpload = [];
448-
for (const item of reqData) {
449-
for (const [key, value] of Object.entries(item)) {
450-
if(props.meta.outputImageFields?.includes(key)) {
451-
const p = uploadImage(value, item[primaryKey], key).then(result => {
452-
item[key] = result;
453-
});
454-
imagesToUpload.push(p);
448+
if (isImageGenerationError.value === false) {
449+
const imagesToUpload = [];
450+
for (const item of reqData) {
451+
for (const [key, value] of Object.entries(item)) {
452+
if(props.meta.outputImageFields?.includes(key)) {
453+
const p = uploadImage(value, item[primaryKey], key).then(result => {
454+
item[key] = result;
455+
});
456+
imagesToUpload.push(p);
457+
}
455458
}
456459
}
460+
await Promise.all(imagesToUpload);
457461
}
458-
await Promise.all(imagesToUpload);
459462
460463
const res = await callAdminForthApi({
461464
path: `/plugin/${props.meta.pluginInstanceId}/update_fields`,
462465
method: 'POST',
463466
body: {
464467
selectedIds: checkedItemsIDs,
465468
fields: reqData,
469+
saveImages: !isImageGenerationError.value
466470
},
467471
});
468472
@@ -508,7 +512,7 @@ async function generateImages() {
508512
} catch (e) {
509513
console.error('Error generating images:', e);
510514
isError.value = true;
511-
isCriticalError.value = true;
515+
isImageGenerationError.value = true;
512516
errorMessage.value = `Failed to generate images. Please, try to re-run the action.`;
513517
}
514518
isAiResponseReceivedImage.value = props.checkboxes.map(() => true);
@@ -519,7 +523,7 @@ async function generateImages() {
519523
if (!res) {
520524
error = 'Error generating images, something went wrong';
521525
isError.value = true;
522-
isCriticalError.value = true;
526+
isImageGenerationError.value = true;
523527
errorMessage.value = `Failed to generate images. Please, try to re-run the action.`;
524528
}
525529
@@ -528,9 +532,9 @@ async function generateImages() {
528532
message: error,
529533
variant: 'danger',
530534
timeout: 'unlimited',
531-
});;
535+
});
532536
isError.value = true;
533-
isCriticalError.value = true;
537+
isImageGenerationError.value = true;
534538
errorMessage.value = error;
535539
} else {
536540
res.result.forEach((item, idx) => {

index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
360360
if (isAllowedToSave.ok !== false) {
361361
const selectedIds = body.selectedIds || [];
362362
const fieldsToUpdate = body.fields || {};
363+
const saveImages = body.saveImages;
363364
const outputImageFields = [];
364365
if (this.options.generateImages) {
365366
for (const [key, value] of Object.entries(this.options.generateImages)) {
@@ -374,7 +375,7 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
374375
p.resourceConfig!.resourceId === this.resourceConfig.resourceId &&
375376
p.pluginOptions.pathColumnName === value
376377
);
377-
if (columnPlugin) {
378+
if (columnPlugin && saveImages) {
378379
if(columnPlugin.pluginOptions.storageAdapter.objectCanBeAccesedPublicly()) {
379380
if (oldRecord[value]) {
380381
// put tag to delete old file

0 commit comments

Comments
 (0)