@byline/storage-s3 2.2.7 → 2.2.8
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.
|
@@ -73,7 +73,7 @@ export interface S3StorageConfig {
|
|
|
73
73
|
* uploads compute their key from the original's `storagePath`, which
|
|
74
74
|
* already carries the prefix.
|
|
75
75
|
*
|
|
76
|
-
* @example `'byline'` → keys stored as `byline/<collection>/<
|
|
76
|
+
* @example `'byline'` → keys stored as `byline/<collection>/<uuid>-<filename>`
|
|
77
77
|
*/
|
|
78
78
|
pathPrefix?: string;
|
|
79
79
|
/**
|
|
@@ -122,7 +122,7 @@ export interface S3StorageConfig {
|
|
|
122
122
|
* `forcePathStyle: true` for non-AWS providers.
|
|
123
123
|
*
|
|
124
124
|
* Uploaded files are stored at:
|
|
125
|
-
* `[pathPrefix/]<collection>/<
|
|
125
|
+
* `[pathPrefix/]<collection>/<uuid>-<filename>`
|
|
126
126
|
*
|
|
127
127
|
* Image variants (thumbnail / card / etc.) are written as siblings of the
|
|
128
128
|
* original under the same prefix, e.g.:
|
|
@@ -23,14 +23,20 @@ function sanitiseFilename(filename) {
|
|
|
23
23
|
.replace(/^-|-$/g, '');
|
|
24
24
|
return `${safe || 'file'}${ext.toLowerCase()}`;
|
|
25
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Build a namespaced object key, e.g.:
|
|
28
|
+
* `[pathPrefix/]media/a1b2c3d4-e5f6-...-photo.jpg`
|
|
29
|
+
*
|
|
30
|
+
* The UUIDv4 prefix is sufficient to prevent filename collisions without
|
|
31
|
+
* year/month directory nesting, and it simplifies variant path derivation
|
|
32
|
+
* and cleanup on deletion. The high-entropy UUID prefix also gives S3
|
|
33
|
+
* enough scatter to auto-scale per prefix without a hot-partition concern.
|
|
34
|
+
*/
|
|
26
35
|
function buildObjectKey(pathPrefix, collection, filename) {
|
|
27
|
-
const now = new Date();
|
|
28
|
-
const year = now.getUTCFullYear();
|
|
29
|
-
const month = String(now.getUTCMonth() + 1).padStart(2, '0');
|
|
30
36
|
const uid = uuidv4();
|
|
31
37
|
const safe = sanitiseFilename(filename);
|
|
32
38
|
const scope = collection ?? 'uploads';
|
|
33
|
-
const key = `${scope}/${
|
|
39
|
+
const key = `${scope}/${uid}-${safe}`;
|
|
34
40
|
return pathPrefix ? `${pathPrefix}/${key}` : key;
|
|
35
41
|
}
|
|
36
42
|
function toReadable(stream) {
|
|
@@ -137,7 +143,7 @@ class S3StorageProvider {
|
|
|
137
143
|
* `forcePathStyle: true` for non-AWS providers.
|
|
138
144
|
*
|
|
139
145
|
* Uploaded files are stored at:
|
|
140
|
-
* `[pathPrefix/]<collection>/<
|
|
146
|
+
* `[pathPrefix/]<collection>/<uuid>-<filename>`
|
|
141
147
|
*
|
|
142
148
|
* Image variants (thumbnail / card / etc.) are written as siblings of the
|
|
143
149
|
* original under the same prefix, e.g.:
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@byline/storage-s3",
|
|
3
3
|
"private": false,
|
|
4
4
|
"license": "MPL-2.0",
|
|
5
|
-
"version": "2.2.
|
|
5
|
+
"version": "2.2.8",
|
|
6
6
|
"engines": {
|
|
7
7
|
"node": ">=20.9.0"
|
|
8
8
|
},
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"@aws-sdk/lib-storage": "^3.1045.0",
|
|
44
44
|
"npm-run-all": "^4.1.5",
|
|
45
45
|
"uuid": "^14.0.0",
|
|
46
|
-
"@byline/core": "2.2.
|
|
46
|
+
"@byline/core": "2.2.8"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@biomejs/biome": "2.4.15",
|