@appweaver/cli 1.0.15 → 1.0.17
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 +1 -1
- package/skill/SKILL.md +4 -2
- package/skill/references/resources.md +60 -9
- package/skill/references/storage.md +29 -0
package/package.json
CHANGED
package/skill/SKILL.md
CHANGED
|
@@ -212,7 +212,8 @@ export default createModel({
|
|
|
212
212
|
files: {
|
|
213
213
|
photo: {
|
|
214
214
|
mimeType: 'image/*',
|
|
215
|
-
maxSize: '2 MB'
|
|
215
|
+
maxSize: '2 MB',
|
|
216
|
+
image: { quality: 80, maxWidth: 1200 }
|
|
216
217
|
}
|
|
217
218
|
},
|
|
218
219
|
create: {
|
|
@@ -333,7 +334,8 @@ export default createAuthModel({
|
|
|
333
334
|
files: {
|
|
334
335
|
avatar: {
|
|
335
336
|
mimeType: 'image/(png|jpeg|gif)',
|
|
336
|
-
maxSize: '2 MB'
|
|
337
|
+
maxSize: '2 MB',
|
|
338
|
+
image: { quality: 80, maxHeight: 800, fit: 'inside' }
|
|
337
339
|
}
|
|
338
340
|
}
|
|
339
341
|
});
|
|
@@ -434,7 +434,13 @@ const config = {
|
|
|
434
434
|
photo: {
|
|
435
435
|
mimeType: 'image/*',
|
|
436
436
|
namePattern: 'photos/{userId}-{name}-{hash}.{extension}',
|
|
437
|
-
maxSize: '2 MB'
|
|
437
|
+
maxSize: '2 MB',
|
|
438
|
+
image: {
|
|
439
|
+
quality: 80,
|
|
440
|
+
maxWidth: 1200,
|
|
441
|
+
maxHeight: 1200,
|
|
442
|
+
fit: 'inside'
|
|
443
|
+
}
|
|
438
444
|
},
|
|
439
445
|
documents: {
|
|
440
446
|
mimeType: 'application/pdf',
|
|
@@ -445,14 +451,16 @@ const config = {
|
|
|
445
451
|
};
|
|
446
452
|
```
|
|
447
453
|
|
|
448
|
-
| Property
|
|
449
|
-
|
|
450
|
-
| `mimeType`
|
|
451
|
-
| `namePattern`
|
|
452
|
-
| `array`
|
|
453
|
-
| `maxSize`
|
|
454
|
-
| `maxCount`
|
|
455
|
-
| `output`
|
|
454
|
+
| Property | Type | Description |
|
|
455
|
+
|---------------------|------------------------|-------------------------------------------------------------------------------------------------------------|
|
|
456
|
+
| `mimeType` | string \| RegExp | Allowed MIME types (glob patterns like `'image/*'` supported). |
|
|
457
|
+
| `namePattern` | string \| function | File naming pattern or function (available variables are listed below). |
|
|
458
|
+
| `array` | boolean | Allow multiple files. |
|
|
459
|
+
| `maxSize` | number \| string | Maximum file size (e.g. `'2 MB'`, `5242880`). |
|
|
460
|
+
| `maxCount` | number | Maximum number of files (for array fields). |
|
|
461
|
+
| `output` | RelationOutput | When to include file info in output. |
|
|
462
|
+
| `onResourceDeleted` | `'delete'` \| `'keep'` | When the owning resource is deleted. `'delete'` (default) removes files from storage, `'keep'` leaves them. |
|
|
463
|
+
| `image` | ImageConfig | Image compression and resize settings. Only applies to image MIME types (excluding GIF). |
|
|
456
464
|
|
|
457
465
|
#### Available namePattern variables
|
|
458
466
|
|
|
@@ -482,6 +490,49 @@ Default pattern is: `{name}-{hash}.{extension}`.
|
|
|
482
490
|
| `uuid` | string | Generated random UUID. |
|
|
483
491
|
| `hash` | string | Generated random hash (32 bytes). |
|
|
484
492
|
|
|
493
|
+
#### Image compression
|
|
494
|
+
|
|
495
|
+
Configure automatic image compression and resizing by adding the `image` property to a file field. Processing only
|
|
496
|
+
applies to supported image MIME types: `image/jpeg`, `image/png`, `image/webp`, `image/avif`, `image/tiff`. GIF files
|
|
497
|
+
are passed through unchanged.
|
|
498
|
+
|
|
499
|
+
| Property | Type | Description |
|
|
500
|
+
|-------------|----------|----------------------------------------------------------------------------------------------------------------|
|
|
501
|
+
| `quality` | number | Compression quality (1-100). Applies to JPEG, PNG, WebP, AVIF, and TIFF. |
|
|
502
|
+
| `width` | number | Exact resize width in pixels. |
|
|
503
|
+
| `height` | number | Exact resize height in pixels. |
|
|
504
|
+
| `maxWidth` | number | Maximum width. Only downscales if the image exceeds this dimension. |
|
|
505
|
+
| `maxHeight` | number | Maximum height. Only downscales if the image exceeds this dimension. |
|
|
506
|
+
| `fit` | ImageFit | How the image fits the target dimensions: `'inside'` (default), `'contain'`, `'cover'`, `'fill'`, `'outside'`. |
|
|
507
|
+
|
|
508
|
+
`width`/`height` take precedence over `maxWidth`/`maxHeight`. When using `maxWidth`/`maxHeight`, images smaller than
|
|
509
|
+
the specified dimensions are not enlarged.
|
|
510
|
+
|
|
511
|
+
```ts
|
|
512
|
+
// Compress and limit dimensions
|
|
513
|
+
const config = {
|
|
514
|
+
files: {
|
|
515
|
+
avatar: {
|
|
516
|
+
mimeType: 'image/*',
|
|
517
|
+
maxSize: '5 MB',
|
|
518
|
+
image: { quality: 80, maxWidth: 800, maxHeight: 800 }
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
};
|
|
522
|
+
```
|
|
523
|
+
|
|
524
|
+
```ts
|
|
525
|
+
// Exact resize for thumbnails
|
|
526
|
+
const config = {
|
|
527
|
+
files: {
|
|
528
|
+
thumbnail: {
|
|
529
|
+
mimeType: 'image/jpeg',
|
|
530
|
+
image: { quality: 70, width: 200, height: 200, fit: 'inside' }
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
```
|
|
535
|
+
|
|
485
536
|
### Virtual fields
|
|
486
537
|
|
|
487
538
|
Virtual fields are computed values not stored in the database. They can appear in input DTOs (to receive data) and/or
|
|
@@ -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
|
+
```
|