@adminforth/upload 1.4.6 → 1.4.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build.log +2 -2
- package/custom/imageGenerator.vue +22 -13
- package/dist/custom/imageGenerator.vue +22 -13
- package/dist/index.js +17 -0
- package/index.ts +24 -0
- package/package.json +1 -1
package/build.log
CHANGED
|
@@ -11,5 +11,5 @@ custom/preview.vue
|
|
|
11
11
|
custom/tsconfig.json
|
|
12
12
|
custom/uploader.vue
|
|
13
13
|
|
|
14
|
-
sent
|
|
15
|
-
total size is 42,
|
|
14
|
+
sent 43,060 bytes received 134 bytes 86,388.00 bytes/sec
|
|
15
|
+
total size is 42,578 speedup is 0.99
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
:minValue="0"
|
|
51
51
|
:maxValue="historicalAverage"
|
|
52
52
|
:showValues="false"
|
|
53
|
-
:progressFormatter="(value: number, percentage: number) => `${ formatTime(loadingTimer) } ( ${ Math.floor( (
|
|
53
|
+
:progressFormatter="(value: number, percentage: number) => `${ formatTime(loadingTimer) } ( ~ ${ Math.floor( (
|
|
54
54
|
loadingTimer < historicalAverage ? loadingTimer : historicalAverage
|
|
55
55
|
) / historicalAverage * 100) }% )`"
|
|
56
56
|
/>
|
|
@@ -252,15 +252,10 @@ async function confirmImage() {
|
|
|
252
252
|
|
|
253
253
|
const loadingTimer: Ref<number | null> = ref(null);
|
|
254
254
|
|
|
255
|
-
const historicalRuns: Ref<number[]> = ref([]);
|
|
256
255
|
|
|
257
256
|
const errorMessage: Ref<string | null> = ref(null);
|
|
258
257
|
|
|
259
|
-
const historicalAverage: Ref<number | null> =
|
|
260
|
-
if (historicalRuns.value.length === 0) return null;
|
|
261
|
-
const sum = historicalRuns.value.reduce((a, b) => a + b, 0);
|
|
262
|
-
return Math.floor(sum / historicalRuns.value.length);
|
|
263
|
-
});
|
|
258
|
+
const historicalAverage: Ref<number | null> = ref(null);
|
|
264
259
|
|
|
265
260
|
|
|
266
261
|
function formatTime(seconds: number): string {
|
|
@@ -269,6 +264,14 @@ function formatTime(seconds: number): string {
|
|
|
269
264
|
}
|
|
270
265
|
|
|
271
266
|
|
|
267
|
+
async function getHistoricalAverage() {
|
|
268
|
+
const resp = await callAdminForthApi({
|
|
269
|
+
path: `/plugin/${props.meta.pluginInstanceId}/averageDuration`,
|
|
270
|
+
method: 'GET',
|
|
271
|
+
});
|
|
272
|
+
historicalAverage.value = resp?.averageDuration || null;
|
|
273
|
+
}
|
|
274
|
+
|
|
272
275
|
async function generateImages() {
|
|
273
276
|
errorMessage.value = null;
|
|
274
277
|
loading.value = true;
|
|
@@ -279,7 +282,8 @@ async function generateImages() {
|
|
|
279
282
|
loadingTimer.value = elapsed;
|
|
280
283
|
}, 100);
|
|
281
284
|
const currentIndex = caurosel.value?.getActiveItem()?.position || 0;
|
|
282
|
-
|
|
285
|
+
|
|
286
|
+
await getHistoricalAverage();
|
|
283
287
|
let resp = null;
|
|
284
288
|
let error = null;
|
|
285
289
|
try {
|
|
@@ -294,7 +298,6 @@ async function generateImages() {
|
|
|
294
298
|
} catch (e) {
|
|
295
299
|
console.error(e);
|
|
296
300
|
} finally {
|
|
297
|
-
historicalRuns.value.push(loadingTimer.value);
|
|
298
301
|
clearInterval(ticker);
|
|
299
302
|
loadingTimer.value = null;
|
|
300
303
|
loading.value = false;
|
|
@@ -330,12 +333,17 @@ async function generateImages() {
|
|
|
330
333
|
// ];
|
|
331
334
|
await nextTick();
|
|
332
335
|
|
|
336
|
+
|
|
333
337
|
caurosel.value = new Carousel(
|
|
334
338
|
document.getElementById('gallery'),
|
|
335
|
-
images.value.map((img, index) =>
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
+
images.value.map((img, index) => {
|
|
340
|
+
console.log('mapping image', img, index);
|
|
341
|
+
return {
|
|
342
|
+
image: img,
|
|
343
|
+
el: document.getElementById('gallery').querySelector(`[data-carousel-item]:nth-child(${index + 1})`),
|
|
344
|
+
position: index,
|
|
345
|
+
};
|
|
346
|
+
}),
|
|
339
347
|
{
|
|
340
348
|
internal: 0,
|
|
341
349
|
defaultPosition: currentIndex,
|
|
@@ -345,6 +353,7 @@ async function generateImages() {
|
|
|
345
353
|
}
|
|
346
354
|
);
|
|
347
355
|
await nextTick();
|
|
356
|
+
|
|
348
357
|
loading.value = false;
|
|
349
358
|
}
|
|
350
359
|
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
:minValue="0"
|
|
51
51
|
:maxValue="historicalAverage"
|
|
52
52
|
:showValues="false"
|
|
53
|
-
:progressFormatter="(value: number, percentage: number) => `${ formatTime(loadingTimer) } ( ${ Math.floor( (
|
|
53
|
+
:progressFormatter="(value: number, percentage: number) => `${ formatTime(loadingTimer) } ( ~ ${ Math.floor( (
|
|
54
54
|
loadingTimer < historicalAverage ? loadingTimer : historicalAverage
|
|
55
55
|
) / historicalAverage * 100) }% )`"
|
|
56
56
|
/>
|
|
@@ -252,15 +252,10 @@ async function confirmImage() {
|
|
|
252
252
|
|
|
253
253
|
const loadingTimer: Ref<number | null> = ref(null);
|
|
254
254
|
|
|
255
|
-
const historicalRuns: Ref<number[]> = ref([]);
|
|
256
255
|
|
|
257
256
|
const errorMessage: Ref<string | null> = ref(null);
|
|
258
257
|
|
|
259
|
-
const historicalAverage: Ref<number | null> =
|
|
260
|
-
if (historicalRuns.value.length === 0) return null;
|
|
261
|
-
const sum = historicalRuns.value.reduce((a, b) => a + b, 0);
|
|
262
|
-
return Math.floor(sum / historicalRuns.value.length);
|
|
263
|
-
});
|
|
258
|
+
const historicalAverage: Ref<number | null> = ref(null);
|
|
264
259
|
|
|
265
260
|
|
|
266
261
|
function formatTime(seconds: number): string {
|
|
@@ -269,6 +264,14 @@ function formatTime(seconds: number): string {
|
|
|
269
264
|
}
|
|
270
265
|
|
|
271
266
|
|
|
267
|
+
async function getHistoricalAverage() {
|
|
268
|
+
const resp = await callAdminForthApi({
|
|
269
|
+
path: `/plugin/${props.meta.pluginInstanceId}/averageDuration`,
|
|
270
|
+
method: 'GET',
|
|
271
|
+
});
|
|
272
|
+
historicalAverage.value = resp?.averageDuration || null;
|
|
273
|
+
}
|
|
274
|
+
|
|
272
275
|
async function generateImages() {
|
|
273
276
|
errorMessage.value = null;
|
|
274
277
|
loading.value = true;
|
|
@@ -279,7 +282,8 @@ async function generateImages() {
|
|
|
279
282
|
loadingTimer.value = elapsed;
|
|
280
283
|
}, 100);
|
|
281
284
|
const currentIndex = caurosel.value?.getActiveItem()?.position || 0;
|
|
282
|
-
|
|
285
|
+
|
|
286
|
+
await getHistoricalAverage();
|
|
283
287
|
let resp = null;
|
|
284
288
|
let error = null;
|
|
285
289
|
try {
|
|
@@ -294,7 +298,6 @@ async function generateImages() {
|
|
|
294
298
|
} catch (e) {
|
|
295
299
|
console.error(e);
|
|
296
300
|
} finally {
|
|
297
|
-
historicalRuns.value.push(loadingTimer.value);
|
|
298
301
|
clearInterval(ticker);
|
|
299
302
|
loadingTimer.value = null;
|
|
300
303
|
loading.value = false;
|
|
@@ -330,12 +333,17 @@ async function generateImages() {
|
|
|
330
333
|
// ];
|
|
331
334
|
await nextTick();
|
|
332
335
|
|
|
336
|
+
|
|
333
337
|
caurosel.value = new Carousel(
|
|
334
338
|
document.getElementById('gallery'),
|
|
335
|
-
images.value.map((img, index) =>
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
+
images.value.map((img, index) => {
|
|
340
|
+
console.log('mapping image', img, index);
|
|
341
|
+
return {
|
|
342
|
+
image: img,
|
|
343
|
+
el: document.getElementById('gallery').querySelector(`[data-carousel-item]:nth-child(${index + 1})`),
|
|
344
|
+
position: index,
|
|
345
|
+
};
|
|
346
|
+
}),
|
|
339
347
|
{
|
|
340
348
|
internal: 0,
|
|
341
349
|
defaultPosition: currentIndex,
|
|
@@ -345,6 +353,7 @@ async function generateImages() {
|
|
|
345
353
|
}
|
|
346
354
|
);
|
|
347
355
|
await nextTick();
|
|
356
|
+
|
|
348
357
|
loading.value = false;
|
|
349
358
|
}
|
|
350
359
|
|
package/dist/index.js
CHANGED
|
@@ -17,6 +17,9 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
17
17
|
constructor(options) {
|
|
18
18
|
super(options, import.meta.url);
|
|
19
19
|
this.options = options;
|
|
20
|
+
// for calcualting average time
|
|
21
|
+
this.totalCalls = 0;
|
|
22
|
+
this.totalDuration = 0;
|
|
20
23
|
}
|
|
21
24
|
instanceUniqueRepresentation(pluginOptions) {
|
|
22
25
|
return `${pluginOptions.pathColumnName}`;
|
|
@@ -354,6 +357,17 @@ getBucketLifecycleConfiguration on bucket ${this.options.s3Bucket} in region ${t
|
|
|
354
357
|
this.setupLifecycleRule();
|
|
355
358
|
}
|
|
356
359
|
setupEndpoints(server) {
|
|
360
|
+
server.endpoint({
|
|
361
|
+
method: 'GET',
|
|
362
|
+
path: `/plugin/${this.pluginInstanceId}/averageDuration`,
|
|
363
|
+
handler: () => __awaiter(this, void 0, void 0, function* () {
|
|
364
|
+
return {
|
|
365
|
+
totalCalls: this.totalCalls,
|
|
366
|
+
totalDuration: this.totalDuration,
|
|
367
|
+
averageDuration: this.totalCalls ? this.totalDuration / this.totalCalls : null,
|
|
368
|
+
};
|
|
369
|
+
})
|
|
370
|
+
});
|
|
357
371
|
server.endpoint({
|
|
358
372
|
method: 'POST',
|
|
359
373
|
path: `/plugin/${this.pluginInstanceId}/get_s3_upload_url`,
|
|
@@ -467,6 +481,7 @@ getBucketLifecycleConfiguration on bucket ${this.options.s3Bucket} in region ${t
|
|
|
467
481
|
yield new Promise((resolve) => setTimeout(resolve, 2000));
|
|
468
482
|
return `https://picsum.photos/200/300?random=${Math.floor(Math.random() * 1000)}`;
|
|
469
483
|
}
|
|
484
|
+
const start = +new Date();
|
|
470
485
|
const resp = yield this.options.generation.adapter.generate({
|
|
471
486
|
prompt,
|
|
472
487
|
inputFiles: attachmentFiles,
|
|
@@ -478,6 +493,8 @@ getBucketLifecycleConfiguration on bucket ${this.options.s3Bucket} in region ${t
|
|
|
478
493
|
error = resp.error;
|
|
479
494
|
return;
|
|
480
495
|
}
|
|
496
|
+
this.totalCalls++;
|
|
497
|
+
this.totalDuration += (+new Date() - start) / 1000;
|
|
481
498
|
return resp.imageURLs[0];
|
|
482
499
|
})));
|
|
483
500
|
return { error, images };
|
package/index.ts
CHANGED
|
@@ -13,9 +13,16 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
13
13
|
|
|
14
14
|
adminforth!: IAdminForth;
|
|
15
15
|
|
|
16
|
+
totalCalls: number;
|
|
17
|
+
totalDuration: number;
|
|
18
|
+
|
|
16
19
|
constructor(options: PluginOptions) {
|
|
17
20
|
super(options, import.meta.url);
|
|
18
21
|
this.options = options;
|
|
22
|
+
|
|
23
|
+
// for calcualting average time
|
|
24
|
+
this.totalCalls = 0;
|
|
25
|
+
this.totalDuration = 0;
|
|
19
26
|
}
|
|
20
27
|
|
|
21
28
|
instanceUniqueRepresentation(pluginOptions: any) : string {
|
|
@@ -390,8 +397,21 @@ getBucketLifecycleConfiguration on bucket ${this.options.s3Bucket} in region ${t
|
|
|
390
397
|
// called here because modifyResourceConfig can be called in build time where there is no environment and AWS secrets
|
|
391
398
|
this.setupLifecycleRule();
|
|
392
399
|
}
|
|
400
|
+
|
|
393
401
|
|
|
394
402
|
setupEndpoints(server: IHttpServer) {
|
|
403
|
+
server.endpoint({
|
|
404
|
+
method: 'GET',
|
|
405
|
+
path: `/plugin/${this.pluginInstanceId}/averageDuration`,
|
|
406
|
+
handler: async () => {
|
|
407
|
+
return {
|
|
408
|
+
totalCalls: this.totalCalls,
|
|
409
|
+
totalDuration: this.totalDuration,
|
|
410
|
+
averageDuration: this.totalCalls ? this.totalDuration / this.totalCalls : null,
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
});
|
|
414
|
+
|
|
395
415
|
server.endpoint({
|
|
396
416
|
method: 'POST',
|
|
397
417
|
path: `/plugin/${this.pluginInstanceId}/get_s3_upload_url`,
|
|
@@ -527,6 +547,7 @@ getBucketLifecycleConfiguration on bucket ${this.options.s3Bucket} in region ${t
|
|
|
527
547
|
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
528
548
|
return `https://picsum.photos/200/300?random=${Math.floor(Math.random() * 1000)}`;
|
|
529
549
|
}
|
|
550
|
+
const start = +new Date();
|
|
530
551
|
const resp = await this.options.generation.adapter.generate(
|
|
531
552
|
{
|
|
532
553
|
prompt,
|
|
@@ -541,6 +562,9 @@ getBucketLifecycleConfiguration on bucket ${this.options.s3Bucket} in region ${t
|
|
|
541
562
|
error = resp.error;
|
|
542
563
|
return;
|
|
543
564
|
}
|
|
565
|
+
|
|
566
|
+
this.totalCalls++;
|
|
567
|
+
this.totalDuration += (+new Date() - start) / 1000;
|
|
544
568
|
|
|
545
569
|
return resp.imageURLs[0]
|
|
546
570
|
|