@datrix/api-upload 0.1.0 → 0.2.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 +21 -2
- package/dist/index.js +335 -292
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +331 -288
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -8
package/README.md
CHANGED
|
@@ -41,6 +41,20 @@ The plugin automatically registers a `media` schema and exposes `/api/upload` en
|
|
|
41
41
|
|
|
42
42
|
`GET` requests fall through to the standard CRUD handler — filtering, pagination, and populate work out of the box.
|
|
43
43
|
|
|
44
|
+
Notes:
|
|
45
|
+
|
|
46
|
+
- One file per request — multiple `file` entries in the form data are rejected with `400`.
|
|
47
|
+
- `PATCH`/`PUT` are not supported: media records are immutable over HTTP. Re-upload and delete instead.
|
|
48
|
+
- `DELETE` removes the database record first, then deletes storage objects best-effort — a failed storage delete is logged, never blocks the request.
|
|
49
|
+
|
|
50
|
+
## Permissions
|
|
51
|
+
|
|
52
|
+
When auth is enabled on `ApiPlugin`, the upload endpoints are gated **before** the handler runs:
|
|
53
|
+
|
|
54
|
+
- `POST /api/upload` evaluates `permission.create`, `DELETE /api/upload/:id` evaluates `permission.delete` (from `UploadOptions.permission`).
|
|
55
|
+
- With no explicit value, writes require an authenticated user; `read` stays open (the API-wide default).
|
|
56
|
+
- Direct CRUD writes to the media model (`POST`/`PATCH /api/media`) are **denied by default** — the upload pipeline is the only write path. Override via `permission.create` / `permission.update` only if you know what you are doing (records written this way bypass storage handling).
|
|
57
|
+
|
|
44
58
|
## Storage providers
|
|
45
59
|
|
|
46
60
|
### Local
|
|
@@ -67,8 +81,10 @@ new S3StorageProvider({
|
|
|
67
81
|
region: "us-east-1",
|
|
68
82
|
accessKeyId: "...",
|
|
69
83
|
secretAccessKey: "...",
|
|
70
|
-
endpoint: "
|
|
71
|
-
pathPrefix: "uploads
|
|
84
|
+
endpoint: "abc.r2.cloudflarestorage.com", // optional — custom host for R2 / MinIO (no protocol)
|
|
85
|
+
pathPrefix: "uploads", // optional key prefix
|
|
86
|
+
sessionToken: "...", // optional — STS temporary credentials
|
|
87
|
+
forcePathStyle: true, // optional — path-style addressing (MinIO / localstack)
|
|
72
88
|
})
|
|
73
89
|
```
|
|
74
90
|
|
|
@@ -135,6 +151,9 @@ new Upload({
|
|
|
135
151
|
})
|
|
136
152
|
```
|
|
137
153
|
|
|
154
|
+
- Oversized requests are rejected from the `Content-Length` header (`413`) before the body is buffered. A hard streaming limit should still be enforced at the server/proxy level.
|
|
155
|
+
- Files declared with an `image/*` MIME type are verified against their actual content (via sharp) — e.g. HTML uploaded as `image/png` is rejected with `400`. Non-image MIME types are stored as declared; serve local uploads with `X-Content-Type-Options: nosniff`.
|
|
156
|
+
|
|
138
157
|
## Media schema
|
|
139
158
|
|
|
140
159
|
`ApiPlugin` automatically registers a `media` schema with the following fields:
|