@usegraft/assets 1.0.0-beta.0 → 1.0.0-beta.2
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/dist/index.js +7 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -41,6 +41,11 @@ function defaultKeyFor(file) {
|
|
|
41
41
|
|
|
42
42
|
// src/storage.ts
|
|
43
43
|
import { AwsClient } from "aws4fetch";
|
|
44
|
+
function withoutTrailingSlashes(value) {
|
|
45
|
+
let end = value.length;
|
|
46
|
+
while (end > 0 && value.charCodeAt(end - 1) === 47) end -= 1;
|
|
47
|
+
return value.slice(0, end);
|
|
48
|
+
}
|
|
44
49
|
function createStorage(config = storageConfigFromEnv()) {
|
|
45
50
|
const aws = new AwsClient({
|
|
46
51
|
accessKeyId: config.accessKeyId,
|
|
@@ -48,7 +53,7 @@ function createStorage(config = storageConfigFromEnv()) {
|
|
|
48
53
|
region: config.region,
|
|
49
54
|
service: "s3"
|
|
50
55
|
});
|
|
51
|
-
const base = `${config.endpoint
|
|
56
|
+
const base = `${withoutTrailingSlashes(config.endpoint)}/${config.bucket}`;
|
|
52
57
|
const urlFor = (key) => `${base}/${key.split("/").map(encodeURIComponent).join("/")}`;
|
|
53
58
|
const presign = async (key, method, options) => {
|
|
54
59
|
const url = new URL(urlFor(key));
|
|
@@ -86,7 +91,7 @@ function createStorage(config = storageConfigFromEnv()) {
|
|
|
86
91
|
},
|
|
87
92
|
async url(key, options = {}) {
|
|
88
93
|
if (config.publicBaseUrl) {
|
|
89
|
-
const publicBase = config.publicBaseUrl
|
|
94
|
+
const publicBase = withoutTrailingSlashes(config.publicBaseUrl);
|
|
90
95
|
return `${publicBase}/${key.split("/").map(encodeURIComponent).join("/")}`;
|
|
91
96
|
}
|
|
92
97
|
return presign(key, "GET", options);
|