@adminforth/upload 2.2.3 → 2.3.1
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/uploader.vue +11 -12
- package/dist/custom/uploader.vue +11 -12
- package/dist/index.js +14 -7
- package/index.ts +15 -9
- 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 46,
|
|
15
|
-
total size is
|
|
14
|
+
sent 46,954 bytes received 134 bytes 94,176.00 bytes/sec
|
|
15
|
+
total size is 46,465 speedup is 0.99
|
package/custom/uploader.vue
CHANGED
|
@@ -12,27 +12,27 @@
|
|
|
12
12
|
</button>
|
|
13
13
|
|
|
14
14
|
<label :for="inputId"
|
|
15
|
-
class="af-uploader flex flex-col px-3 items-center justify-center w-full h-64 border-2 border-dashed rounded-lg cursor-pointer dark:hover:bg-gray-800 hover:bg-gray-100 dark:hover:border-gray-500 dark:hover:bg-gray-600"
|
|
15
|
+
class="af-uploader flex flex-col px-3 items-center justify-center w-full h-64 border-2 border-dashed rounded-lg cursor-pointer dark:hover:!bg-darkDropzoneBackgroundHover dark:hover:bg-gray-800 hover:!bg-lightDropzoneBackgroundHover hover:bg-gray-100 dark:hover:!border-darkDropzoneBorderHover dark:hover:border-gray-500 dark:hover:!bg-darkDropzoneBackgroundHover dark:hover:bg-gray-600 hover:!border-lightDropzoneBorderHover"
|
|
16
16
|
@dragover.prevent="() => dragging = true"
|
|
17
17
|
@dragleave.prevent="() => dragging = false"
|
|
18
18
|
@drop.prevent="onFileChange"
|
|
19
19
|
:class="{
|
|
20
|
-
'border-blue-600 dark:border-blue-400': dragging,
|
|
21
|
-
'border-gray-300 dark:border-gray-600': !dragging,
|
|
22
|
-
'bg-blue-50 dark:bg-blue-800': dragging,
|
|
23
|
-
'bg-gray-50 dark:bg-gray-800': !dragging,
|
|
20
|
+
'border-blue-600 dark:border-blue-400 !border-lightDropzoneBorderDragging dark:!border-darkDropzoneBorderDragging': dragging,
|
|
21
|
+
'border-gray-300 dark:border-gray-600 !border-lightDropzoneBorder dark:!border-darkDropzoneBorder': !dragging,
|
|
22
|
+
'bg-blue-50 dark:bg-blue-800 !bg-lightDropzoneBackgroundDragging dark:!bg-darkDropzoneBackgroundDragging': dragging,
|
|
23
|
+
'bg-gray-50 dark:bg-gray-800 !bg-lightDropzoneBackground dark:!bg-darkDropzoneBackground': !dragging,
|
|
24
24
|
}"
|
|
25
25
|
>
|
|
26
26
|
<div class="flex flex-col items-center justify-center pt-5 pb-6">
|
|
27
27
|
<img v-if="imgPreview" :src="imgPreview" class="w-100 mt-4 rounded-lg h-40 object-contain" />
|
|
28
28
|
|
|
29
|
-
<svg v-else class="w-8 h-8 mb-4 text-gray-500 dark:text-gray-400" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 20 16">
|
|
29
|
+
<svg v-else class="w-8 h-8 mb-4 text-gray-500 dark:text-gray-400 !text-lightDropzoneText dark:!text-darkDropzoneText" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 20 16">
|
|
30
30
|
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 13h3a3 3 0 0 0 0-6h-.025A5.56 5.56 0 0 0 16 6.5 5.5 5.5 0 0 0 5.207 5.021C5.137 5.017 5.071 5 5 5a4 4 0 0 0 0 8h2.167M10 15V6m0 0L8 8m2-2 2 2"/>
|
|
31
31
|
</svg>
|
|
32
32
|
|
|
33
33
|
<template v-if="!uploaded">
|
|
34
|
-
<p class="mb-2 text-sm text-gray-500 dark:text-gray-400"><span class="font-semibold">{{ $t('Click to upload') }}</span> {{ $t('or drag and drop') }}</p>
|
|
35
|
-
<p class="text-xs text-gray-500 dark:text-gray-400">
|
|
34
|
+
<p class="mb-2 text-sm text-gray-500 dark:text-gray-400 !text-lightDropzoneText dark:!text-darkDropzoneText"><span class="font-semibold">{{ $t('Click to upload') }}</span> {{ $t('or drag and drop') }}</p>
|
|
35
|
+
<p class="text-xs text-gray-500 dark:text-gray-400 !text-lightDropzoneText dark:!text-darkDropzoneText">
|
|
36
36
|
{{ allowedExtensionsLabel }} {{ meta.maxFileSize ? $t(`(up to {size})`, { size: humanifySize(meta.maxFileSize) }) : '' }}
|
|
37
37
|
</p>
|
|
38
38
|
</template>
|
|
@@ -51,11 +51,11 @@
|
|
|
51
51
|
</svg>
|
|
52
52
|
<p class="ml-2 text-sm text-green-600 dark:text-green-400 flex items-center">
|
|
53
53
|
{{ $t('File uploaded') }}
|
|
54
|
-
<span class="text-xs text-gray-500 dark:text-gray-400">{{ humanifySize(uploadedSize) }}</span>
|
|
54
|
+
<span class="text-xs text-gray-500 dark:text-gray-400 !text-lightDropzoneText dark:!text-darkDropzoneText">{{ humanifySize(uploadedSize) }}</span>
|
|
55
55
|
</p>
|
|
56
56
|
|
|
57
57
|
<button @click.stop.prevent="clear" class="ml-2 text-xs text-gray-500 dark:text-gray-400 hover:text-gray-600 dark:hover:text-gray-500
|
|
58
|
-
hover:underline dark:hover:underline focus:outline-none">{{ $t('Clear') }}</button>
|
|
58
|
+
hover:underline dark:hover:underline focus:outline-none !text-lightDropzoneText hover:!text-lightDropzoneText dark:!text-darkDropzoneText dark:hover:!text-darkDropzoneText">{{ $t('Clear') }}</button>
|
|
59
59
|
</div>
|
|
60
60
|
|
|
61
61
|
</div>
|
|
@@ -72,7 +72,6 @@ import { IconMagic } from '@iconify-prerendered/vue-mdi';
|
|
|
72
72
|
import { useI18n } from 'vue-i18n';
|
|
73
73
|
import { useRoute } from 'vue-router';
|
|
74
74
|
|
|
75
|
-
|
|
76
75
|
const route = useRoute();
|
|
77
76
|
const { t } = useI18n();
|
|
78
77
|
|
|
@@ -195,7 +194,7 @@ const onFileChange = async (e) => {
|
|
|
195
194
|
console.log('File details:', { name, extension, size, type });
|
|
196
195
|
// validate file extension
|
|
197
196
|
const allowedExtensions = props.meta.allowedExtensions || []
|
|
198
|
-
if (allowedExtensions.length > 0 && !allowedExtensions.includes(extension)) {
|
|
197
|
+
if (allowedExtensions.length > 0 && !allowedExtensions.includes(extension.toLowerCase())) {
|
|
199
198
|
adminforth.alert({
|
|
200
199
|
message: t('Sorry but the file type {extension} is not allowed. Please upload a file with one of the following extensions: {allowedExtensionsLabel}', {
|
|
201
200
|
extension,
|
package/dist/custom/uploader.vue
CHANGED
|
@@ -12,27 +12,27 @@
|
|
|
12
12
|
</button>
|
|
13
13
|
|
|
14
14
|
<label :for="inputId"
|
|
15
|
-
class="af-uploader flex flex-col px-3 items-center justify-center w-full h-64 border-2 border-dashed rounded-lg cursor-pointer dark:hover:bg-gray-800 hover:bg-gray-100 dark:hover:border-gray-500 dark:hover:bg-gray-600"
|
|
15
|
+
class="af-uploader flex flex-col px-3 items-center justify-center w-full h-64 border-2 border-dashed rounded-lg cursor-pointer dark:hover:!bg-darkDropzoneBackgroundHover dark:hover:bg-gray-800 hover:!bg-lightDropzoneBackgroundHover hover:bg-gray-100 dark:hover:!border-darkDropzoneBorderHover dark:hover:border-gray-500 dark:hover:!bg-darkDropzoneBackgroundHover dark:hover:bg-gray-600 hover:!border-lightDropzoneBorderHover"
|
|
16
16
|
@dragover.prevent="() => dragging = true"
|
|
17
17
|
@dragleave.prevent="() => dragging = false"
|
|
18
18
|
@drop.prevent="onFileChange"
|
|
19
19
|
:class="{
|
|
20
|
-
'border-blue-600 dark:border-blue-400': dragging,
|
|
21
|
-
'border-gray-300 dark:border-gray-600': !dragging,
|
|
22
|
-
'bg-blue-50 dark:bg-blue-800': dragging,
|
|
23
|
-
'bg-gray-50 dark:bg-gray-800': !dragging,
|
|
20
|
+
'border-blue-600 dark:border-blue-400 !border-lightDropzoneBorderDragging dark:!border-darkDropzoneBorderDragging': dragging,
|
|
21
|
+
'border-gray-300 dark:border-gray-600 !border-lightDropzoneBorder dark:!border-darkDropzoneBorder': !dragging,
|
|
22
|
+
'bg-blue-50 dark:bg-blue-800 !bg-lightDropzoneBackgroundDragging dark:!bg-darkDropzoneBackgroundDragging': dragging,
|
|
23
|
+
'bg-gray-50 dark:bg-gray-800 !bg-lightDropzoneBackground dark:!bg-darkDropzoneBackground': !dragging,
|
|
24
24
|
}"
|
|
25
25
|
>
|
|
26
26
|
<div class="flex flex-col items-center justify-center pt-5 pb-6">
|
|
27
27
|
<img v-if="imgPreview" :src="imgPreview" class="w-100 mt-4 rounded-lg h-40 object-contain" />
|
|
28
28
|
|
|
29
|
-
<svg v-else class="w-8 h-8 mb-4 text-gray-500 dark:text-gray-400" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 20 16">
|
|
29
|
+
<svg v-else class="w-8 h-8 mb-4 text-gray-500 dark:text-gray-400 !text-lightDropzoneText dark:!text-darkDropzoneText" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 20 16">
|
|
30
30
|
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 13h3a3 3 0 0 0 0-6h-.025A5.56 5.56 0 0 0 16 6.5 5.5 5.5 0 0 0 5.207 5.021C5.137 5.017 5.071 5 5 5a4 4 0 0 0 0 8h2.167M10 15V6m0 0L8 8m2-2 2 2"/>
|
|
31
31
|
</svg>
|
|
32
32
|
|
|
33
33
|
<template v-if="!uploaded">
|
|
34
|
-
<p class="mb-2 text-sm text-gray-500 dark:text-gray-400"><span class="font-semibold">{{ $t('Click to upload') }}</span> {{ $t('or drag and drop') }}</p>
|
|
35
|
-
<p class="text-xs text-gray-500 dark:text-gray-400">
|
|
34
|
+
<p class="mb-2 text-sm text-gray-500 dark:text-gray-400 !text-lightDropzoneText dark:!text-darkDropzoneText"><span class="font-semibold">{{ $t('Click to upload') }}</span> {{ $t('or drag and drop') }}</p>
|
|
35
|
+
<p class="text-xs text-gray-500 dark:text-gray-400 !text-lightDropzoneText dark:!text-darkDropzoneText">
|
|
36
36
|
{{ allowedExtensionsLabel }} {{ meta.maxFileSize ? $t(`(up to {size})`, { size: humanifySize(meta.maxFileSize) }) : '' }}
|
|
37
37
|
</p>
|
|
38
38
|
</template>
|
|
@@ -51,11 +51,11 @@
|
|
|
51
51
|
</svg>
|
|
52
52
|
<p class="ml-2 text-sm text-green-600 dark:text-green-400 flex items-center">
|
|
53
53
|
{{ $t('File uploaded') }}
|
|
54
|
-
<span class="text-xs text-gray-500 dark:text-gray-400">{{ humanifySize(uploadedSize) }}</span>
|
|
54
|
+
<span class="text-xs text-gray-500 dark:text-gray-400 !text-lightDropzoneText dark:!text-darkDropzoneText">{{ humanifySize(uploadedSize) }}</span>
|
|
55
55
|
</p>
|
|
56
56
|
|
|
57
57
|
<button @click.stop.prevent="clear" class="ml-2 text-xs text-gray-500 dark:text-gray-400 hover:text-gray-600 dark:hover:text-gray-500
|
|
58
|
-
hover:underline dark:hover:underline focus:outline-none">{{ $t('Clear') }}</button>
|
|
58
|
+
hover:underline dark:hover:underline focus:outline-none !text-lightDropzoneText hover:!text-lightDropzoneText dark:!text-darkDropzoneText dark:hover:!text-darkDropzoneText">{{ $t('Clear') }}</button>
|
|
59
59
|
</div>
|
|
60
60
|
|
|
61
61
|
</div>
|
|
@@ -72,7 +72,6 @@ import { IconMagic } from '@iconify-prerendered/vue-mdi';
|
|
|
72
72
|
import { useI18n } from 'vue-i18n';
|
|
73
73
|
import { useRoute } from 'vue-router';
|
|
74
74
|
|
|
75
|
-
|
|
76
75
|
const route = useRoute();
|
|
77
76
|
const { t } = useI18n();
|
|
78
77
|
|
|
@@ -195,7 +194,7 @@ const onFileChange = async (e) => {
|
|
|
195
194
|
console.log('File details:', { name, extension, size, type });
|
|
196
195
|
// validate file extension
|
|
197
196
|
const allowedExtensions = props.meta.allowedExtensions || []
|
|
198
|
-
if (allowedExtensions.length > 0 && !allowedExtensions.includes(extension)) {
|
|
197
|
+
if (allowedExtensions.length > 0 && !allowedExtensions.includes(extension.toLowerCase())) {
|
|
199
198
|
adminforth.alert({
|
|
200
199
|
message: t('Sorry but the file type {extension} is not allowed. Please upload a file with one of the following extensions: {allowedExtensionsLabel}', {
|
|
201
200
|
extension,
|
package/dist/index.js
CHANGED
|
@@ -248,7 +248,7 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
248
248
|
handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body }) {
|
|
249
249
|
var _b, _c;
|
|
250
250
|
const { originalFilename, contentType, size, originalExtension, recordPk } = body;
|
|
251
|
-
if (this.options.allowedFileExtensions && !this.options.allowedFileExtensions.includes(originalExtension)) {
|
|
251
|
+
if (this.options.allowedFileExtensions && !this.options.allowedFileExtensions.includes(originalExtension.toLowerCase())) {
|
|
252
252
|
return {
|
|
253
253
|
error: `File extension "${originalExtension}" is not allowed, allowed extensions are: ${this.options.allowedFileExtensions.join(', ')}`
|
|
254
254
|
};
|
|
@@ -334,12 +334,19 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
334
334
|
return `https://picsum.photos/200/300?random=${Math.floor(Math.random() * 1000)}`;
|
|
335
335
|
}
|
|
336
336
|
const start = +new Date();
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
337
|
+
let resp;
|
|
338
|
+
try {
|
|
339
|
+
resp = yield this.options.generation.adapter.generate({
|
|
340
|
+
prompt,
|
|
341
|
+
inputFiles: attachmentFiles,
|
|
342
|
+
n: 1,
|
|
343
|
+
size: this.options.generation.outputSize,
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
catch (e) {
|
|
347
|
+
error = `No response from image generation provider: ${e.message}. Please check your prompt or try again later.`;
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
343
350
|
if (resp.error) {
|
|
344
351
|
console.error('Error generating image', resp.error);
|
|
345
352
|
error = resp.error;
|
package/index.ts
CHANGED
|
@@ -281,7 +281,7 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
281
281
|
handler: async ({ body }) => {
|
|
282
282
|
const { originalFilename, contentType, size, originalExtension, recordPk } = body;
|
|
283
283
|
|
|
284
|
-
if (this.options.allowedFileExtensions && !this.options.allowedFileExtensions.includes(originalExtension)) {
|
|
284
|
+
if (this.options.allowedFileExtensions && !this.options.allowedFileExtensions.includes(originalExtension.toLowerCase())) {
|
|
285
285
|
return {
|
|
286
286
|
error: `File extension "${originalExtension}" is not allowed, allowed extensions are: ${this.options.allowedFileExtensions.join(', ')}`
|
|
287
287
|
};
|
|
@@ -386,14 +386,20 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
386
386
|
return `https://picsum.photos/200/300?random=${Math.floor(Math.random() * 1000)}`;
|
|
387
387
|
}
|
|
388
388
|
const start = +new Date();
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
389
|
+
let resp;
|
|
390
|
+
try {
|
|
391
|
+
resp = await this.options.generation.adapter.generate(
|
|
392
|
+
{
|
|
393
|
+
prompt,
|
|
394
|
+
inputFiles: attachmentFiles,
|
|
395
|
+
n: 1,
|
|
396
|
+
size: this.options.generation.outputSize,
|
|
397
|
+
}
|
|
398
|
+
)
|
|
399
|
+
} catch (e: any) {
|
|
400
|
+
error = `No response from image generation provider: ${e.message}. Please check your prompt or try again later.`;
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
397
403
|
|
|
398
404
|
if (resp.error) {
|
|
399
405
|
console.error('Error generating image', resp.error);
|