@venizia/ignis-docs 0.2.0 → 0.2.1-0
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 +14 -14
- package/content/best-practices/api-usage-examples.md +39 -19
- package/content/best-practices/architectural-patterns.md +22 -11
- package/content/best-practices/architecture-decisions.md +29 -16
- package/content/best-practices/code-style-standards/advanced-patterns.md +43 -31
- package/content/best-practices/code-style-standards/constants-configuration.md +19 -4
- package/content/best-practices/code-style-standards/control-flow.md +33 -1
- package/content/best-practices/code-style-standards/documentation.md +28 -8
- package/content/best-practices/code-style-standards/function-patterns.md +15 -4
- package/content/best-practices/code-style-standards/index.md +7 -2
- package/content/best-practices/code-style-standards/naming-conventions.md +26 -2
- package/content/best-practices/code-style-standards/route-definitions.md +9 -5
- package/content/best-practices/code-style-standards/tooling.md +14 -1
- package/content/best-practices/code-style-standards/type-safety.md +39 -6
- package/content/best-practices/common-pitfalls.md +59 -35
- package/content/best-practices/contribution-workflow.md +6 -2
- package/content/best-practices/data-modeling.md +78 -62
- package/content/best-practices/deployment-strategies.md +56 -19
- package/content/best-practices/error-handling.md +182 -93
- package/content/best-practices/index.md +6 -0
- package/content/best-practices/performance-optimization.md +26 -13
- package/content/best-practices/security-guidelines.md +35 -9
- package/content/best-practices/testing-strategies.md +7 -2
- package/content/best-practices/troubleshooting-tips.md +27 -17
- package/content/extensions/components/api-reference.md +107 -322
- package/content/extensions/components/authentication/api.md +454 -603
- package/content/extensions/components/authentication/errors.md +121 -498
- package/content/extensions/components/authentication/index.md +88 -801
- package/content/extensions/components/authentication/usage.md +207 -956
- package/content/extensions/components/authorization/api.md +736 -656
- package/content/extensions/components/authorization/errors.md +168 -206
- package/content/extensions/components/authorization/index.md +82 -797
- package/content/extensions/components/authorization/usage.md +194 -527
- package/content/extensions/components/health-check.md +71 -243
- package/content/extensions/components/mail/api.md +504 -287
- package/content/extensions/components/mail/errors.md +73 -61
- package/content/extensions/components/mail/index.md +96 -467
- package/content/extensions/components/mail/usage.md +130 -172
- package/content/extensions/components/request-tracker.md +66 -173
- package/content/extensions/components/socket-io/api.md +195 -13
- package/content/extensions/components/socket-io/errors.md +3 -3
- package/content/extensions/components/socket-io/index.md +50 -337
- package/content/extensions/components/socket-io/usage.md +143 -26
- package/content/extensions/components/static-asset/api.md +410 -142
- package/content/extensions/components/static-asset/errors.md +110 -53
- package/content/extensions/components/static-asset/index.md +79 -608
- package/content/extensions/components/static-asset/usage.md +180 -300
- package/content/extensions/components/websocket/api.md +275 -399
- package/content/extensions/components/websocket/errors.md +47 -56
- package/content/extensions/components/websocket/index.md +74 -407
- package/content/extensions/components/websocket/usage.md +110 -341
- package/content/extensions/helpers/cron/index.md +51 -160
- package/content/extensions/helpers/crypto/index.md +62 -483
- package/content/extensions/helpers/crypto/reference.md +456 -0
- package/content/extensions/helpers/env/index.md +60 -178
- package/content/extensions/helpers/error/index.md +221 -207
- package/content/extensions/helpers/inversion/index.md +65 -556
- package/content/extensions/helpers/inversion/reference.md +522 -0
- package/content/extensions/helpers/kafka/admin.md +20 -1
- package/content/extensions/helpers/kafka/compile-binary.md +41 -35
- package/content/extensions/helpers/kafka/consumer.md +54 -20
- package/content/extensions/helpers/kafka/examples.md +21 -16
- package/content/extensions/helpers/kafka/index.md +80 -610
- package/content/extensions/helpers/kafka/producer.md +134 -5
- package/content/extensions/helpers/kafka/schema-registry.md +45 -70
- package/content/extensions/helpers/logger/hf-logger.md +193 -0
- package/content/extensions/helpers/logger/index.md +64 -563
- package/content/extensions/helpers/logger/pino.md +85 -0
- package/content/extensions/helpers/logger/reference.md +746 -0
- package/content/extensions/helpers/network/api.md +241 -195
- package/content/extensions/helpers/network/index.md +72 -530
- package/content/extensions/helpers/queue/index.md +72 -900
- package/content/extensions/helpers/queue/reference.md +467 -0
- package/content/extensions/helpers/redis/index.md +73 -645
- package/content/extensions/helpers/redis/reference.md +727 -0
- package/content/extensions/helpers/secrets/index.md +66 -0
- package/content/extensions/helpers/socket-io/api.md +305 -203
- package/content/extensions/helpers/socket-io/index.md +66 -432
- package/content/extensions/helpers/storage/api.md +564 -462
- package/content/extensions/helpers/storage/index.md +77 -573
- package/content/extensions/helpers/types/index.md +66 -499
- package/content/extensions/helpers/types/reference.md +650 -0
- package/content/extensions/helpers/uid/index.md +58 -227
- package/content/extensions/helpers/websocket/api.md +329 -216
- package/content/extensions/helpers/websocket/index.md +65 -503
- package/content/extensions/helpers/worker-thread/index.md +58 -396
- package/content/extensions/helpers/worker-thread/reference.md +428 -0
- package/content/guides/core-concepts/persistent/models.md +1 -1
- package/content/guides/core-concepts/persistent/search-typesense.md +3 -3
- package/content/guides/core-concepts/persistent/transactions.md +1 -1
- package/content/guides/core-concepts/secrets-vault.md +177 -0
- package/content/guides/core-concepts/services.md +1 -1
- package/content/guides/migrations/redis-helpers-migration.md +1 -1
- package/content/guides/migrations/unified-connectors-migration.md +2 -2
- package/content/guides/tutorials/ecommerce-api.md +3 -8
- package/content/references/base/application.md +1 -1
- package/content/references/base/connectors.md +79 -136
- package/content/references/base/datasources-reference.md +599 -0
- package/content/references/base/datasources.md +84 -444
- package/content/references/base/dependency-injection.md +17 -39
- package/content/references/base/filter-system/application-usage.md +69 -121
- package/content/references/base/filter-system/array-operators.md +12 -0
- package/content/references/base/filter-system/comparison-operators.md +12 -0
- package/content/references/base/filter-system/default-filter.md +136 -348
- package/content/references/base/filter-system/fields-order-pagination.md +38 -16
- package/content/references/base/filter-system/index.md +106 -257
- package/content/references/base/filter-system/json-filtering.md +12 -2
- package/content/references/base/filter-system/list-operators.md +16 -2
- package/content/references/base/filter-system/logical-operators.md +13 -0
- package/content/references/base/filter-system/null-operators.md +13 -0
- package/content/references/base/filter-system/pattern-matching.md +12 -0
- package/content/references/base/filter-system/quick-reference.md +11 -2
- package/content/references/base/filter-system/range-operators.md +12 -0
- package/content/references/base/filter-system/tips.md +70 -133
- package/content/references/base/filter-system/use-cases.md +156 -233
- package/content/references/base/middlewares.md +35 -21
- package/content/references/base/models-reference.md +886 -0
- package/content/references/base/models.md +80 -1452
- package/content/references/base/repositories/advanced.md +156 -192
- package/content/references/base/repositories/index.md +77 -650
- package/content/references/base/repositories/mixins.md +22 -18
- package/content/references/base/repositories/relations.md +123 -171
- package/content/references/base/repositories/soft-deletable.md +58 -56
- package/content/references/base/secrets.md +263 -0
- package/content/references/base/services.md +2 -2
- package/content/references/configuration/environment-variables.md +48 -4
- package/content/references/configuration/index.md +49 -31
- package/content/references/quick-reference.md +3 -16
- package/content/references/utilities/crypto.md +35 -76
- package/content/references/utilities/date.md +33 -73
- package/content/references/utilities/index.md +1 -1
- package/content/references/utilities/jsx-reference.md +298 -0
- package/content/references/utilities/jsx.md +82 -525
- package/content/references/utilities/module.md +29 -62
- package/content/references/utilities/parse.md +34 -64
- package/content/references/utilities/performance.md +33 -58
- package/content/references/utilities/promise.md +28 -62
- package/content/references/utilities/request.md +57 -218
- package/content/references/utilities/schema.md +43 -137
- package/content/references/utilities/statuses-reference.md +361 -0
- package/content/references/utilities/statuses.md +63 -667
- package/package.json +8 -8
|
@@ -1,235 +1,88 @@
|
|
|
1
|
-
|
|
1
|
+
---
|
|
2
|
+
title: Static Asset Component
|
|
3
|
+
description: Generates bucket/object CRUD REST endpoints for disk, MinIO, and Bun S3 storage backends, with optional database-backed file tracking via MetaLink
|
|
4
|
+
difficulty: intermediate
|
|
5
|
+
---
|
|
2
6
|
|
|
3
|
-
|
|
7
|
+
# Static Asset Component
|
|
4
8
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
| Item | Value |
|
|
8
|
-
|------|-------|
|
|
9
|
-
| **Package** | `@venizia/ignis` |
|
|
10
|
-
| **Class** | `StaticAssetComponent` |
|
|
11
|
-
| **Helper** | [`DiskHelper`](/extensions/helpers/storage/), [`MinioHelper`](/extensions/helpers/storage/), [`BunS3Helper`](/extensions/helpers/storage/) |
|
|
12
|
-
| **Runtimes** | Both |
|
|
13
|
-
|
|
14
|
-
#### Import Paths
|
|
9
|
+
`StaticAssetComponent` reads a map of storage backend configurations and generates a full bucket/object REST controller for each one - disk, MinIO, or Bun S3 - all through the same [`IStorageHelper`](./api#istoragehelper-interface) contract.
|
|
15
10
|
|
|
16
11
|
> [!IMPORTANT]
|
|
17
|
-
> `StaticAssetComponent` and its related exports are **not**
|
|
18
|
-
|
|
19
|
-
```typescript
|
|
20
|
-
// From core -- subpath import (NOT from '@venizia/ignis')
|
|
21
|
-
import {
|
|
22
|
-
StaticAssetComponent,
|
|
23
|
-
StaticAssetComponentBindingKeys,
|
|
24
|
-
StaticAssetStorageTypes,
|
|
25
|
-
AssetControllerFactory,
|
|
26
|
-
BaseMetaLinkModel,
|
|
27
|
-
BaseMetaLinkRepository,
|
|
28
|
-
} from '@venizia/ignis/static-asset';
|
|
29
|
-
|
|
30
|
-
import { DiskHelper } from '@venizia/ignis-helpers';
|
|
31
|
-
import { MinioHelper } from '@venizia/ignis-helpers/minio';
|
|
32
|
-
import { BunS3Helper } from '@venizia/ignis-helpers/bun-s3';
|
|
33
|
-
|
|
34
|
-
import type {
|
|
35
|
-
TStaticAssetsComponentOptions,
|
|
36
|
-
TMetaLinkConfig,
|
|
37
|
-
TStaticAssetExtraOptions,
|
|
38
|
-
TStaticAssetStorageType,
|
|
39
|
-
} from '@venizia/ignis/static-asset';
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
### Key Features
|
|
43
|
-
|
|
44
|
-
| Feature | Description |
|
|
45
|
-
|---------|-------------|
|
|
46
|
-
| **Unified Storage Interface** | Single API for all storage types |
|
|
47
|
-
| **Multiple Storage Instances** | Configure multiple storage backends simultaneously |
|
|
48
|
-
| **Factory Pattern** | Dynamic controller generation per storage backend |
|
|
49
|
-
| **Built-in Security** | Comprehensive name validation, path traversal protection, header sanitization |
|
|
50
|
-
| **Database Tracking (MetaLink)** | Optional database-backed file tracking with metadata, principal association, variant support, and sync status |
|
|
51
|
-
| **Per-Route Configuration** | Override authentication, middleware, and path for individual routes |
|
|
52
|
-
| **Flexible Configuration** | Environment-based, production-ready setup |
|
|
12
|
+
> `StaticAssetComponent` and its related exports are **not** on the `@venizia/ignis` root barrel. Import from the `@venizia/ignis/static-asset` subpath.
|
|
53
13
|
|
|
54
|
-
##
|
|
55
|
-
|
|
56
|
-
### Step 1: Bind Configuration
|
|
14
|
+
## In one example
|
|
57
15
|
|
|
58
16
|
```typescript
|
|
59
17
|
import { BaseApplication } from '@venizia/ignis';
|
|
60
18
|
import {
|
|
19
|
+
StaticAssetComponent,
|
|
61
20
|
StaticAssetComponentBindingKeys,
|
|
62
21
|
StaticAssetStorageTypes,
|
|
63
22
|
} from '@venizia/ignis/static-asset';
|
|
64
|
-
import { DiskHelper } from '@venizia/ignis-helpers';
|
|
65
|
-
import { MinioHelper } from '@venizia/ignis-helpers/minio';
|
|
66
23
|
import type { TStaticAssetsComponentOptions } from '@venizia/ignis/static-asset';
|
|
24
|
+
import { DiskHelper } from '@venizia/ignis-helpers';
|
|
67
25
|
|
|
68
26
|
export class Application extends BaseApplication {
|
|
69
27
|
preConfigure() {
|
|
70
28
|
this.bind<TStaticAssetsComponentOptions>({
|
|
71
29
|
key: StaticAssetComponentBindingKeys.STATIC_ASSET_COMPONENT_OPTIONS,
|
|
72
30
|
}).toValue({
|
|
73
|
-
// MinIO storage for user uploads
|
|
74
31
|
staticAsset: {
|
|
75
|
-
controller: {
|
|
76
|
-
name: 'AssetController',
|
|
77
|
-
basePath: '/assets',
|
|
78
|
-
isStrict: true,
|
|
79
|
-
},
|
|
80
|
-
storage: StaticAssetStorageTypes.MINIO,
|
|
81
|
-
helper: new MinioHelper({
|
|
82
|
-
endPoint: 'localhost',
|
|
83
|
-
port: 9000,
|
|
84
|
-
accessKey: 'minioadmin',
|
|
85
|
-
secretKey: 'minioadmin',
|
|
86
|
-
useSSL: false,
|
|
87
|
-
}),
|
|
88
|
-
extra: {
|
|
89
|
-
parseMultipartBody: { storage: 'memory' },
|
|
90
|
-
},
|
|
91
|
-
},
|
|
92
|
-
// Local disk storage for temporary files
|
|
93
|
-
staticResource: {
|
|
94
|
-
controller: {
|
|
95
|
-
name: 'ResourceController',
|
|
96
|
-
basePath: '/resources',
|
|
97
|
-
isStrict: true,
|
|
98
|
-
},
|
|
32
|
+
controller: { name: 'AssetController', basePath: '/assets', isStrict: true },
|
|
99
33
|
storage: StaticAssetStorageTypes.DISK,
|
|
100
|
-
helper: new DiskHelper({
|
|
101
|
-
|
|
102
|
-
}),
|
|
103
|
-
extra: {
|
|
104
|
-
parseMultipartBody: { storage: 'memory' },
|
|
105
|
-
},
|
|
34
|
+
helper: new DiskHelper({ basePath: './app_data/assets' }),
|
|
35
|
+
extra: { parseMultipartBody: { storage: 'memory' } },
|
|
106
36
|
},
|
|
107
37
|
});
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
```
|
|
111
38
|
|
|
112
|
-
Each storage backend gets a unique key (`staticAsset`, `staticResource`), its own controller configuration, and a helper instance.
|
|
113
|
-
|
|
114
|
-
### Step 2: Register Component
|
|
115
|
-
|
|
116
|
-
```typescript
|
|
117
|
-
import { StaticAssetComponent } from '@venizia/ignis/static-asset';
|
|
118
|
-
|
|
119
|
-
export class Application extends BaseApplication {
|
|
120
|
-
preConfigure() {
|
|
121
|
-
// ... Step 1 binding ...
|
|
122
39
|
this.component(StaticAssetComponent);
|
|
123
40
|
}
|
|
124
41
|
}
|
|
125
42
|
```
|
|
126
43
|
|
|
127
|
-
|
|
44
|
+
This registers `GET`/`POST`/`DELETE` on `/assets/buckets/:bucketName`, `POST /assets/buckets/:bucketName/upload`, `GET /assets/buckets/:bucketName/objects`, plus stream/download/delete-object routes - no controller class to write by hand.
|
|
128
45
|
|
|
129
|
-
|
|
46
|
+
## How it works
|
|
130
47
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
GET /assets/buckets/:bucketName/objects - List objects in bucket
|
|
138
|
-
GET /assets/buckets/:bucketName/objects/:obj - Stream file inline
|
|
139
|
-
GET /assets/buckets/:bucketName/download/:obj - Download file (attachment)
|
|
140
|
-
DELETE /assets/buckets/:bucketName/objects/:obj - Delete file
|
|
141
|
-
PUT /assets/buckets/:bucketName/meta-links/:obj - Sync MetaLink (MetaLink only)
|
|
142
|
-
```
|
|
143
|
-
|
|
144
|
-
Each storage backend gets its own base path (`/assets`, `/resources`, etc.) with the same endpoint structure.
|
|
145
|
-
|
|
146
|
-
#### Environment Variables
|
|
48
|
+
- **One options key, one generated controller.** `TStaticAssetsComponentOptions` is a record - each key (`staticAsset` above) becomes an independently-configured storage backend with its own `basePath`, built by `AssetControllerFactory.defineAssetController()` inside `StaticAssetComponent.binding()`.
|
|
49
|
+
- **`storage` and `helper` are a discriminated pair.** The options type forces `storage: 'disk'` with a `DiskHelper`, `'minio'` with a `MinioHelper`, or `'bun-s3'` with a `BunS3Helper` - mismatching them fails at compile time, not at runtime.
|
|
50
|
+
- **Every backend implements the same `IStorageHelper` contract.** `DiskHelper`, `MinioHelper`, and `BunS3Helper` all extend `BaseStorageHelper`, so bucket/object operations, name validation (`isValidName`/`isValidPath`), and upload normalization behave identically regardless of backend.
|
|
51
|
+
- **Object names can embed folder paths, encoded as one segment.** `objects/{objectName}` takes the whole `folder/file.ext` string percent-encoded (`encodeURIComponent`, which also escapes `/`) - Hono decodes it once before the handler reads it, so client code must encode but never decode a second time.
|
|
52
|
+
- **MetaLink is opt-in.** Set `useMetaLink: true` and provide `metaLink.repository` to persist a database row (bucket, object, mimetype, size, etag, principal, variant) alongside every upload - useful for querying "which files does user X own" without listing a whole bucket.
|
|
53
|
+
- **The default binding is empty.** `StaticAssetComponentBindingKeys.STATIC_ASSET_COMPONENT_OPTIONS` defaults to `{}` - bind it with at least one storage backend before `this.component(StaticAssetComponent)` produces any routes.
|
|
147
54
|
|
|
148
|
-
|
|
55
|
+
## Common tasks
|
|
149
56
|
|
|
150
|
-
|
|
151
|
-
APP_ENV_MINIO_HOST=localhost
|
|
152
|
-
APP_ENV_MINIO_API_PORT=9000
|
|
153
|
-
APP_ENV_MINIO_ACCESS_KEY=minioadmin
|
|
154
|
-
APP_ENV_MINIO_SECRET_KEY=minioadmin
|
|
155
|
-
```
|
|
57
|
+
### Add a second storage backend
|
|
156
58
|
|
|
157
|
-
|
|
59
|
+
Each key in the options object is independent - mix disk and MinIO under different base paths in one binding.
|
|
158
60
|
|
|
159
61
|
```typescript
|
|
160
|
-
|
|
161
|
-
import { EnvironmentKeys as BaseEnv } from '@venizia/ignis';
|
|
162
|
-
|
|
163
|
-
export class EnvironmentKeys extends BaseEnv {
|
|
164
|
-
static readonly APP_ENV_MINIO_HOST = 'APP_ENV_MINIO_HOST';
|
|
165
|
-
static readonly APP_ENV_MINIO_API_PORT = 'APP_ENV_MINIO_API_PORT';
|
|
166
|
-
static readonly APP_ENV_MINIO_ACCESS_KEY = 'APP_ENV_MINIO_ACCESS_KEY';
|
|
167
|
-
static readonly APP_ENV_MINIO_SECRET_KEY = 'APP_ENV_MINIO_SECRET_KEY';
|
|
168
|
-
}
|
|
169
|
-
```
|
|
170
|
-
|
|
171
|
-
#### Docker Compose for MinIO
|
|
172
|
-
|
|
173
|
-
```yaml
|
|
174
|
-
version: '3.8'
|
|
175
|
-
services:
|
|
176
|
-
minio:
|
|
177
|
-
image: minio/minio:latest
|
|
178
|
-
container_name: minio
|
|
179
|
-
ports:
|
|
180
|
-
- "9000:9000" # API port
|
|
181
|
-
- "9001:9001" # Console port
|
|
182
|
-
environment:
|
|
183
|
-
MINIO_ROOT_USER: minioadmin
|
|
184
|
-
MINIO_ROOT_PASSWORD: minioadmin
|
|
185
|
-
command: server /data --console-address ":9001"
|
|
186
|
-
volumes:
|
|
187
|
-
- minio_data:/data
|
|
188
|
-
|
|
189
|
-
volumes:
|
|
190
|
-
minio_data:
|
|
191
|
-
```
|
|
192
|
-
|
|
193
|
-
Start with `docker-compose up -d` and access the console at `http://localhost:9001`.
|
|
194
|
-
|
|
195
|
-
## Configuration
|
|
196
|
-
|
|
197
|
-
### Storage Types
|
|
198
|
-
|
|
199
|
-
| Type | Constant | Helper | Description |
|
|
200
|
-
|------|----------|--------|-------------|
|
|
201
|
-
| `'disk'` | `StaticAssetStorageTypes.DISK` | `DiskHelper` | Local filesystem with bucket-based directory structure |
|
|
202
|
-
| `'minio'` | `StaticAssetStorageTypes.MINIO` | `MinioHelper` | S3-compatible object storage (MinIO, AWS S3, etc.) |
|
|
203
|
-
| `'bun-s3'` | `StaticAssetStorageTypes.BUN_S3` | `BunS3Helper` | Bun-native S3 client (requires Bun runtime) |
|
|
204
|
-
|
|
205
|
-
The `StaticAssetStorageTypes` class provides a `SCHEME_SET` (a `Set` of all valid storage type strings) and an `isValid(orgType)` method for runtime validation:
|
|
62
|
+
import { MinioHelper } from '@venizia/ignis-helpers/minio';
|
|
206
63
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
64
|
+
this.bind<TStaticAssetsComponentOptions>({
|
|
65
|
+
key: StaticAssetComponentBindingKeys.STATIC_ASSET_COMPONENT_OPTIONS,
|
|
66
|
+
}).toValue({
|
|
67
|
+
uploads: {
|
|
68
|
+
controller: { name: 'UploadsController', basePath: '/uploads' },
|
|
69
|
+
storage: StaticAssetStorageTypes.MINIO,
|
|
70
|
+
helper: new MinioHelper({
|
|
71
|
+
endPoint: 'localhost', port: 9000, useSSL: false,
|
|
72
|
+
accessKey: 'minioadmin', secretKey: 'minioadmin',
|
|
73
|
+
}),
|
|
74
|
+
},
|
|
75
|
+
tempFiles: {
|
|
76
|
+
controller: { name: 'TempController', basePath: '/temp' },
|
|
77
|
+
storage: StaticAssetStorageTypes.DISK,
|
|
78
|
+
helper: new DiskHelper({ basePath: './temp' }),
|
|
79
|
+
},
|
|
80
|
+
});
|
|
212
81
|
```
|
|
213
82
|
|
|
214
|
-
###
|
|
215
|
-
|
|
216
|
-
Each key in the options object defines a separate storage backend with its own controller:
|
|
217
|
-
|
|
218
|
-
| Option | Type | Default | Description |
|
|
219
|
-
|--------|------|---------|-------------|
|
|
220
|
-
| `controller.name` | `string` | -- | Controller class name |
|
|
221
|
-
| `controller.basePath` | `string` | -- | Base URL path (e.g., `'/assets'`) |
|
|
222
|
-
| `controller.isStrict` | `boolean` | `true` | Strict routing mode |
|
|
223
|
-
| `controller.routes` | `object` | `undefined` | Per-route overrides (authenticate, middleware, path) |
|
|
224
|
-
| `storage` | `'disk' \| 'minio' \| 'bun-s3'` | -- | Storage type |
|
|
225
|
-
| `helper` | `DiskHelper \| MinioHelper \| BunS3Helper` | -- | Storage helper instance |
|
|
226
|
-
| `extra` | `TStaticAssetExtraOptions` | `undefined` | Extra options (multipart parsing, name normalization) |
|
|
227
|
-
| `useMetaLink` | `boolean` | `false` | Enable database file tracking |
|
|
228
|
-
| `metaLink` | `TMetaLinkConfig` | -- | MetaLink configuration (required when `useMetaLink: true`) |
|
|
83
|
+
### Lock down individual routes
|
|
229
84
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
Each route can be individually configured with authentication, middleware, and path overrides:
|
|
85
|
+
Each key under `controller.routes` accepts a partial `authenticate`/`authorize`/`middleware`/`path` override; unset routes stay public.
|
|
233
86
|
|
|
234
87
|
```typescript
|
|
235
88
|
{
|
|
@@ -237,446 +90,64 @@ Each route can be individually configured with authentication, middleware, and p
|
|
|
237
90
|
name: 'AssetController',
|
|
238
91
|
basePath: '/assets',
|
|
239
92
|
routes: {
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
downloadObjectByName: { /* public */ },
|
|
244
|
-
deleteObject: { authenticate: { strategies: ['jwt'], mode: 'any' } },
|
|
245
|
-
deleteBucket: { authenticate: { strategies: ['jwt'], mode: 'any' } },
|
|
93
|
+
upload: { authenticate: { strategies: ['jwt'], mode: 'required' } },
|
|
94
|
+
deleteObject: { authenticate: { strategies: ['jwt'], mode: 'required' } },
|
|
95
|
+
deleteBucket: { authenticate: { strategies: ['jwt'], mode: 'required' } },
|
|
246
96
|
},
|
|
247
97
|
},
|
|
248
|
-
// ...
|
|
249
98
|
}
|
|
250
99
|
```
|
|
251
100
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
#### TStaticAssetsComponentOptions -- Full Reference
|
|
255
|
-
```typescript
|
|
256
|
-
type TStaticAssetsComponentOptions = {
|
|
257
|
-
[key: string]: {
|
|
258
|
-
controller: {
|
|
259
|
-
name: string;
|
|
260
|
-
basePath: string;
|
|
261
|
-
isStrict?: boolean;
|
|
262
|
-
routes?: {
|
|
263
|
-
getBuckets?: Partial<Omit<IAuthRouteConfig, 'method' | 'request' | 'responses'>>;
|
|
264
|
-
getBucketByName?: Partial<Omit<IAuthRouteConfig, 'method' | 'request' | 'responses'>>;
|
|
265
|
-
createBucket?: Partial<Omit<IAuthRouteConfig, 'method' | 'request' | 'responses'>>;
|
|
266
|
-
deleteBucket?: Partial<Omit<IAuthRouteConfig, 'method' | 'request' | 'responses'>>;
|
|
267
|
-
upload?: Partial<Omit<IAuthRouteConfig, 'method' | 'request' | 'responses'>>;
|
|
268
|
-
listObjects?: Partial<Omit<IAuthRouteConfig, 'method' | 'request' | 'responses'>>;
|
|
269
|
-
deleteObject?: Partial<Omit<IAuthRouteConfig, 'method' | 'request' | 'responses'>>;
|
|
270
|
-
getObjectByName?: Partial<Omit<IAuthRouteConfig, 'method' | 'request' | 'responses'>>;
|
|
271
|
-
downloadObjectByName?: Partial<Omit<IAuthRouteConfig, 'method' | 'request' | 'responses'>>;
|
|
272
|
-
recreateMetaLink?: Partial<Omit<IAuthRouteConfig, 'method' | 'request' | 'responses'>>;
|
|
273
|
-
};
|
|
274
|
-
};
|
|
275
|
-
extra?: TStaticAssetExtraOptions;
|
|
276
|
-
} & (
|
|
277
|
-
| { storage: typeof StaticAssetStorageTypes.BUN_S3; helper: BunS3Helper }
|
|
278
|
-
| { storage: typeof StaticAssetStorageTypes.DISK; helper: DiskHelper }
|
|
279
|
-
| { storage: typeof StaticAssetStorageTypes.MINIO; helper: MinioHelper }
|
|
280
|
-
) &
|
|
281
|
-
({ useMetaLink?: false | undefined } | { useMetaLink: true; metaLink: TMetaLinkConfig });
|
|
282
|
-
};
|
|
283
|
-
|
|
284
|
-
type TStaticAssetExtraOptions = {
|
|
285
|
-
parseMultipartBody?: {
|
|
286
|
-
storage?: 'memory' | 'disk';
|
|
287
|
-
uploadDir?: string;
|
|
288
|
-
};
|
|
289
|
-
normalizeNameFn?: (opts: { originalName: string }) => string;
|
|
290
|
-
normalizeLinkFn?: (opts: { bucketName: string; normalizeName: string }) => string;
|
|
291
|
-
/** Maximum folder nesting depth allowed in object paths. Default: 2 */
|
|
292
|
-
maxFolderDepth?: number;
|
|
293
|
-
[key: string]: any;
|
|
294
|
-
};
|
|
295
|
-
|
|
296
|
-
type TMetaLinkConfig<Schema extends TMetaLinkSchema = TMetaLinkSchema> = {
|
|
297
|
-
model: typeof BasePostgresEntity<Schema>;
|
|
298
|
-
repository: DefaultCRUDRepository<Schema>;
|
|
299
|
-
createMetaLink?: (opts: {
|
|
300
|
-
uploadResult: IUploadResult;
|
|
301
|
-
fileStat: IFileStat;
|
|
302
|
-
query: TUploadQuery;
|
|
303
|
-
}) => ValueOrPromise<{ count: number; data: Schema }>;
|
|
304
|
-
};
|
|
305
|
-
```
|
|
306
|
-
|
|
307
|
-
> [!NOTE]
|
|
308
|
-
> The `normalizeNameFn` receives only `{ originalName }` -- there is no `folderPath` parameter.
|
|
309
|
-
|
|
310
|
-
> [!TIP]
|
|
311
|
-
> The `createMetaLink` callback on `TMetaLinkConfig` is optional. When provided, it replaces the default MetaLink creation logic during upload, giving you full control over how file metadata is stored.
|
|
312
|
-
|
|
313
|
-
### DiskHelper
|
|
101
|
+
### Switch multipart parsing to disk for large uploads
|
|
314
102
|
|
|
315
|
-
|
|
103
|
+
`parseMultipartBody: { storage: 'memory' }` (the default) buffers the whole file in RAM before writing it to the backend. Switch to `'disk'` to spool it to a temp file instead.
|
|
316
104
|
|
|
317
105
|
```typescript
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
scope?: string; // Logger scope
|
|
321
|
-
identifier?: string; // Helper identifier
|
|
322
|
-
})
|
|
323
|
-
```
|
|
324
|
-
|
|
325
|
-
**Example:**
|
|
326
|
-
|
|
327
|
-
```typescript
|
|
328
|
-
const diskHelper = new DiskHelper({
|
|
329
|
-
basePath: './app_data/storage',
|
|
330
|
-
});
|
|
331
|
-
```
|
|
332
|
-
|
|
333
|
-
**Directory structure:**
|
|
334
|
-
```
|
|
335
|
-
app_data/storage/
|
|
336
|
-
├── bucket-1/
|
|
337
|
-
│ ├── file1.pdf
|
|
338
|
-
│ └── file2.jpg
|
|
339
|
-
├── bucket-2/
|
|
340
|
-
│ └── document.docx
|
|
341
|
-
```
|
|
342
|
-
|
|
343
|
-
Features: automatic directory creation, built-in path validation, metadata from file stats, stream-based operations.
|
|
344
|
-
|
|
345
|
-
### MinioHelper
|
|
346
|
-
|
|
347
|
-
Connects to MinIO or any S3-compatible object storage.
|
|
348
|
-
|
|
349
|
-
```typescript
|
|
350
|
-
new MinioHelper({
|
|
351
|
-
endPoint: string; // MinIO server hostname
|
|
352
|
-
port: number; // API port (default: 9000)
|
|
353
|
-
useSSL: boolean; // Use HTTPS
|
|
354
|
-
accessKey: string; // Access key
|
|
355
|
-
secretKey: string; // Secret key
|
|
356
|
-
})
|
|
357
|
-
```
|
|
358
|
-
|
|
359
|
-
**Example:**
|
|
360
|
-
|
|
361
|
-
```typescript
|
|
362
|
-
const minioHelper = new MinioHelper({
|
|
363
|
-
endPoint: 'minio.example.com',
|
|
364
|
-
port: 9000,
|
|
365
|
-
useSSL: true,
|
|
366
|
-
accessKey: process.env.MINIO_ACCESS_KEY,
|
|
367
|
-
secretKey: process.env.MINIO_SECRET_KEY,
|
|
368
|
-
});
|
|
369
|
-
```
|
|
370
|
-
|
|
371
|
-
### BunS3Helper
|
|
372
|
-
|
|
373
|
-
Bun-native S3 client for direct S3/S3-compatible access using Bun's built-in S3 support. Requires Bun runtime.
|
|
374
|
-
|
|
375
|
-
```typescript
|
|
376
|
-
import { BunS3Helper } from '@venizia/ignis-helpers/bun-s3';
|
|
377
|
-
```
|
|
378
|
-
|
|
379
|
-
### MetaLink Configuration
|
|
380
|
-
|
|
381
|
-
MetaLink is an optional feature that tracks uploaded files in a database, storing file location, metadata (mimetype, size, etag), storage type, principal association (`principalType`, `principalId`), variant, timestamps, and custom metadata (JSONB).
|
|
382
|
-
|
|
383
|
-
#### Benefits
|
|
384
|
-
|
|
385
|
-
- Query uploaded files by bucket, name, mimetype, variant, etc.
|
|
386
|
-
- Track file history and audit trails
|
|
387
|
-
- Store custom metadata about files
|
|
388
|
-
- Associate files with principals via `principalType` and `principalId` (passed as query parameters on the upload endpoint)
|
|
389
|
-
- Tag uploads with a `variant` query parameter (e.g., `"thumbnail"`, `"original"`)
|
|
390
|
-
- Custom `createMetaLink` callback for full control over MetaLink creation
|
|
391
|
-
- Graceful errors -- upload succeeds even if MetaLink creation fails
|
|
392
|
-
|
|
393
|
-
#### Setup
|
|
394
|
-
|
|
395
|
-
**1. Create Model:**
|
|
396
|
-
|
|
397
|
-
```typescript
|
|
398
|
-
import { BaseMetaLinkModel } from '@venizia/ignis/static-asset';
|
|
399
|
-
import { model } from '@venizia/ignis';
|
|
400
|
-
|
|
401
|
-
@model({ type: 'entity' })
|
|
402
|
-
export class FileMetaLinkModel extends BaseMetaLinkModel {
|
|
403
|
-
// Inherits all fields from BaseMetaLinkModel
|
|
106
|
+
extra: {
|
|
107
|
+
parseMultipartBody: { storage: 'disk', uploadDir: './tmp/uploads' },
|
|
404
108
|
}
|
|
405
109
|
```
|
|
406
110
|
|
|
407
|
-
|
|
111
|
+
### Enable MetaLink database tracking
|
|
408
112
|
|
|
409
|
-
|
|
410
|
-
import { BaseMetaLinkRepository } from '@venizia/ignis/static-asset';
|
|
411
|
-
import { repository } from '@venizia/ignis';
|
|
412
|
-
import { FileMetaLinkModel } from './file-meta-link.model';
|
|
413
|
-
import { PostgresDataSource } from '../datasources/postgres.datasource';
|
|
414
|
-
|
|
415
|
-
@repository({ model: FileMetaLinkModel, dataSource: PostgresDataSource })
|
|
416
|
-
export class FileMetaLinkRepository extends BaseMetaLinkRepository {
|
|
417
|
-
// No constructor needed - dataSource auto-injected from @repository metadata
|
|
418
|
-
}
|
|
419
|
-
```
|
|
420
|
-
|
|
421
|
-
**3. Create Database Table:**
|
|
422
|
-
|
|
423
|
-
The model has `skipMigrate: true`, so create the table manually:
|
|
424
|
-
|
|
425
|
-
```sql
|
|
426
|
-
CREATE TABLE "MetaLink" (
|
|
427
|
-
id TEXT PRIMARY KEY,
|
|
428
|
-
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
429
|
-
modified_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
430
|
-
bucket_name TEXT NOT NULL,
|
|
431
|
-
object_name TEXT NOT NULL,
|
|
432
|
-
link TEXT NOT NULL,
|
|
433
|
-
mimetype TEXT NOT NULL,
|
|
434
|
-
size INTEGER NOT NULL,
|
|
435
|
-
etag TEXT,
|
|
436
|
-
metadata JSONB,
|
|
437
|
-
storage_type TEXT NOT NULL,
|
|
438
|
-
is_synced BOOLEAN NOT NULL DEFAULT false,
|
|
439
|
-
variant TEXT,
|
|
440
|
-
principal_type TEXT,
|
|
441
|
-
principal_id TEXT
|
|
442
|
-
);
|
|
443
|
-
|
|
444
|
-
CREATE INDEX "IDX_MetaLink_bucketName" ON "MetaLink"(bucket_name);
|
|
445
|
-
CREATE INDEX "IDX_MetaLink_objectName" ON "MetaLink"(object_name);
|
|
446
|
-
CREATE INDEX "IDX_MetaLink_storageType" ON "MetaLink"(storage_type);
|
|
447
|
-
CREATE INDEX "IDX_MetaLink_isSynced" ON "MetaLink"(is_synced);
|
|
448
|
-
```
|
|
449
|
-
|
|
450
|
-
**4. Configure Component:**
|
|
451
|
-
|
|
452
|
-
```typescript
|
|
453
|
-
import { FileMetaLinkModel, FileMetaLinkRepository } from './your-models';
|
|
454
|
-
import {
|
|
455
|
-
StaticAssetComponent,
|
|
456
|
-
StaticAssetComponentBindingKeys,
|
|
457
|
-
StaticAssetStorageTypes,
|
|
458
|
-
} from '@venizia/ignis/static-asset';
|
|
459
|
-
import type { TStaticAssetsComponentOptions } from '@venizia/ignis/static-asset';
|
|
460
|
-
|
|
461
|
-
export class Application extends BaseApplication {
|
|
462
|
-
configureComponents(): void {
|
|
463
|
-
this.repository(FileMetaLinkRepository);
|
|
464
|
-
|
|
465
|
-
this.bind<TStaticAssetsComponentOptions>({
|
|
466
|
-
key: StaticAssetComponentBindingKeys.STATIC_ASSET_COMPONENT_OPTIONS,
|
|
467
|
-
}).toValue({
|
|
468
|
-
uploads: {
|
|
469
|
-
controller: {
|
|
470
|
-
name: 'UploadController',
|
|
471
|
-
basePath: '/uploads',
|
|
472
|
-
isStrict: true,
|
|
473
|
-
},
|
|
474
|
-
storage: StaticAssetStorageTypes.MINIO,
|
|
475
|
-
helper: new MinioHelper({ /* ... */ }),
|
|
476
|
-
useMetaLink: true,
|
|
477
|
-
metaLink: {
|
|
478
|
-
model: FileMetaLinkModel,
|
|
479
|
-
repository: this.getSync(FileMetaLinkRepository),
|
|
480
|
-
},
|
|
481
|
-
extra: {
|
|
482
|
-
parseMultipartBody: { storage: 'memory' },
|
|
483
|
-
},
|
|
484
|
-
},
|
|
485
|
-
});
|
|
486
|
-
|
|
487
|
-
this.component(StaticAssetComponent);
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
```
|
|
491
|
-
|
|
492
|
-
**5. Upload with Principal Association and Variant:**
|
|
493
|
-
|
|
494
|
-
When MetaLink is enabled, you can associate uploaded files with a principal and variant by passing query parameters on the upload endpoint:
|
|
495
|
-
|
|
496
|
-
```typescript
|
|
497
|
-
const formData = new FormData();
|
|
498
|
-
formData.append('file', fileBlob, 'document.pdf');
|
|
499
|
-
|
|
500
|
-
// Associate the upload with a user and tag as 'original' variant
|
|
501
|
-
const response = await fetch(
|
|
502
|
-
'/uploads/buckets/user-files/upload?principalType=user&principalId=42&variant=original',
|
|
503
|
-
{ method: 'POST', body: formData },
|
|
504
|
-
);
|
|
505
|
-
```
|
|
506
|
-
|
|
507
|
-
The `principalId` value is always stored as a string regardless of input type (coerced via `String()`).
|
|
508
|
-
|
|
509
|
-
#### Custom MetaLink Creation
|
|
510
|
-
|
|
511
|
-
You can provide a custom `createMetaLink` callback to fully control how MetaLink records are created:
|
|
113
|
+
Bind a repository over `BaseMetaLinkModel` (used directly, no subclass needed) and pass it as `metaLink.repository`.
|
|
512
114
|
|
|
513
115
|
```typescript
|
|
116
|
+
useMetaLink: true,
|
|
514
117
|
metaLink: {
|
|
515
|
-
model:
|
|
516
|
-
repository: this.
|
|
517
|
-
createMetaLink: async ({ uploadResult, fileStat, query }) => {
|
|
518
|
-
// Custom logic -- e.g., add extra fields, validate, transform
|
|
519
|
-
return metaLinkRepo.create({
|
|
520
|
-
data: {
|
|
521
|
-
bucketName: uploadResult.bucketName,
|
|
522
|
-
objectName: uploadResult.objectName,
|
|
523
|
-
link: uploadResult.link,
|
|
524
|
-
mimetype: fileStat.metadata?.['mimetype'],
|
|
525
|
-
size: fileStat.size,
|
|
526
|
-
etag: fileStat.etag,
|
|
527
|
-
metadata: fileStat.metadata,
|
|
528
|
-
storageType: 'minio',
|
|
529
|
-
isSynced: true,
|
|
530
|
-
principalId: query.principalId ? String(query.principalId) : undefined,
|
|
531
|
-
principalType: query.principalType,
|
|
532
|
-
variant: query.variant,
|
|
533
|
-
// ... additional custom fields
|
|
534
|
-
},
|
|
535
|
-
});
|
|
536
|
-
},
|
|
118
|
+
model: BaseMetaLinkModel,
|
|
119
|
+
repository: this.get<MetaLinkRepository>({ key: 'repositories.MetaLinkRepository' }),
|
|
537
120
|
},
|
|
538
121
|
```
|
|
539
122
|
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
#### Querying MetaLinks
|
|
543
|
-
|
|
544
|
-
```typescript
|
|
545
|
-
// Get all files in a bucket
|
|
546
|
-
const files = await fileMetaLinkRepository.find({
|
|
547
|
-
where: { bucketName: 'user-uploads' },
|
|
548
|
-
});
|
|
549
|
-
|
|
550
|
-
// Get files by mimetype
|
|
551
|
-
const pdfs = await fileMetaLinkRepository.find({
|
|
552
|
-
where: { mimetype: 'application/pdf' },
|
|
553
|
-
});
|
|
554
|
-
|
|
555
|
-
// Get files by storage type
|
|
556
|
-
const minioFiles = await fileMetaLinkRepository.find({
|
|
557
|
-
where: { storageType: 'minio' },
|
|
558
|
-
});
|
|
559
|
-
|
|
560
|
-
// Get files by principal
|
|
561
|
-
const userFiles = await fileMetaLinkRepository.find({
|
|
562
|
-
where: { principalType: 'user', principalId: '42' },
|
|
563
|
-
});
|
|
564
|
-
|
|
565
|
-
// Get files by variant
|
|
566
|
-
const thumbnails = await fileMetaLinkRepository.find({
|
|
567
|
-
where: { variant: 'thumbnail' },
|
|
568
|
-
});
|
|
569
|
-
|
|
570
|
-
// Get synced files only
|
|
571
|
-
const syncedFiles = await fileMetaLinkRepository.find({
|
|
572
|
-
where: { isSynced: true },
|
|
573
|
-
});
|
|
574
|
-
```
|
|
575
|
-
|
|
576
|
-
### Quick Start Options
|
|
123
|
+
See [Enable MetaLink tracking](./usage#enable-metalink-tracking) for the full repository/table/binding setup.
|
|
577
124
|
|
|
578
|
-
|
|
579
|
-
```typescript
|
|
580
|
-
import {
|
|
581
|
-
StaticAssetComponent,
|
|
582
|
-
StaticAssetComponentBindingKeys,
|
|
583
|
-
StaticAssetStorageTypes,
|
|
584
|
-
} from '@venizia/ignis/static-asset';
|
|
585
|
-
|
|
586
|
-
this.bind({
|
|
587
|
-
key: StaticAssetComponentBindingKeys.STATIC_ASSET_COMPONENT_OPTIONS,
|
|
588
|
-
}).toValue({
|
|
589
|
-
cloudStorage: {
|
|
590
|
-
controller: { name: 'CloudController', basePath: '/cloud' },
|
|
591
|
-
storage: StaticAssetStorageTypes.MINIO,
|
|
592
|
-
helper: new MinioHelper({ /* ... */ }),
|
|
593
|
-
extra: { parseMultipartBody: { storage: 'memory' } },
|
|
594
|
-
},
|
|
595
|
-
});
|
|
596
|
-
this.component(StaticAssetComponent);
|
|
597
|
-
```
|
|
125
|
+
### Customize object names and links
|
|
598
126
|
|
|
599
|
-
|
|
600
|
-
```typescript
|
|
601
|
-
this.bind({
|
|
602
|
-
key: StaticAssetComponentBindingKeys.STATIC_ASSET_COMPONENT_OPTIONS,
|
|
603
|
-
}).toValue({
|
|
604
|
-
localStorage: {
|
|
605
|
-
controller: { name: 'LocalController', basePath: '/files' },
|
|
606
|
-
storage: StaticAssetStorageTypes.DISK,
|
|
607
|
-
helper: new DiskHelper({ basePath: './uploads' }),
|
|
608
|
-
extra: { parseMultipartBody: { storage: 'disk' } },
|
|
609
|
-
},
|
|
610
|
-
});
|
|
611
|
-
this.component(StaticAssetComponent);
|
|
612
|
-
```
|
|
127
|
+
`normalizeNameFn` runs before the file is written to storage; `normalizeLinkFn` builds the `link` value returned to the client. Both are optional - omit either to keep the component's defaults.
|
|
613
128
|
|
|
614
|
-
**Option 3: Multiple Storage Backends (Recommended)**
|
|
615
129
|
```typescript
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
}).
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
helper: new MinioHelper({ /* ... */ }),
|
|
623
|
-
extra: {},
|
|
624
|
-
},
|
|
625
|
-
tempFiles: {
|
|
626
|
-
controller: { name: 'TempController', basePath: '/temp' },
|
|
627
|
-
storage: StaticAssetStorageTypes.DISK,
|
|
628
|
-
helper: new DiskHelper({ basePath: './temp' }),
|
|
629
|
-
extra: {},
|
|
630
|
-
},
|
|
631
|
-
publicAssets: {
|
|
632
|
-
controller: { name: 'PublicController', basePath: '/public' },
|
|
633
|
-
storage: StaticAssetStorageTypes.DISK,
|
|
634
|
-
helper: new DiskHelper({ basePath: './public' }),
|
|
635
|
-
extra: {},
|
|
636
|
-
},
|
|
637
|
-
});
|
|
638
|
-
this.component(StaticAssetComponent);
|
|
639
|
-
```
|
|
640
|
-
|
|
641
|
-
### Custom Filename Normalization
|
|
642
|
-
|
|
643
|
-
```typescript
|
|
644
|
-
{
|
|
645
|
-
uploads: {
|
|
646
|
-
controller: { name: 'UploadController', basePath: '/uploads' },
|
|
647
|
-
storage: StaticAssetStorageTypes.MINIO,
|
|
648
|
-
helper: new MinioHelper({ /* ... */ }),
|
|
649
|
-
extra: {
|
|
650
|
-
parseMultipartBody: { storage: 'memory' },
|
|
651
|
-
normalizeNameFn: ({ originalName }) => {
|
|
652
|
-
return `${Date.now()}_${originalName.toLowerCase().replace(/\s/g, '_')}`;
|
|
653
|
-
},
|
|
654
|
-
normalizeLinkFn: ({ bucketName, normalizeName }) => {
|
|
655
|
-
return `/api/files/${bucketName}/${encodeURIComponent(normalizeName)}`;
|
|
656
|
-
},
|
|
657
|
-
},
|
|
658
|
-
},
|
|
659
|
-
}
|
|
130
|
+
extra: {
|
|
131
|
+
normalizeNameFn: ({ originalName, folderPath }) =>
|
|
132
|
+
`${Date.now()}_${originalName.toLowerCase().replace(/\s/g, '_')}`,
|
|
133
|
+
normalizeLinkFn: ({ bucketName, normalizeName }) =>
|
|
134
|
+
`/api/files/${bucketName}/${encodeURIComponent(normalizeName)}`,
|
|
135
|
+
},
|
|
660
136
|
```
|
|
661
137
|
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
## Binding Keys
|
|
665
|
-
|
|
666
|
-
| Key | Constant | Type | Required | Default |
|
|
667
|
-
|-----|----------|------|----------|---------|
|
|
668
|
-
| `@app/static-asset-component/options` | `StaticAssetComponentBindingKeys.STATIC_ASSET_COMPONENT_OPTIONS` | `TStaticAssetsComponentOptions` | Yes | `{}` |
|
|
138
|
+
## See also
|
|
669
139
|
|
|
670
|
-
|
|
671
|
-
|
|
140
|
+
- [Usage & Examples](./usage) - task-oriented walkthroughs for every endpoint and MetaLink setup
|
|
141
|
+
- [Full Reference](./api) - controller factory, `IStorageHelper` interface, MetaLink schema, internals
|
|
142
|
+
- [Error Reference](./errors) - name validation rules and troubleshooting
|
|
143
|
+
- [Storage Helpers](/extensions/helpers/storage/) - `DiskHelper`, `MinioHelper`, `BaseStorageHelper` reference
|
|
144
|
+
- [Components Overview](/guides/core-concepts/components) - component system basics
|
|
672
145
|
|
|
673
|
-
|
|
146
|
+
**Files:**
|
|
674
147
|
|
|
675
|
-
- [
|
|
676
|
-
- [
|
|
677
|
-
- [
|
|
678
|
-
- [
|
|
679
|
-
- [
|
|
680
|
-
- [
|
|
681
|
-
- [Components Overview](/guides/core-concepts/components) - Component system basics
|
|
682
|
-
- [Controllers](/guides/core-concepts/rest-controllers) - File upload endpoints
|
|
148
|
+
- [`packages/core/src/components/static-asset/component.ts`](https://github.com/VENIZIA-AI/ignis/blob/main/packages/core/src/components/static-asset/component.ts) - `StaticAssetComponent`
|
|
149
|
+
- [`packages/core/src/components/static-asset/common/types.ts`](https://github.com/VENIZIA-AI/ignis/blob/main/packages/core/src/components/static-asset/common/types.ts) - `TStaticAssetsComponentOptions`, `TStaticAssetExtraOptions`, `TMetaLinkConfig`
|
|
150
|
+
- [`packages/core/src/components/static-asset/common/constants.ts`](https://github.com/VENIZIA-AI/ignis/blob/main/packages/core/src/components/static-asset/common/constants.ts) - `StaticAssetStorageTypes`
|
|
151
|
+
- [`packages/core/src/components/static-asset/controller/factory.ts`](https://github.com/VENIZIA-AI/ignis/blob/main/packages/core/src/components/static-asset/controller/factory.ts) - `AssetControllerFactory`
|
|
152
|
+
- [`packages/core/src/components/static-asset/models/base.model.ts`](https://github.com/VENIZIA-AI/ignis/blob/main/packages/core/src/components/static-asset/models/base.model.ts) - `BaseMetaLinkModel`
|
|
153
|
+
- [`packages/helpers/src/modules/storage/base.ts`](https://github.com/VENIZIA-AI/ignis/blob/main/packages/helpers/src/modules/storage/base.ts) - `BaseStorageHelper`, `IStorageHelper`
|