diff --git a/README.md b/README.md index 6367e67..14795c1 100644 --- a/README.md +++ b/README.md @@ -4,4 +4,4 @@ Allows to upload files to Amazon S3 bucket from adminforth application. -## For usage, see [AdminForth Upload Documentation](https://adminforth.dev/docs/tutorial/Plugins/upload/) \ No newline at end of file +## For usage, see [AdminForth Upload Documentation](https://adminforth.dev/docs/tutorial/Plugins/upload/) diff --git a/custom/preview.vue b/custom/preview.vue index 75541a0..4080b14 100644 --- a/custom/preview.vue +++ b/custom/preview.vue @@ -58,7 +58,7 @@ } */ \ No newline at end of file diff --git a/custom/uploader.vue b/custom/uploader.vue index e95a6e3..36a0533 100644 --- a/custom/uploader.vue +++ b/custom/uploader.vue @@ -273,7 +273,7 @@ const onFileChange = async (e) => { }); if (!success) { adminforth.alert({ - messageHtml: `
${t('Sorry but the file was not uploaded because of S3 Request Error:')}
+ messageHtml: `
${t('Sorry but the file was not uploaded because of internal storage Request Error:')}
${
           xhr.responseText.replace(//g, '>')
         }
`, diff --git a/index.ts b/index.ts index b284627..3fb70f0 100644 --- a/index.ts +++ b/index.ts @@ -14,6 +14,8 @@ export default class UploadPlugin extends AdminForthPlugin { totalCalls: number; totalDuration: number; + resourceConfig: AdminForthResource; + constructor(options: PluginOptions) { super(options, import.meta.url); this.options = options; @@ -28,7 +30,8 @@ export default class UploadPlugin extends AdminForthPlugin { } async setupLifecycleRule() { - this.options.storageAdapter.setupLifecycle(); + const adapterUserUniqueRepresentation = `${this.resourceConfig.resourceId}-${this.pluginInstanceId}`; + this.options.storageAdapter.setupLifecycle(adapterUserUniqueRepresentation); } async genPreviewUrl(record: any) { @@ -43,6 +46,7 @@ export default class UploadPlugin extends AdminForthPlugin { async modifyResourceConfig(adminforth: IAdminForth, resourceConfig: AdminForthResource) { super.modifyResourceConfig(adminforth, resourceConfig); + this.resourceConfig = resourceConfig; // after column to store the path of the uploaded file, add new VirtualColumn, // show only in edit and create views // use component uploader.vue @@ -361,7 +365,7 @@ export default class UploadPlugin extends AdminForthPlugin { return { error: `Record with id ${recordId} not found` }; } - attachmentFiles = this.options.generation.attachFiles({ record, adminUser }); + attachmentFiles = await this.options.generation.attachFiles({ record, adminUser }); // if files is not array, make it array if (!Array.isArray(attachmentFiles)) { attachmentFiles = [attachmentFiles]; diff --git a/types.ts b/types.ts index 08ad927..b3efd5c 100644 --- a/types.ts +++ b/types.ts @@ -131,7 +131,7 @@ export type PluginOptions = { attachFiles?: ({ record, adminUser }: { record: any, adminUser: AdminUser, - }) => string[], + }) => string[] | Promise, /**