@adminforth/upload 1.0.20 → 1.0.22
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/custom/uploader.vue +11 -2
- package/dist/custom/uploader.vue +11 -2
- package/dist/index.js +3 -3
- package/index.ts +5 -3
- package/package.json +1 -1
package/custom/uploader.vue
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
<IconMagic class="w-5 h-5"/>
|
|
12
12
|
</button>
|
|
13
13
|
|
|
14
|
-
<label for="
|
|
14
|
+
<label :for="inputId"
|
|
15
15
|
class="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"
|
|
16
16
|
@dragover.prevent="() => dragging = true"
|
|
17
17
|
@dragleave.prevent="() => dragging = false"
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
</div>
|
|
60
60
|
|
|
61
61
|
</div>
|
|
62
|
-
<input id="
|
|
62
|
+
<input :id="inputId" type="file" class="hidden" @change="onFileChange" ref="uploadInputRef" />
|
|
63
63
|
</label>
|
|
64
64
|
</div>
|
|
65
65
|
|
|
@@ -70,6 +70,7 @@ import { computed, ref, onMounted, watch } from 'vue'
|
|
|
70
70
|
import { callAdminForthApi } from '@/utils'
|
|
71
71
|
import { IconMagic } from '@iconify-prerendered/vue-mdi';
|
|
72
72
|
|
|
73
|
+
const inputId = computed(() => `dropzone-file-${props.meta.pluginInstanceId}`);
|
|
73
74
|
|
|
74
75
|
import ImageGenerator from '@@/plugins/UploadPlugin/imageGenerator.vue';
|
|
75
76
|
|
|
@@ -85,6 +86,8 @@ const emit = defineEmits([
|
|
|
85
86
|
'update:emptiness',
|
|
86
87
|
]);
|
|
87
88
|
|
|
89
|
+
const uploadInputRef = ref(null);
|
|
90
|
+
|
|
88
91
|
const showImageGen = ref(false);
|
|
89
92
|
const dragging = ref(false);
|
|
90
93
|
|
|
@@ -136,6 +139,7 @@ function clear() {
|
|
|
136
139
|
progress.value = 0;
|
|
137
140
|
uploaded.value = false;
|
|
138
141
|
uploadedSize.value = 0;
|
|
142
|
+
uploadInputRef.value.value = null;
|
|
139
143
|
emit('update:value', null);
|
|
140
144
|
}
|
|
141
145
|
|
|
@@ -154,6 +158,11 @@ function humanifySize(size) {
|
|
|
154
158
|
|
|
155
159
|
|
|
156
160
|
const onFileChange = async (e) => {
|
|
161
|
+
// if empty then return
|
|
162
|
+
if (!e.target.files || e.target.files.length === 0) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
|
|
157
166
|
imgPreview.value = null;
|
|
158
167
|
progress.value = 0;
|
|
159
168
|
uploaded.value = false;
|
package/dist/custom/uploader.vue
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
<IconMagic class="w-5 h-5"/>
|
|
12
12
|
</button>
|
|
13
13
|
|
|
14
|
-
<label for="
|
|
14
|
+
<label :for="inputId"
|
|
15
15
|
class="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"
|
|
16
16
|
@dragover.prevent="() => dragging = true"
|
|
17
17
|
@dragleave.prevent="() => dragging = false"
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
</div>
|
|
60
60
|
|
|
61
61
|
</div>
|
|
62
|
-
<input id="
|
|
62
|
+
<input :id="inputId" type="file" class="hidden" @change="onFileChange" ref="uploadInputRef" />
|
|
63
63
|
</label>
|
|
64
64
|
</div>
|
|
65
65
|
|
|
@@ -70,6 +70,7 @@ import { computed, ref, onMounted, watch } from 'vue'
|
|
|
70
70
|
import { callAdminForthApi } from '@/utils'
|
|
71
71
|
import { IconMagic } from '@iconify-prerendered/vue-mdi';
|
|
72
72
|
|
|
73
|
+
const inputId = computed(() => `dropzone-file-${props.meta.pluginInstanceId}`);
|
|
73
74
|
|
|
74
75
|
import ImageGenerator from '@@/plugins/UploadPlugin/imageGenerator.vue';
|
|
75
76
|
|
|
@@ -85,6 +86,8 @@ const emit = defineEmits([
|
|
|
85
86
|
'update:emptiness',
|
|
86
87
|
]);
|
|
87
88
|
|
|
89
|
+
const uploadInputRef = ref(null);
|
|
90
|
+
|
|
88
91
|
const showImageGen = ref(false);
|
|
89
92
|
const dragging = ref(false);
|
|
90
93
|
|
|
@@ -136,6 +139,7 @@ function clear() {
|
|
|
136
139
|
progress.value = 0;
|
|
137
140
|
uploaded.value = false;
|
|
138
141
|
uploadedSize.value = 0;
|
|
142
|
+
uploadInputRef.value.value = null;
|
|
139
143
|
emit('update:value', null);
|
|
140
144
|
}
|
|
141
145
|
|
|
@@ -154,6 +158,11 @@ function humanifySize(size) {
|
|
|
154
158
|
|
|
155
159
|
|
|
156
160
|
const onFileChange = async (e) => {
|
|
161
|
+
// if empty then return
|
|
162
|
+
if (!e.target.files || e.target.files.length === 0) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
|
|
157
166
|
imgPreview.value = null;
|
|
158
167
|
progress.value = 0;
|
|
159
168
|
uploaded.value = false;
|
package/dist/index.js
CHANGED
|
@@ -11,7 +11,7 @@ import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
|
|
|
11
11
|
import { ExpirationStatus, GetObjectCommand, PutObjectCommand, S3 } from '@aws-sdk/client-s3';
|
|
12
12
|
import { AdminForthPlugin, suggestIfTypo } from "adminforth";
|
|
13
13
|
import { Readable } from "stream";
|
|
14
|
-
import { RateLimiter
|
|
14
|
+
import { RateLimiter } from "adminforth";
|
|
15
15
|
const ADMINFORTH_NOT_YET_USED_TAG = 'adminforth-candidate-for-cleanup';
|
|
16
16
|
export default class UploadPlugin extends AdminForthPlugin {
|
|
17
17
|
constructor(options) {
|
|
@@ -329,6 +329,7 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
329
329
|
});
|
|
330
330
|
}
|
|
331
331
|
validateConfigAfterDiscover(adminforth, resourceConfig) {
|
|
332
|
+
this.adminforth = adminforth;
|
|
332
333
|
// called here because modifyResourceConfig can be called in build time where there is no environment and AWS secrets
|
|
333
334
|
this.setupLifecycleRule();
|
|
334
335
|
}
|
|
@@ -370,7 +371,6 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
370
371
|
let previewUrl;
|
|
371
372
|
if ((_b = this.options.preview) === null || _b === void 0 ? void 0 : _b.previewUrl) {
|
|
372
373
|
previewUrl = this.options.preview.previewUrl({ s3Path });
|
|
373
|
-
return;
|
|
374
374
|
}
|
|
375
375
|
else if (this.options.s3ACL === 'public-read') {
|
|
376
376
|
previewUrl = `https://${this.options.s3Bucket}.s3.${this.options.s3Region}.amazonaws.com/${s3Path}`;
|
|
@@ -418,7 +418,7 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
418
418
|
}
|
|
419
419
|
if ((_d = this.options.generation.rateLimit) === null || _d === void 0 ? void 0 : _d.limit) {
|
|
420
420
|
// rate limit
|
|
421
|
-
const { error } = RateLimiter.checkRateLimit(this.pluginInstanceId, (_e = this.options.generation.rateLimit) === null || _e === void 0 ? void 0 : _e.limit, getClientIp(headers));
|
|
421
|
+
const { error } = RateLimiter.checkRateLimit(this.pluginInstanceId, (_e = this.options.generation.rateLimit) === null || _e === void 0 ? void 0 : _e.limit, this.adminforth.auth.getClientIp(headers));
|
|
422
422
|
if (error) {
|
|
423
423
|
return { error: this.options.generation.rateLimit.errorMessage };
|
|
424
424
|
}
|
package/index.ts
CHANGED
|
@@ -4,13 +4,15 @@ import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
|
|
|
4
4
|
import { ExpirationStatus, GetObjectCommand, ObjectCannedACL, PutObjectCommand, S3 } from '@aws-sdk/client-s3';
|
|
5
5
|
import { AdminForthPlugin, AdminForthResourceColumn, AdminForthResourcePages, IAdminForth, IHttpServer, suggestIfTypo } from "adminforth";
|
|
6
6
|
import { Readable } from "stream";
|
|
7
|
-
import { RateLimiter
|
|
7
|
+
import { RateLimiter } from "adminforth";
|
|
8
8
|
|
|
9
9
|
const ADMINFORTH_NOT_YET_USED_TAG = 'adminforth-candidate-for-cleanup';
|
|
10
10
|
|
|
11
11
|
export default class UploadPlugin extends AdminForthPlugin {
|
|
12
12
|
options: PluginOptions;
|
|
13
13
|
|
|
14
|
+
adminforth!: IAdminForth;
|
|
15
|
+
|
|
14
16
|
constructor(options: PluginOptions) {
|
|
15
17
|
super(options, import.meta.url);
|
|
16
18
|
this.options = options;
|
|
@@ -363,6 +365,7 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
363
365
|
}
|
|
364
366
|
|
|
365
367
|
validateConfigAfterDiscover(adminforth: IAdminForth, resourceConfig: any) {
|
|
368
|
+
this.adminforth = adminforth;
|
|
366
369
|
// called here because modifyResourceConfig can be called in build time where there is no environment and AWS secrets
|
|
367
370
|
this.setupLifecycleRule();
|
|
368
371
|
}
|
|
@@ -410,7 +413,6 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
410
413
|
let previewUrl;
|
|
411
414
|
if (this.options.preview?.previewUrl) {
|
|
412
415
|
previewUrl = this.options.preview.previewUrl({ s3Path });
|
|
413
|
-
return;
|
|
414
416
|
} else if (this.options.s3ACL === 'public-read') {
|
|
415
417
|
previewUrl = `https://${this.options.s3Bucket}.s3.${this.options.s3Region}.amazonaws.com/${s3Path}`;
|
|
416
418
|
} else {
|
|
@@ -464,7 +466,7 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
464
466
|
const { error } = RateLimiter.checkRateLimit(
|
|
465
467
|
this.pluginInstanceId,
|
|
466
468
|
this.options.generation.rateLimit?.limit,
|
|
467
|
-
getClientIp(headers),
|
|
469
|
+
this.adminforth.auth.getClientIp(headers),
|
|
468
470
|
);
|
|
469
471
|
if (error) {
|
|
470
472
|
return { error: this.options.generation.rateLimit.errorMessage };
|