@adminforth/upload 1.0.9 → 1.0.11

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.
@@ -47,7 +47,7 @@
47
47
 
48
48
  <style scoped>
49
49
  img {
50
- min-width: 200px;
50
+ min-width: 150px;
51
51
  }
52
52
  video {
53
53
  min-width: 200px;
@@ -74,6 +74,9 @@ const url = computed(() => {
74
74
  // since we have no way to know the content type of the file, we will try to guess it from extension
75
75
  // for better experience probably we should check whether user saves content type in the database and use it here
76
76
  const contentType = computed(() => {
77
+ if (!url.value) {
78
+ return null;
79
+ }
77
80
  const u = new URL(url.value);
78
81
  return guessContentType(u.pathname);
79
82
  });
@@ -1,7 +1,7 @@
1
1
  <template>
2
2
  <div class="flex items-center justify-center w-full">
3
3
  <label for="dropzone-file"
4
- class="flex flex-col 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"
4
+ 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"
5
5
  @dragover.prevent="() => dragging = true"
6
6
  @dragleave.prevent="() => dragging = false"
7
7
  @drop.prevent="onFileChange"
@@ -22,7 +22,7 @@
22
22
  <template v-if="!uploaded">
23
23
  <p class="mb-2 text-sm text-gray-500 dark:text-gray-400"><span class="font-semibold">Click to upload</span> or drag and drop</p>
24
24
  <p class="text-xs text-gray-500 dark:text-gray-400">
25
- {{ allowedExtensionsLabel }} {{ meta.maxFileSize ? `(up to ${maxFileSizeHumanized})` : '' }}
25
+ {{ allowedExtensionsLabel }} {{ meta.maxFileSize ? `(up to ${humanifySize(meta.maxFileSize)})` : '' }}
26
26
  </p>
27
27
  </template>
28
28
 
@@ -60,7 +60,7 @@ import { computed, ref, onMounted, watch } from 'vue'
60
60
  import { callAdminForthApi } from '@/utils'
61
61
 
62
62
  const props = defineProps({
63
- meta: String,
63
+ meta: Object,
64
64
  record: Object,
65
65
  })
66
66
 
@@ -47,7 +47,7 @@
47
47
 
48
48
  <style scoped>
49
49
  img {
50
- min-width: 200px;
50
+ min-width: 150px;
51
51
  }
52
52
  video {
53
53
  min-width: 200px;
@@ -74,6 +74,9 @@ const url = computed(() => {
74
74
  // since we have no way to know the content type of the file, we will try to guess it from extension
75
75
  // for better experience probably we should check whether user saves content type in the database and use it here
76
76
  const contentType = computed(() => {
77
+ if (!url.value) {
78
+ return null;
79
+ }
77
80
  const u = new URL(url.value);
78
81
  return guessContentType(u.pathname);
79
82
  });
@@ -1,7 +1,7 @@
1
1
  <template>
2
2
  <div class="flex items-center justify-center w-full">
3
3
  <label for="dropzone-file"
4
- class="flex flex-col 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"
4
+ 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"
5
5
  @dragover.prevent="() => dragging = true"
6
6
  @dragleave.prevent="() => dragging = false"
7
7
  @drop.prevent="onFileChange"
@@ -22,7 +22,7 @@
22
22
  <template v-if="!uploaded">
23
23
  <p class="mb-2 text-sm text-gray-500 dark:text-gray-400"><span class="font-semibold">Click to upload</span> or drag and drop</p>
24
24
  <p class="text-xs text-gray-500 dark:text-gray-400">
25
- {{ allowedExtensionsLabel }} {{ meta.maxFileSize ? `(up to ${maxFileSizeHumanized})` : '' }}
25
+ {{ allowedExtensionsLabel }} {{ meta.maxFileSize ? `(up to ${humanifySize(meta.maxFileSize)})` : '' }}
26
26
  </p>
27
27
  </template>
28
28
 
@@ -60,7 +60,7 @@ import { computed, ref, onMounted, watch } from 'vue'
60
60
  import { callAdminForthApi } from '@/utils'
61
61
 
62
62
  const props = defineProps({
63
- meta: String,
63
+ meta: Object,
64
64
  record: Object,
65
65
  })
66
66
 
package/dist/index.js CHANGED
@@ -15,6 +15,9 @@ export default class UploadPlugin extends AdminForthPlugin {
15
15
  super(options, import.meta.url);
16
16
  this.options = options;
17
17
  }
18
+ instanceUniqueRepresentation(pluginOptions) {
19
+ return `${pluginOptions.pathColumnName}`;
20
+ }
18
21
  setupLifecycleRule() {
19
22
  return __awaiter(this, void 0, void 0, function* () {
20
23
  // check that lifecyle rule "adminforth-unused-cleaner" exists
@@ -90,7 +93,6 @@ export default class UploadPlugin extends AdminForthPlugin {
90
93
  });
91
94
  return __awaiter(this, void 0, void 0, function* () {
92
95
  var _a, _b, _c;
93
- this.setupLifecycleRule();
94
96
  _super.modifyResourceConfig.call(this, adminforth, resourceConfig);
95
97
  // after column to store the path of the uploaded file, add new VirtualColumn,
96
98
  // show only in edit and create views
@@ -202,7 +204,7 @@ export default class UploadPlugin extends AdminForthPlugin {
202
204
  }
203
205
  // ** HOOKS FOR DELETE **//
204
206
  // add delete hook which sets tag adminforth-candidate-for-cleanup to true
205
- resourceConfig.hooks.delete.beforeSave.push((_h) => __awaiter(this, [_h], void 0, function* ({ record }) {
207
+ resourceConfig.hooks.delete.afterSave.push((_h) => __awaiter(this, [_h], void 0, function* ({ record }) {
206
208
  if (record[pathColumnName]) {
207
209
  const s3 = new AWS.S3({
208
210
  accessKeyId: this.options.s3AccessKeyId,
@@ -271,6 +273,10 @@ export default class UploadPlugin extends AdminForthPlugin {
271
273
  }));
272
274
  });
273
275
  }
276
+ validateConfigAfterDiscover(adminforth, resourceConfig) {
277
+ // called here because modifyResourceConfig can be called in build time where there is no environment and AWS secrets
278
+ this.setupLifecycleRule();
279
+ }
274
280
  setupEndpoints(server) {
275
281
  server.endpoint({
276
282
  method: 'POST',
package/index.ts CHANGED
@@ -10,10 +10,13 @@ export default class UploadPlugin extends AdminForthPlugin {
10
10
 
11
11
  constructor(options: PluginOptions) {
12
12
  super(options, import.meta.url);
13
-
14
13
  this.options = options;
15
14
  }
16
15
 
16
+ instanceUniqueRepresentation(pluginOptions: any) : string {
17
+ return `${pluginOptions.pathColumnName}`;
18
+ }
19
+
17
20
  async setupLifecycleRule() {
18
21
  // check that lifecyle rule "adminforth-unused-cleaner" exists
19
22
  const CLEANUP_RULE_ID = 'adminforth-unused-cleaner';
@@ -84,7 +87,6 @@ export default class UploadPlugin extends AdminForthPlugin {
84
87
  }
85
88
 
86
89
  async modifyResourceConfig(adminforth: IAdminForth, resourceConfig: any) {
87
- this.setupLifecycleRule();
88
90
 
89
91
  super.modifyResourceConfig(adminforth, resourceConfig);
90
92
  // after column to store the path of the uploaded file, add new VirtualColumn,
@@ -225,7 +227,7 @@ export default class UploadPlugin extends AdminForthPlugin {
225
227
  // ** HOOKS FOR DELETE **//
226
228
 
227
229
  // add delete hook which sets tag adminforth-candidate-for-cleanup to true
228
- resourceConfig.hooks.delete.beforeSave.push(async ({ record }: { record: any }) => {
230
+ resourceConfig.hooks.delete.afterSave.push(async ({ record }: { record: any }) => {
229
231
  if (record[pathColumnName]) {
230
232
  const s3 = new AWS.S3({
231
233
  accessKeyId: this.options.s3AccessKeyId,
@@ -304,7 +306,10 @@ export default class UploadPlugin extends AdminForthPlugin {
304
306
 
305
307
  }
306
308
 
307
-
309
+ validateConfigAfterDiscover(adminforth: IAdminForth, resourceConfig: any) {
310
+ // called here because modifyResourceConfig can be called in build time where there is no environment and AWS secrets
311
+ this.setupLifecycleRule();
312
+ }
308
313
 
309
314
  setupEndpoints(server: IHttpServer) {
310
315
  server.endpoint({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/upload",
3
- "version": "1.0.9",
3
+ "version": "1.0.11",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",