@adminforth/upload 1.0.9 → 1.0.10

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
@@ -202,7 +205,7 @@ export default class UploadPlugin extends AdminForthPlugin {
202
205
  }
203
206
  // ** HOOKS FOR DELETE **//
204
207
  // 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 }) {
208
+ resourceConfig.hooks.delete.afterSave.push((_h) => __awaiter(this, [_h], void 0, function* ({ record }) {
206
209
  if (record[pathColumnName]) {
207
210
  const s3 = new AWS.S3({
208
211
  accessKeyId: this.options.s3AccessKeyId,
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';
@@ -225,7 +228,7 @@ export default class UploadPlugin extends AdminForthPlugin {
225
228
  // ** HOOKS FOR DELETE **//
226
229
 
227
230
  // add delete hook which sets tag adminforth-candidate-for-cleanup to true
228
- resourceConfig.hooks.delete.beforeSave.push(async ({ record }: { record: any }) => {
231
+ resourceConfig.hooks.delete.afterSave.push(async ({ record }: { record: any }) => {
229
232
  if (record[pathColumnName]) {
230
233
  const s3 = new AWS.S3({
231
234
  accessKeyId: this.options.s3AccessKeyId,
@@ -304,7 +307,6 @@ export default class UploadPlugin extends AdminForthPlugin {
304
307
 
305
308
  }
306
309
 
307
-
308
310
 
309
311
  setupEndpoints(server: IHttpServer) {
310
312
  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.10",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",