@easy-cms/storage-s3 0.47.4 → 0.49.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 +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +11 -3
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ export default defineConfig({
|
|
|
22
22
|
```
|
|
23
23
|
|
|
24
24
|
Credentials default to `AWS_ACCESS_KEY_ID` / `AWS_SECRET_ACCESS_KEY`. Files are served through the
|
|
25
|
-
CMS API (private bucket) unless you set `
|
|
25
|
+
CMS API (private bucket) unless you set `publicURL`.
|
|
26
26
|
|
|
27
27
|
## Links
|
|
28
28
|
|
package/dist/index.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ interface S3StorageOptions {
|
|
|
25
25
|
* When set, media URLs point there. When not set, files are served through the REST API
|
|
26
26
|
* (`<api>/media/file/<key>`), which works with private buckets.
|
|
27
27
|
*/
|
|
28
|
-
readonly
|
|
28
|
+
readonly publicURL?: string;
|
|
29
29
|
/**
|
|
30
30
|
* Address the bucket as `<endpoint>/<bucket>/<key>` instead of `<bucket>.<endpoint>/<key>`.
|
|
31
31
|
* Default: `true` when `endpoint` is set (MinIO needs it, R2 accepts it), otherwise `false`.
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
+
import { checkRenamedOptions } from "@easy-cms/core/internal";
|
|
2
3
|
import { AwsClient } from "aws4fetch";
|
|
3
4
|
function s3Storage(options) {
|
|
5
|
+
checkRenamedOptions("s3Storage", options, { publicUrl: "publicURL" });
|
|
4
6
|
const prefix = normalizePrefix(options.prefix);
|
|
5
7
|
let client;
|
|
6
8
|
let objectURL = () => {
|
|
@@ -13,6 +15,7 @@ function s3Storage(options) {
|
|
|
13
15
|
};
|
|
14
16
|
return {
|
|
15
17
|
name: "s3",
|
|
18
|
+
apiVersion: 1,
|
|
16
19
|
init() {
|
|
17
20
|
const env = process.env;
|
|
18
21
|
const accessKeyId = options.accessKeyId ?? env.AWS_ACCESS_KEY_ID;
|
|
@@ -65,7 +68,12 @@ function s3Storage(options) {
|
|
|
65
68
|
if (!response.ok) throw await s3Error("GET", key, response);
|
|
66
69
|
const body = new Uint8Array(await response.arrayBuffer());
|
|
67
70
|
const total = Number(response.headers.get("content-range")?.split("/")[1]);
|
|
68
|
-
|
|
71
|
+
const contentType = response.headers.get("content-type");
|
|
72
|
+
return {
|
|
73
|
+
body,
|
|
74
|
+
size: Number.isFinite(total) && total > 0 ? total : body.byteLength,
|
|
75
|
+
...contentType ? { contentType } : {}
|
|
76
|
+
};
|
|
69
77
|
},
|
|
70
78
|
async get(key) {
|
|
71
79
|
const response = await request(key, { method: "GET" });
|
|
@@ -79,8 +87,8 @@ function s3Storage(options) {
|
|
|
79
87
|
if (!response.ok && response.status !== 404) throw await s3Error("DELETE", key, response);
|
|
80
88
|
},
|
|
81
89
|
url(key) {
|
|
82
|
-
if (!options.
|
|
83
|
-
return `${options.
|
|
90
|
+
if (!options.publicURL) return void 0;
|
|
91
|
+
return `${options.publicURL.replace(/\/+$/, "")}/${encodeKey(prefix + key)}`;
|
|
84
92
|
}
|
|
85
93
|
};
|
|
86
94
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@easy-cms/storage-s3",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.49.0",
|
|
4
4
|
"description": "S3-compatible upload storage for Easy CMS: AWS S3, Cloudflare R2, MinIO",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -19,12 +19,12 @@
|
|
|
19
19
|
"aws4fetch": "^1.0.20"
|
|
20
20
|
},
|
|
21
21
|
"peerDependencies": {
|
|
22
|
-
"@easy-cms/core": "^0.
|
|
22
|
+
"@easy-cms/core": "^0.49.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"sharp": "^0.35.5",
|
|
26
|
-
"@easy-cms/core": "^0.
|
|
27
|
-
"@easy-cms/db-sqlite": "^0.
|
|
26
|
+
"@easy-cms/core": "^0.49.0",
|
|
27
|
+
"@easy-cms/db-sqlite": "^0.49.0"
|
|
28
28
|
},
|
|
29
29
|
"engines": {
|
|
30
30
|
"node": ">=22.12"
|