@adminforth/upload 2.8.1 → 2.8.2

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 CHANGED
@@ -11,5 +11,5 @@ custom/preview.vue
11
11
  custom/tsconfig.json
12
12
  custom/uploader.vue
13
13
 
14
- sent 51,375 bytes received 134 bytes 103,018.00 bytes/sec
15
- total size is 50,893 speedup is 0.99
14
+ sent 51,915 bytes received 134 bytes 104,098.00 bytes/sec
15
+ total size is 51,426 speedup is 0.99
@@ -169,10 +169,24 @@ onMounted(async () => {
169
169
 
170
170
  const existingValue = (props as any).value;
171
171
  const existingFilePath =
172
- typeof existingValue === 'string' && existingValue.trim() ? existingValue : null;
173
-
172
+ typeof existingValue === 'string' && existingValue.trim() ? existingValue : null;
174
173
  if (!uploaded.value && props.record?.[previewColumnName]) {
175
- imgPreview.value = props.record[previewColumnName];
174
+ if (Array.isArray(props.record[previewColumnName]) && props.record[previewColumnName].length > 0) {
175
+ const resp = await callAdminForthApi({
176
+ path: `/plugin/${props.meta.pluginInstanceId}/get-file-preview-url`,
177
+ method: 'POST',
178
+ body: { filePath: existingFilePath },
179
+ });
180
+ if (!resp?.error && resp?.url) {
181
+ imgPreview.value = resp.url;
182
+ uploaded.value = true;
183
+ emit('update:emptiness', false);
184
+ return;
185
+ }
186
+ imgPreview.value = resp.url;
187
+ } else {
188
+ imgPreview.value = props.record[previewColumnName];
189
+ }
176
190
  uploaded.value = true;
177
191
  emit('update:emptiness', false);
178
192
  } else if (!uploaded.value && existingFilePath) {
@@ -169,10 +169,24 @@ onMounted(async () => {
169
169
 
170
170
  const existingValue = (props as any).value;
171
171
  const existingFilePath =
172
- typeof existingValue === 'string' && existingValue.trim() ? existingValue : null;
173
-
172
+ typeof existingValue === 'string' && existingValue.trim() ? existingValue : null;
174
173
  if (!uploaded.value && props.record?.[previewColumnName]) {
175
- imgPreview.value = props.record[previewColumnName];
174
+ if (Array.isArray(props.record[previewColumnName]) && props.record[previewColumnName].length > 0) {
175
+ const resp = await callAdminForthApi({
176
+ path: `/plugin/${props.meta.pluginInstanceId}/get-file-preview-url`,
177
+ method: 'POST',
178
+ body: { filePath: existingFilePath },
179
+ });
180
+ if (!resp?.error && resp?.url) {
181
+ imgPreview.value = resp.url;
182
+ uploaded.value = true;
183
+ emit('update:emptiness', false);
184
+ return;
185
+ }
186
+ imgPreview.value = resp.url;
187
+ } else {
188
+ imgPreview.value = props.record[previewColumnName];
189
+ }
176
190
  uploaded.value = true;
177
191
  emit('update:emptiness', false);
178
192
  } else if (!uploaded.value && existingFilePath) {
package/dist/index.js CHANGED
@@ -454,5 +454,21 @@ export default class UploadPlugin extends AdminForthPlugin {
454
454
  return { error: 'You do not have permission to download this file' };
455
455
  }),
456
456
  });
457
+ server.endpoint({
458
+ method: 'POST',
459
+ path: `/plugin/${this.pluginInstanceId}/get-file-preview-url`,
460
+ handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser }) {
461
+ var _b;
462
+ const { filePath } = body;
463
+ if (!filePath) {
464
+ return { error: 'Missing filePath' };
465
+ }
466
+ if ((_b = this.options.preview) === null || _b === void 0 ? void 0 : _b.previewUrl) {
467
+ const url = this.options.preview.previewUrl({ filePath });
468
+ return { url };
469
+ }
470
+ return { error: 'failed to generate preview URL' };
471
+ }),
472
+ });
457
473
  }
458
474
  }
package/index.ts CHANGED
@@ -40,7 +40,6 @@ export default class UploadPlugin extends AdminForthPlugin {
40
40
  }
41
41
 
42
42
  this.getFileUploadUrl = async ( originalFilename, contentType, size, originalExtension, recordPk ) : Promise<{ uploadUrl: string, tagline?: string, filePath?: string, uploadExtraParams?: Record<string, string>, previewUrl?: string, error?: string } | {error: string}> => {
43
-
44
43
  if (this.options.allowedFileExtensions && !this.options.allowedFileExtensions.includes(originalExtension.toLowerCase())) {
45
44
  return {
46
45
  error: `File extension "${originalExtension}" is not allowed, allowed extensions are: ${this.options.allowedFileExtensions.join(', ')}`
@@ -526,6 +525,23 @@ export default class UploadPlugin extends AdminForthPlugin {
526
525
  },
527
526
  });
528
527
 
528
+ server.endpoint({
529
+ method: 'POST',
530
+ path: `/plugin/${this.pluginInstanceId}/get-file-preview-url`,
531
+ handler: async ({ body, adminUser }) => {
532
+ const { filePath } = body;
533
+ if (!filePath) {
534
+ return { error: 'Missing filePath' };
535
+ }
536
+ if (this.options.preview?.previewUrl) {
537
+ const url = this.options.preview.previewUrl({ filePath });
538
+ return { url };
539
+ }
540
+ return { error: 'failed to generate preview URL' };
541
+ },
542
+ });
543
+
544
+
529
545
  }
530
546
 
531
547
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/upload",
3
- "version": "2.8.1",
3
+ "version": "2.8.2",
4
4
  "description": "Plugin for uploading files for adminforth",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",