@easy-cms/storage-s3 0.40.0 → 0.42.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.
Files changed (2) hide show
  1. package/dist/index.js +20 -0
  2. package/package.json +4 -4
package/dist/index.js CHANGED
@@ -47,6 +47,26 @@ function s3Storage(options) {
47
47
  });
48
48
  if (!response.ok) throw await s3Error("PUT", key, response);
49
49
  },
50
+ // Large files from the browser: a presigned PUT (the bucket needs CORS for the admin's
51
+ // origin). The size is checked once the file is there.
52
+ async uploadURL(key, { contentType, expiresIn }) {
53
+ if (!client) throw new Error("s3Storage used before init()");
54
+ const url = new URL(objectURL(prefix + key));
55
+ url.searchParams.set("X-Amz-Expires", String(expiresIn));
56
+ const signed = await client.sign(url.toString(), { method: "PUT", aws: { signQuery: true } });
57
+ return { url: signed.url, method: "PUT", headers: { "content-type": contentType } };
58
+ },
59
+ async getStart(key, bytes) {
60
+ const response = await request(key, {
61
+ method: "GET",
62
+ headers: { range: `bytes=0-${bytes - 1}` }
63
+ });
64
+ if (response.status === 404) return null;
65
+ if (!response.ok) throw await s3Error("GET", key, response);
66
+ const body = new Uint8Array(await response.arrayBuffer());
67
+ const total = Number(response.headers.get("content-range")?.split("/")[1]);
68
+ return { body, size: Number.isFinite(total) && total > 0 ? total : body.byteLength };
69
+ },
50
70
  async get(key) {
51
71
  const response = await request(key, { method: "GET" });
52
72
  if (response.status === 404) return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easy-cms/storage-s3",
3
- "version": "0.40.0",
3
+ "version": "0.42.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.40.0"
22
+ "@easy-cms/core": "^0.42.0"
23
23
  },
24
24
  "devDependencies": {
25
25
  "sharp": "^0.35.4",
26
- "@easy-cms/core": "^0.40.0",
27
- "@easy-cms/db-sqlite": "^0.40.0"
26
+ "@easy-cms/db-sqlite": "^0.42.0",
27
+ "@easy-cms/core": "^0.42.0"
28
28
  },
29
29
  "engines": {
30
30
  "node": ">=22.12"