Skip to content

Commit c944eef

Browse files
committed
upload plugin: Add 'record' param for s3Path callback in edit mode
1 parent 35d7297 commit c944eef

File tree

5 files changed

+15
-10
lines changed

5 files changed

+15
-10
lines changed

adminforth/documentation/docs/tutorial/05-Plugins/05-upload.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,13 @@ which are generated by plugin:
155155
![alt text](Upload.png)
156156
157157
158-
> ☝ When upload feature is used on record which already exists in database (from 'edit' view), s3path callback will
158+
> ☝ When upload feature is used on record which already exists in database (from 'edit' page), s3path callback will
159159
> receive additional parameter `record` with all values of record. Generally we don't recommend denormalizing any state
160-
> of record into s3Path (and instead only store links from record to file path like in example above).
160+
> of record into s3 path (and instead store links to unique path on s3 in the record field, like in example above).
161161
> But if you are 100% sure this kind of sate will be static, you might link to it:
162162
>
163163
> ```ts
164-
> s3Path: ({originalExtension, record}) => `game_images/${record.game_code}.${originalExtension}`
164+
> s3Path: ({originalExtension, record}) => `game_images/${record.static_game_code}.${originalExtension}`
165165
> ```
166166
>
167167
> ! Please note that when upload is done from create view, record will be `undefined`.

adminforth/plugins/upload/ChangeLog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11

2+
## [1.0.30] - 2024-12-26
3+
4+
### Improved
5+
6+
- Add 'record' param for s3Path callback in edit mode
27

38
## [1.0.24] - 2023-12-24
49

adminforth/plugins/upload/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { PluginOptions } from './types.js';
33
import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
44
import { ExpirationStatus, GetObjectCommand, ObjectCannedACL, PutObjectCommand, S3 } from '@aws-sdk/client-s3';
5-
import { AdminForthPlugin, AdminForthResourceColumn, AdminForthResourcePages, Filters, IAdminForth, IHttpServer, suggestIfTypo } from "adminforth";
5+
import { AdminForthPlugin, AdminForthResourceColumn, AdminForthResource, Filters, IAdminForth, IHttpServer, suggestIfTypo } from "adminforth";
66
import { Readable } from "stream";
77
import { RateLimiter } from "adminforth";
88

@@ -94,15 +94,15 @@ export default class UploadPlugin extends AdminForthPlugin {
9494
record[`previewUrl_${this.pluginInstanceId}`] = previewUrl;
9595
}
9696

97-
async modifyResourceConfig(adminforth: IAdminForth, resourceConfig: any) {
97+
async modifyResourceConfig(adminforth: IAdminForth, resourceConfig: AdminForthResource) {
9898
super.modifyResourceConfig(adminforth, resourceConfig);
9999
// after column to store the path of the uploaded file, add new VirtualColumn,
100100
// show only in edit and create views
101101
// use component uploader.vue
102102
const { pathColumnName } = this.options;
103103
const pathColumnIndex = resourceConfig.columns.findIndex((column: any) => column.name === pathColumnName);
104104
if (pathColumnIndex === -1) {
105-
throw new Error(`Column with name "${pathColumnName}" not found in resource "${resourceConfig.name}"`);
105+
throw new Error(`Column with name "${pathColumnName}" not found in resource "${resourceConfig.label}"`);
106106
}
107107

108108
if (this.options.generation?.fieldsForContext) {
@@ -315,7 +315,7 @@ export default class UploadPlugin extends AdminForthPlugin {
315315

316316

317317
// add edit postSave hook to delete old file and remove tag from new file
318-
resourceConfig.hooks.edit.afterSave.push(async ({ updates, oldRecord }: { record: any, oldRecord: any }) => {
318+
resourceConfig.hooks.edit.afterSave.push(async ({ updates, oldRecord }: { updates: any, oldRecord: any }) => {
319319

320320
if (updates[virtualColumn.name] || updates[virtualColumn.name] === null) {
321321
const s3 = new S3({

adminforth/plugins/upload/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

adminforth/plugins/upload/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@adminforth/upload",
3-
"version": "1.0.29",
3+
"version": "1.0.30",
44
"description": "",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

0 commit comments

Comments
 (0)