@adminforth/upload 2.8.1 → 2.8.3
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 +17 -3
- package/dist/custom/uploader.vue +17 -3
- package/dist/index.js +16 -0
- package/index.ts +20 -4
- 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 51,
|
|
15
|
-
total size is
|
|
14
|
+
sent 51,915 bytes received 134 bytes 104,098.00 bytes/sec
|
|
15
|
+
total size is 51,426 speedup is 0.99
|
package/custom/uploader.vue
CHANGED
|
@@ -169,10 +169,24 @@ onMounted(async () => {
|
|
|
169
169
|
|
|
170
170
|
const existingValue = (props as any).value;
|
|
171
171
|
const existingFilePath =
|
|
172
|
-
|
|
173
|
-
|
|
172
|
+
typeof existingValue === 'string' && existingValue.trim() ? existingValue : null;
|
|
174
173
|
if (!uploaded.value && props.record?.[previewColumnName]) {
|
|
175
|
-
|
|
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/custom/uploader.vue
CHANGED
|
@@ -169,10 +169,24 @@ onMounted(async () => {
|
|
|
169
169
|
|
|
170
170
|
const existingValue = (props as any).value;
|
|
171
171
|
const existingFilePath =
|
|
172
|
-
|
|
173
|
-
|
|
172
|
+
typeof existingValue === 'string' && existingValue.trim() ? existingValue : null;
|
|
174
173
|
if (!uploaded.value && props.record?.[previewColumnName]) {
|
|
175
|
-
|
|
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(', ')}`
|
|
@@ -98,11 +97,11 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
98
97
|
await fn.call(adapter, filePath);
|
|
99
98
|
}
|
|
100
99
|
|
|
101
|
-
|
|
100
|
+
public markKeyForNotDeletion(filePath: string) {
|
|
102
101
|
return this.callStorageAdapter('markKeyForNotDeletion', 'markKeyForNotDeletation', filePath);
|
|
103
102
|
}
|
|
104
|
-
|
|
105
|
-
|
|
103
|
+
|
|
104
|
+
public markKeyForDeletion(filePath: string) {
|
|
106
105
|
return this.callStorageAdapter('markKeyForDeletion', 'markKeyForDeletation', filePath);
|
|
107
106
|
}
|
|
108
107
|
|
|
@@ -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
|
|