Skip to content

Commit 7e2bad3

Browse files
authored
Merge pull request #481 from devforth/next
Next
2 parents 84b0c22 + 9a58bba commit 7e2bad3

File tree

17 files changed

+571
-87
lines changed

17 files changed

+571
-87
lines changed

adminforth/dataConnectors/postgres.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ class PostgresConnector extends AdminForthBaseConnector implements IAdminForthDa
232232
}
233233
return JSON.stringify(value);
234234
} else if (field.type == AdminForthDataTypes.BOOLEAN) {
235-
return value === null ? null : (value ? 1 : 0);
235+
return value === null ? null : (value ? true : false);
236236
} else if (field.type == AdminForthDataTypes.JSON) {
237237
if (field._underlineType == 'json') {
238238
return typeof value === 'string' || value === null ? value : JSON.stringify(value);

adminforth/documentation/docs/tutorial/03-Customization/02-customFieldRendering.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,9 @@ Sometimes a custom editor needs to update not only its own field, but also other
239239
240240
For this, custom `edit`/`create` components can emit an `update:recordFieldValue` event with the payload `{ fieldName, fieldValue }`. AdminForth will update the corresponding field in the record.
241241
242+
> If you emit `update:recordFieldValue` to modify a field which is hidden by `showIn.create: false` / `showIn.edit: false`, the backend will reject the request by default.
243+
> To allow this, set the target column config to `allowModifyWhenNotShowInCreate: true` and/or `allowModifyWhenNotShowInEdit: true`.
244+
242245
```html title='./custom/TitleWithSlugEditor.vue'
243246
<template>
244247
<div class="flex flex-col gap-2">

adminforth/documentation/docs/tutorial/03-Customization/04-hooks.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ When user opens edit page, AdminForth makes a request to the backend to get the
4444

4545
Practically you can use `show.afterDatasourceResponse` to modify or add some data before it is displayed on the edit page.
4646

47-
For example [upload plugin](/docs/tutorial/Plugins/upload/) uses this hook to generate signed preview URL so user can see existing uploaded file preview in form, and at the same time database stores only original file path which might be not accessible without presigned URL.
47+
For example [upload plugin](/docs/tutorial/Plugins/05-0-upload/) uses this hook to generate signed preview URL so user can see existing uploaded file preview in form, and at the same time database stores only original file path which might be not accessible without presigned URL.
4848

4949
## Saving data on edit page
5050

adminforth/documentation/docs/tutorial/03-Customization/12-security.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Also you can add custom rules. For example to prevent popular words:
6666
],
6767
```
6868
69-
All rules defined in password column will be also delivered to [password reset plugin](../07-Plugins/07-email-password-reset.md) if you are using it to ensure that password reset will also respect same rules.
69+
All rules defined in password column will be also delivered to [password reset plugin](../08-Plugins/07-email-password-reset.md) if you are using it to ensure that password reset will also respect same rules.
7070
7171
7272
## Trusting client IP addresses

adminforth/documentation/docs/tutorial/03-Customization/15-afcl.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2215,7 +2215,7 @@ const datePickerValue = ref()
22152215
<div>
22162216
```html
22172217
<DatePicker
2218-
v-model:datePickerValue="datePickerValue"
2218+
v-model:valueStart="datePickerValue"
22192219
:column="{ type: 'datetime' }"
22202220
label="Pick start"
22212221
/>

adminforth/documentation/docs/tutorial/08-Plugins/05-upload.md renamed to adminforth/documentation/docs/tutorial/08-Plugins/05-0-upload.md

Lines changed: 6 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -305,73 +305,6 @@ new UploadPlugin({
305305
> adminServeBaseUrl defines the public path prefix. If your AdminForth base URL is /admin, files will be accessible under /admin/static/source/&lt;key&gt;.
306306
307307
308-
## API
309-
310-
### uploadFromBufferToNewRecord
311-
312-
In some cases you may want to upload a file directly from your backend (for example, a file generated by a background job or received from a webhook) without going through the browser. For this, the Upload plugin exposes the `uploadFromBufferToNewRecord` method.
313-
314-
You can code it as custom logic or you can simply reuse Upload plugin for this purpose as well.
315-
316-
This method uploads a file from a Node.js `Buffer`, automatically creates a record in the corresponding resource, and returns both the stored file path and a preview URL.
317-
318-
```ts title="./some-backend-service.ts"
319-
import { admin } from './admin'; // your AdminForth instance
320-
321-
...
322-
plugins: [
323-
new UploadPlugin({
324-
id: 'my_reports_plugin', // unique identifier for your plugin instance
325-
....
326-
})
327-
]
328-
...
329-
330-
const plugin = admin.getPluginById('my_reports_plugin');
331-
332-
const { path, previewUrl } = await plugin.uploadFromBufferToNewRecord({
333-
filename: 'report.pdf',
334-
contentType: 'application/pdf',
335-
buffer, // Node.js Buffer with file content
336-
adminUser, // current admin user or system user
337-
recordAttributes: {
338-
title: 'Generated report',
339-
listed: false,
340-
},
341-
});
342-
```
343-
344-
- `uploadFromBufferToNewRecord` uses the configured storage adapter (S3, local, etc.) to store the file.
345-
- It automatically creates a new record in the resource and stores the file path into the column defined by `pathColumnName`, together with any extra `recordAttributes` you pass.
346-
- It returns an object `{ path, previewUrl }`, where `previewUrl` is the same URL that would be used for previews inside AdminForth.
347-
348-
> ⚠️ It is not recommended to upload large files from the backend using `uploadFromBuffer`, because the entire file must go through your server memory and network. For large uploads you should prefer frontend presigned uploads directly to storage. You can find an example of presigned upload flow using upload plugin in the Rich editor plugin source code (Rich editor actually uses Upload plugin to upload images in edited content).
349-
350-
351-
### uploadFromBufferToExistingRecord
352-
353-
If you already have a record and just want to replace the file referenced in its `pathColumnName` field, you can use the `uploadFromBufferToExistingRecord` method. It uploads a file from a Node.js `Buffer`, updates the existing record, and returns the new file path and preview URL.
354-
355-
```ts title="./some-backend-service.ts"
356-
const plugin = admin.getPluginById('my_reports_plugin');
357-
358-
const { path, previewUrl } = await plugin.uploadFromBufferToExistingRecord({
359-
recordId: existingRecordId, // primary key of the record to update
360-
filename: 'report.pdf',
361-
contentType: 'application/pdf',
362-
buffer, // Node.js Buffer with file content
363-
adminUser, // current admin user or system user
364-
extra: {}, // optional extra meta for your hooks / audit
365-
});
366-
```
367-
368-
- Uses the same storage adapter and validation rules as `uploadFromBufferToNewRecord` (file extension whitelist, `maxFileSize`, `filePath` callback, etc.).
369-
- Does not create a new record – it only updates the existing one identified by `recordId`, replacing the value in `pathColumnName` with the new storage path.
370-
- If the generated `filePath` would be the same as the current value in the record, it throws an error to help you avoid CDN/browser caching issues. To force a refresh, make sure your `filePath` callback produces a different key (for example, include a timestamp or random UUID).
371-
372-
> ⚠️ The same recommendation about large files applies here: avoid using `uploadFromBufferToExistingRecord` for very large uploads; prefer a presigned upload flow from the frontend instead.
373-
374-
375308
376309
## Image generation
377310
@@ -726,4 +659,9 @@ And finally add this callback:
726659

727660
```
728661
729-
And now you can easily update avatar for each user
662+
And now you can easily update avatar for each user
663+
664+
# API
665+
666+
If you wish to reuse Upload plugin for advanced tasks like upload custom files from frontend/backend
667+
(including presigned frontend upload), see [05-1-upload-api.md](05-1-upload-api.md).

0 commit comments

Comments
 (0)