@appweaver/cli 1.0.15 → 1.0.16
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/package.json
CHANGED
|
@@ -445,14 +445,15 @@ const config = {
|
|
|
445
445
|
};
|
|
446
446
|
```
|
|
447
447
|
|
|
448
|
-
| Property
|
|
449
|
-
|
|
450
|
-
| `mimeType`
|
|
451
|
-
| `namePattern`
|
|
452
|
-
| `array`
|
|
453
|
-
| `maxSize`
|
|
454
|
-
| `maxCount`
|
|
455
|
-
| `output`
|
|
448
|
+
| Property | Type | Description |
|
|
449
|
+
|---------------------|------------------------|-------------------------------------------------------------------------------------------------------------|
|
|
450
|
+
| `mimeType` | string \| RegExp | Allowed MIME types (glob patterns like `'image/*'` supported). |
|
|
451
|
+
| `namePattern` | string \| function | File naming pattern or function (available variables are listed below). |
|
|
452
|
+
| `array` | boolean | Allow multiple files. |
|
|
453
|
+
| `maxSize` | number \| string | Maximum file size (e.g. `'2 MB'`, `5242880`). |
|
|
454
|
+
| `maxCount` | number | Maximum number of files (for array fields). |
|
|
455
|
+
| `output` | RelationOutput | When to include file info in output. |
|
|
456
|
+
| `onResourceDeleted` | `'delete'` \| `'keep'` | When the owning resource is deleted. `'delete'` (default) removes files from storage, `'keep'` leaves them. |
|
|
456
457
|
|
|
457
458
|
#### Available namePattern variables
|
|
458
459
|
|
|
@@ -249,3 +249,32 @@ await fileService.deleteFile(
|
|
|
249
249
|
postClient // ResourceClient
|
|
250
250
|
);
|
|
251
251
|
```
|
|
252
|
+
|
|
253
|
+
### Deleting all files on resource deletion
|
|
254
|
+
|
|
255
|
+
When a resource is deleted, files belonging to file fields configured with `onResourceDeleted: 'delete'` can be
|
|
256
|
+
automatically cleaned up. This is handled by `deleteResourceFiles()`, which is called automatically by the framework's
|
|
257
|
+
delete route handler.
|
|
258
|
+
|
|
259
|
+
To enable automatic file cleanup, set `onResourceDeleted: 'delete'` on the file field in your model config:
|
|
260
|
+
|
|
261
|
+
```ts
|
|
262
|
+
const config = {
|
|
263
|
+
files: {
|
|
264
|
+
coverImage: {
|
|
265
|
+
mimeType: 'image/*',
|
|
266
|
+
onResourceDeleted: 'delete' // default: files removed when resource is deleted
|
|
267
|
+
},
|
|
268
|
+
documents: {
|
|
269
|
+
array: true,
|
|
270
|
+
onResourceDeleted: 'keep' // opt out: files are kept
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
You can also call `deleteResourceFiles` manually if needed:
|
|
277
|
+
|
|
278
|
+
```ts
|
|
279
|
+
await fileService.deleteResourceFiles('Post', postId);
|
|
280
|
+
```
|