|
1 | 1 | import AdminForth, { AdminForthDataTypes } from 'adminforth'; |
2 | 2 | import type { AdminForthResourceInput, AdminUser } from 'adminforth'; |
3 | 3 | import { randomUUID } from 'crypto'; |
| 4 | +import UploadPlugin from '../../../plugins/adminforth-upload/index.js'; |
| 5 | +import AdminForthStorageAdapterLocalFilesystem from '../../../adapters/adminforth-storage-adapter-local/index.js'; |
| 6 | +import AdminForthAdapterS3Storage from '../../../adapters/adminforth-storage-adapter-amazon-s3/index.js'; |
4 | 7 |
|
5 | 8 | export default { |
6 | 9 | dataSource: 'sqlite', |
7 | 10 | table: 'turns', |
8 | 11 | resourceId: 'turns', |
9 | 12 | label: 'Turns', |
| 13 | + // written by the agent only; edits here would bypass its checks and its file bookkeeping |
| 14 | + options: { |
| 15 | + allowedActions: { |
| 16 | + create: false, |
| 17 | + edit: false, |
| 18 | + delete: false, |
| 19 | + }, |
| 20 | + }, |
10 | 21 | columns: [ |
11 | 22 | { |
12 | 23 | name: 'id', |
@@ -70,5 +81,39 @@ export default { |
70 | 81 | filter: false, |
71 | 82 | }, |
72 | 83 | }, |
| 84 | + { |
| 85 | + name: 'attachments', |
| 86 | + type: AdminForthDataTypes.JSON, |
| 87 | + isArray: { |
| 88 | + enabled: true, |
| 89 | + itemType: AdminForthDataTypes.STRING, |
| 90 | + }, |
| 91 | + showIn: { |
| 92 | + list: false, |
| 93 | + show: true, |
| 94 | + edit: false, |
| 95 | + create: false, |
| 96 | + filter: false, |
| 97 | + }, |
| 98 | + }, |
| 99 | + ], |
| 100 | + plugins: [ |
| 101 | + new UploadPlugin({ |
| 102 | + pathColumnName: 'attachments', |
| 103 | + storageAdapter: process.env.USE_S3 !== 'true' ? new AdminForthStorageAdapterLocalFilesystem({ |
| 104 | + fileSystemFolder: './db/uploads_agent_attachments', |
| 105 | + mode: 'private', |
| 106 | + signingSecret: '1241245', |
| 107 | + }) : new AdminForthAdapterS3Storage({ |
| 108 | + bucket: process.env.AWS_BUCKET_NAME as string, |
| 109 | + region: process.env.AWS_REGION as string, |
| 110 | + accessKeyId: process.env.AWS_ACCESS_KEY_ID as string, |
| 111 | + secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY as string, |
| 112 | + strictContentType: true, |
| 113 | + }), |
| 114 | + allowedFileExtensions: ['png', 'jpg', 'jpeg', 'webp'], |
| 115 | + maxFileSize: 1024 * 1024 * 5, |
| 116 | + filePath: ({ originalExtension }) => `agent_attachments/${randomUUID()}.${originalExtension}`, |
| 117 | + }), |
73 | 118 | ], |
74 | 119 | } as AdminForthResourceInput; |
0 commit comments