Skip to content

Commit 00921e4

Browse files
committed
feat: enhance image generation handling
1 parent ebdec74 commit 00921e4

File tree

2 files changed

+45
-23
lines changed

2 files changed

+45
-23
lines changed

custom/VisionAction.vue

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -101,39 +101,37 @@ const openDialog = async () => {
101101
tableColumnsIndexes.value = result.indexes;
102102
customFieldNames.value = tableHeaders.value.slice((props.meta.isAttachFiles) ? 3 : 2).map(h => h.fieldName);
103103
setSelected();
104+
if (props.meta.isImageGeneration) {
105+
fillCarouselSaveImages();
106+
}
104107
for (let i = 0; i < selected.value?.length; i++) {
105108
openGenerationCarousel.value[i] = props.meta.outputImageFields?.reduce((acc,key) =>{
106109
acc[key] = false;
107110
return acc;
108111
},{[primaryKey]: records.value[i][primaryKey]} as Record<string, boolean>);
109112
}
110113
isFetchingRecords.value = true;
111-
const tasks = [];
114+
112115
if (props.meta.isImageGeneration) {
113-
tasks.push(runAiAction({
116+
runAiAction({
114117
endpoint: 'initial_image_generate',
115118
actionType: 'generate_images',
116119
responseFlag: isAiResponseReceivedImage,
117-
}));
120+
});
118121
}
119122
if (props.meta.isFieldsForAnalizeFromImages) {
120-
tasks.push(runAiAction({
123+
runAiAction({
121124
endpoint: 'analyze',
122125
actionType: 'analyze',
123126
responseFlag: isAiResponseReceivedAnalize,
124-
}));
127+
});
125128
}
126129
if (props.meta.isFieldsForAnalizePlain) {
127-
tasks.push(runAiAction({
130+
runAiAction({
128131
endpoint: 'analyze_no_images',
129132
actionType: 'analyze_no_images',
130133
responseFlag: isAiResponseReceivedAnalize,
131-
}));
132-
}
133-
await Promise.all(tasks);
134-
135-
if (props.meta.isImageGeneration) {
136-
fillCarouselSaveImages();
134+
});
137135
}
138136
139137
isFetchingRecords.value = false;
@@ -144,13 +142,17 @@ watch(selected, (val) => {
144142
checkedCount.value = val.filter(item => item.isChecked === true).length;
145143
}, { deep: true });
146144
145+
watch(carouselSaveImages, (val) => {
146+
console.log('carouselSaveImages changed:', val);
147+
}, { deep: true });
148+
147149
function fillCarouselSaveImages() {
148150
for (const item of selected.value) {
149151
const tempItem: any = {};
150152
const tempItemIndex: any = {};
151153
for (const [key, value] of Object.entries(item)) {
152154
if (props.meta.outputImageFields?.includes(key)) {
153-
tempItem[key] = [value];
155+
tempItem[key] = "";
154156
tempItemIndex[key] = 0;
155157
}
156158
}
@@ -427,17 +429,26 @@ async function runAiAction({
427429
if (actionType !== 'analyze_no_images' || !props.meta.isFieldsForAnalizeFromImages) {
428430
responseFlag.value[i] = true;
429431
}
430-
if (res.result) {
431-
const pk = selected.value[i]?.[primaryKey];
432-
if (pk) {
433-
selected.value[i] = {
434-
...selected.value[i],
435-
...res.result,
436-
isChecked: true,
437-
[primaryKey]: pk,
438-
};
432+
433+
if (res.result) {
434+
if (actionType === 'generate_images') {
435+
for (const [key, value] of Object.entries(carouselSaveImages.value[i])) {
436+
if (props.meta.outputImageFields?.includes(key)) {
437+
carouselSaveImages.value[i][key] = [res.result[key]];
438+
}
439439
}
440440
}
441+
442+
const pk = selected.value[i]?.[primaryKey];
443+
if (pk) {
444+
selected.value[i] = {
445+
...selected.value[i],
446+
...res.result,
447+
isChecked: true,
448+
[primaryKey]: pk,
449+
};
450+
}
451+
}
441452
return { success: true, index: i, data: res };
442453
} catch (e) {
443454
console.error(`Error during ${actionType} for item ${i}:`, e);

index.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
273273
}
274274
});
275275

276+
276277
server.endpoint({
277278
method: 'POST',
278279
path: `/plugin/${this.pluginInstanceId}/analyze_no_images`,
@@ -285,7 +286,7 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
285286
}
286287
//const tasks = selectedIds.map(async (ID) => {
287288
if (STUB_MODE) {
288-
await new Promise((resolve) => setTimeout(resolve, Math.floor(Math.random() * 8000) + 1000));
289+
await new Promise((resolve) => setTimeout(resolve, Math.floor(Math.random() * 20000) + 1000));
289290
return {};
290291
} else {
291292
const primaryKeyColumn = this.resourceConfig.columns.find((col) => col.primaryKey);
@@ -315,6 +316,8 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
315316
// });
316317
}
317318
});
319+
320+
318321
server.endpoint({
319322
method: 'POST',
320323
path: `/plugin/${this.pluginInstanceId}/get_records`,
@@ -335,6 +338,8 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
335338
};
336339
}
337340
});
341+
342+
338343
server.endpoint({
339344
method: 'POST',
340345
path: `/plugin/${this.pluginInstanceId}/get_images`,
@@ -352,6 +357,8 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
352357
};
353358
}
354359
});
360+
361+
355362
server.endpoint({
356363
method: 'POST',
357364
path: `/plugin/${this.pluginInstanceId}/update_fields`,
@@ -435,6 +442,8 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
435442
}
436443
}
437444
});
445+
446+
438447
server.endpoint({
439448
method: 'POST',
440449
path: `/plugin/${this.pluginInstanceId}/regenerate_images`,
@@ -564,6 +573,8 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
564573
return { generationOptions: compiledGenerationOptions };
565574
}
566575
});
576+
577+
567578
server.endpoint({
568579
method: 'GET',
569580
path: `/plugin/${this.pluginInstanceId}/averageDuration`,

0 commit comments

Comments
 (0)