@nestjs-dash/media 0.1.1 → 1.0.1
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/README.md +66 -0
- package/package.json +3 -3
package/README.md
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# @nestjs-dash/media
|
|
2
|
+
|
|
3
|
+
A polymorphic media library plugin for nestjs-dash — Spatie-`laravel-medialibrary`-style media collections (attach many files to any model, grouped into named collections like `avatar` or `gallery`) built on top of [`@nestjs-dash/storage`](https://github.com/nestjs-dash/nestjs-dash)'s disks.
|
|
4
|
+
|
|
5
|
+
## When you need this
|
|
6
|
+
|
|
7
|
+
Only if you turn on `media.enabled` — most apps can use `@nestjs-dash/storage`'s upload fields directly without this plugin. Reach for `@nestjs-dash/media` when a record needs *multiple* attached files organized into named collections, rather than a single upload field per column.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pnpm add @nestjs-dash/media
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Requires `@nestjs-dash/storage` to be configured (this package stores files through it) and `typeorm` (media records persist to a TypeORM table).
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { AdminModule } from '@nestjs-dash/nestjs';
|
|
21
|
+
|
|
22
|
+
AdminModule.forRootAsync({
|
|
23
|
+
useFactory: () => ({
|
|
24
|
+
panel: {
|
|
25
|
+
// ...
|
|
26
|
+
media: { enabled: true },
|
|
27
|
+
},
|
|
28
|
+
}),
|
|
29
|
+
});
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import { MediaService } from '@nestjs-dash/media';
|
|
34
|
+
import { StorageService } from '@nestjs-dash/storage';
|
|
35
|
+
|
|
36
|
+
@Injectable()
|
|
37
|
+
class ProductPhotosService {
|
|
38
|
+
constructor(
|
|
39
|
+
private readonly media: MediaService,
|
|
40
|
+
private readonly storage: StorageService,
|
|
41
|
+
) {}
|
|
42
|
+
|
|
43
|
+
async attachPhoto(product: ProductEntity, file: Express.Multer.File) {
|
|
44
|
+
const stored = await this.storage.put(file.buffer, {
|
|
45
|
+
directory: 'gallery',
|
|
46
|
+
fileName: file.originalname,
|
|
47
|
+
contentType: file.mimetype,
|
|
48
|
+
});
|
|
49
|
+
await this.media.addFromUpload(
|
|
50
|
+
{ modelType: 'Product', modelId: product.id },
|
|
51
|
+
'gallery',
|
|
52
|
+
{ path: stored.path, disk: stored.disk, fileName: file.originalname, mimeType: file.mimetype, size: stored.size },
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
`MediaEntity` is the underlying TypeORM entity (polymorphic `modelType`/`modelId` + `collectionName` + the underlying storage disk/key) — list it in your `TypeOrmModule.forRootAsync`'s `entities: [...]` array the same way you would any other entity `@nestjs-dash/*` provides.
|
|
59
|
+
|
|
60
|
+
## Part of nestjs-dash
|
|
61
|
+
|
|
62
|
+
This package is one piece of [nestjs-dash](https://github.com/nestjs-dash/nestjs-dash), a NestJS-native admin framework.
|
|
63
|
+
|
|
64
|
+
## License
|
|
65
|
+
|
|
66
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nestjs-dash/media",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Polymorphic media library plugin for NestJS Dash (Spatie-style media collections on top of @nestjs-dash/storage)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
"access": "public"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@nestjs-dash/nestjs": "0.1
|
|
21
|
-
"@nestjs-dash/storage": "0.1
|
|
20
|
+
"@nestjs-dash/nestjs": "1.0.1",
|
|
21
|
+
"@nestjs-dash/storage": "1.0.1"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@nestjs-dash/typescript-config": "0.1.0",
|