@studiocms/s3-storage 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/dist/s3-storage-manager.js +25 -0
- package/package.json +8 -8
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
} from "@aws-sdk/client-s3";
|
|
9
9
|
import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
|
|
10
10
|
import { Config, ConfigProvider, Effect, Redacted } from "effect";
|
|
11
|
+
const s3SafeNameRegex = /^[a-zA-Z0-9._-]+(?:\/[a-zA-Z0-9._-]+)*$/;
|
|
11
12
|
const s3ClientBuilder = Effect.gen(function* () {
|
|
12
13
|
const [
|
|
13
14
|
// With default values for optional config
|
|
@@ -113,6 +114,14 @@ class S3ApiService {
|
|
|
113
114
|
};
|
|
114
115
|
}
|
|
115
116
|
case "upload": {
|
|
117
|
+
if (!s3SafeNameRegex.test(jsonBody.key)) {
|
|
118
|
+
return {
|
|
119
|
+
data: {
|
|
120
|
+
error: "Invalid key format. Only alphanumeric characters and . _ - / are allowed."
|
|
121
|
+
},
|
|
122
|
+
status: 400
|
|
123
|
+
};
|
|
124
|
+
}
|
|
116
125
|
const command = new PutObjectCommand({
|
|
117
126
|
Bucket: BUCKET_NAME,
|
|
118
127
|
Key: jsonBody.key,
|
|
@@ -148,6 +157,14 @@ class S3ApiService {
|
|
|
148
157
|
if (!jsonBody.newKey) {
|
|
149
158
|
return { data: { error: "newKey is required for rename action" }, status: 400 };
|
|
150
159
|
}
|
|
160
|
+
if (!s3SafeNameRegex.test(jsonBody.newKey)) {
|
|
161
|
+
return {
|
|
162
|
+
data: {
|
|
163
|
+
error: "Invalid key format. Only alphanumeric characters and . _ - / are allowed."
|
|
164
|
+
},
|
|
165
|
+
status: 400
|
|
166
|
+
};
|
|
167
|
+
}
|
|
151
168
|
const copyCommand = new CopyObjectCommand({
|
|
152
169
|
Bucket: BUCKET_NAME,
|
|
153
170
|
CopySource: `${BUCKET_NAME}/${jsonBody.key}`,
|
|
@@ -225,6 +242,14 @@ class S3ApiService {
|
|
|
225
242
|
if (!key) {
|
|
226
243
|
return { data: { error: "Missing x-storage-key header" }, status: 400 };
|
|
227
244
|
}
|
|
245
|
+
if (!s3SafeNameRegex.test(key)) {
|
|
246
|
+
return {
|
|
247
|
+
data: {
|
|
248
|
+
error: "Invalid key format. Only alphanumeric characters and . _ - / are allowed."
|
|
249
|
+
},
|
|
250
|
+
status: 400
|
|
251
|
+
};
|
|
252
|
+
}
|
|
228
253
|
const fileData = await getArrayBuffer();
|
|
229
254
|
const command = new PutObjectCommand({
|
|
230
255
|
Bucket: BUCKET_NAME,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@studiocms/s3-storage",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Add S3 Storage Support into your StudioCMS project.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "withstudiocms",
|
|
@@ -46,18 +46,18 @@
|
|
|
46
46
|
},
|
|
47
47
|
"type": "module",
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@aws-sdk/client-s3": "^3.
|
|
50
|
-
"@aws-sdk/s3-request-presigner": "^3.
|
|
49
|
+
"@aws-sdk/client-s3": "^3.970.0",
|
|
50
|
+
"@aws-sdk/s3-request-presigner": "^3.970.0",
|
|
51
51
|
"astro-integration-kit": "^0.19.1"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@types/node": "^22.0.0"
|
|
55
|
-
},
|
|
56
|
-
"peerDependencies": {
|
|
54
|
+
"@types/node": "^22.0.0",
|
|
57
55
|
"astro": "^5.12.9",
|
|
58
|
-
"effect": "^3.19.14",
|
|
59
56
|
"vite": "^6.3.4",
|
|
60
|
-
"studiocms": "0.
|
|
57
|
+
"studiocms": "^0.2.0"
|
|
58
|
+
},
|
|
59
|
+
"peerDependencies": {
|
|
60
|
+
"effect": "^3.19.14"
|
|
61
61
|
},
|
|
62
62
|
"scripts": {
|
|
63
63
|
"build": "buildkit build 'src/**/*.{ts,astro,css,json,png}'",
|