@unchainedshop/core-files 5.0.0-alpha.5 → 5.0.0-alpha.7
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 +9 -86
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -13,97 +13,20 @@ npm install @unchainedshop/core-files
|
|
|
13
13
|
|
|
14
14
|
## Usage
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
import { configureFilesModule } from '@unchainedshop/core-files';
|
|
18
|
-
|
|
19
|
-
const filesModule = await configureFilesModule({
|
|
20
|
-
db,
|
|
21
|
-
options: {
|
|
22
|
-
transformUrl: (url, params) => url, // Optional URL transformation
|
|
23
|
-
},
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
// Create a file record
|
|
27
|
-
const fileId = await filesModule.create({
|
|
28
|
-
name: 'product-image.jpg',
|
|
29
|
-
type: 'image/jpeg',
|
|
30
|
-
path: 'products/123',
|
|
31
|
-
url: '/uploads/product-image.jpg',
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
// Find file and normalize URL
|
|
35
|
-
const file = await filesModule.findFile({ fileId });
|
|
36
|
-
const normalizedUrl = filesModule.normalizeUrl(file.url, {});
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
## API Overview
|
|
40
|
-
|
|
41
|
-
### Module Configuration
|
|
42
|
-
|
|
43
|
-
| Export | Description |
|
|
44
|
-
|--------|-------------|
|
|
45
|
-
| `configureFilesModule` | Configure and return the files module |
|
|
46
|
-
|
|
47
|
-
### Queries
|
|
48
|
-
|
|
49
|
-
| Method | Description |
|
|
50
|
-
|--------|-------------|
|
|
51
|
-
| `findFile` | Find file by ID or URL |
|
|
52
|
-
| `findFiles` | Find files with custom selector |
|
|
53
|
-
|
|
54
|
-
### Mutations
|
|
55
|
-
|
|
56
|
-
| Method | Description |
|
|
57
|
-
|--------|-------------|
|
|
58
|
-
| `create` | Create a new file record |
|
|
59
|
-
| `update` | Update an existing file |
|
|
60
|
-
| `delete` | Delete a file record |
|
|
61
|
-
| `deleteMany` | Delete multiple file records |
|
|
62
|
-
| `unexpire` | Remove expiration from a file |
|
|
63
|
-
|
|
64
|
-
### Helper Methods
|
|
65
|
-
|
|
66
|
-
| Method | Description |
|
|
67
|
-
|--------|-------------|
|
|
68
|
-
| `normalizeUrl` | Normalize and transform file URL |
|
|
69
|
-
|
|
70
|
-
### Utilities
|
|
71
|
-
|
|
72
|
-
| Export | Description |
|
|
73
|
-
|--------|-------------|
|
|
74
|
-
| `getFileAdapter` | Get configured file storage adapter |
|
|
75
|
-
| `getFileFromFileData` | Convert file data to File object |
|
|
76
|
-
| `filesSettings` | Access file module settings |
|
|
77
|
-
|
|
78
|
-
### Types
|
|
79
|
-
|
|
80
|
-
| Export | Description |
|
|
81
|
-
|--------|-------------|
|
|
82
|
-
| `File` | File document type |
|
|
83
|
-
| `FilesModule` | Module interface type |
|
|
84
|
-
| `FilesSettingsOptions` | Configuration options type |
|
|
85
|
-
|
|
86
|
-
## Configuration
|
|
16
|
+
The platform initializes this module as `platform.unchainedAPI.modules.files`.
|
|
87
17
|
|
|
88
18
|
```typescript
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
},
|
|
96
|
-
},
|
|
97
|
-
});
|
|
19
|
+
const { files } = platform.unchainedAPI.modules;
|
|
20
|
+
|
|
21
|
+
const file = await files.findFile({ fileId: 'file-123' });
|
|
22
|
+
if (file?.url) {
|
|
23
|
+
const url = files.normalizeUrl(file.url, { version: 'small' });
|
|
24
|
+
}
|
|
98
25
|
```
|
|
99
26
|
|
|
100
|
-
|
|
27
|
+
This module manages file metadata and URL transformation. File adapters and `unchainedAPI.services.files` handle uploads, downloads, and storage operations. Configure `options.files.transformUrl` and `options.files.privateFileSharingMaxAge` when starting the platform.
|
|
101
28
|
|
|
102
|
-
|
|
103
|
-
|-------|-------------|
|
|
104
|
-
| `FILE_CREATE` | Emitted when a file is created |
|
|
105
|
-
| `FILE_UPDATE` | Emitted when a file is updated |
|
|
106
|
-
| `FILE_REMOVE` | Emitted when a file is removed |
|
|
29
|
+
See the [file upload guide](https://docs.unchained.shop/guides/file-uploads), [module settings](https://docs.unchained.shop/platform-configuration/modules/files), [public exports](src/files-index.ts), and [module implementation](src/module/configureFilesModule.ts).
|
|
107
30
|
|
|
108
31
|
## License
|
|
109
32
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unchainedshop/core-files",
|
|
3
3
|
"description": "File management module for the Unchained Engine",
|
|
4
|
-
"version": "5.0.0-alpha.
|
|
4
|
+
"version": "5.0.0-alpha.7",
|
|
5
5
|
"main": "lib/files-index.js",
|
|
6
6
|
"types": "lib/files-index.d.ts",
|
|
7
7
|
"type": "module",
|
|
@@ -35,9 +35,9 @@
|
|
|
35
35
|
},
|
|
36
36
|
"homepage": "https://github.com/unchainedshop/unchained#readme",
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@unchainedshop/events": "^5.0.0-alpha.
|
|
39
|
-
"@unchainedshop/mongodb": "^5.0.0-alpha.
|
|
40
|
-
"@unchainedshop/utils": "^5.0.0-alpha.
|
|
38
|
+
"@unchainedshop/events": "^5.0.0-alpha.7",
|
|
39
|
+
"@unchainedshop/mongodb": "^5.0.0-alpha.7",
|
|
40
|
+
"@unchainedshop/utils": "^5.0.0-alpha.7"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/node": "^26.2.0",
|