@adminforth/upload 1.0.11 → 1.0.13
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/custom/uploader.vue +2 -2
- package/dist/custom/uploader.vue +2 -2
- package/dist/index.js +63 -43
- package/index.ts +71 -44
- package/package.json +4 -3
package/custom/uploader.vue
CHANGED
|
@@ -171,7 +171,7 @@ const onFileChange = async (e) => {
|
|
|
171
171
|
reader.readAsDataURL(file);
|
|
172
172
|
}
|
|
173
173
|
|
|
174
|
-
const { uploadUrl, s3Path } = await callAdminForthApi({
|
|
174
|
+
const { uploadUrl, tagline, s3Path } = await callAdminForthApi({
|
|
175
175
|
path: `/plugin/${props.meta.pluginInstanceId}/get_s3_upload_url`,
|
|
176
176
|
method: 'POST',
|
|
177
177
|
body: {
|
|
@@ -196,7 +196,7 @@ const onFileChange = async (e) => {
|
|
|
196
196
|
});
|
|
197
197
|
xhr.open('PUT', uploadUrl, true);
|
|
198
198
|
xhr.setRequestHeader('Content-Type', type);
|
|
199
|
-
xhr.setRequestHeader('x-amz-tagging',
|
|
199
|
+
xhr.setRequestHeader('x-amz-tagging', tagline);
|
|
200
200
|
xhr.send(file);
|
|
201
201
|
});
|
|
202
202
|
if (!success) {
|
package/dist/custom/uploader.vue
CHANGED
|
@@ -171,7 +171,7 @@ const onFileChange = async (e) => {
|
|
|
171
171
|
reader.readAsDataURL(file);
|
|
172
172
|
}
|
|
173
173
|
|
|
174
|
-
const { uploadUrl, s3Path } = await callAdminForthApi({
|
|
174
|
+
const { uploadUrl, tagline, s3Path } = await callAdminForthApi({
|
|
175
175
|
path: `/plugin/${props.meta.pluginInstanceId}/get_s3_upload_url`,
|
|
176
176
|
method: 'POST',
|
|
177
177
|
body: {
|
|
@@ -196,7 +196,7 @@ const onFileChange = async (e) => {
|
|
|
196
196
|
});
|
|
197
197
|
xhr.open('PUT', uploadUrl, true);
|
|
198
198
|
xhr.setRequestHeader('Content-Type', type);
|
|
199
|
-
xhr.setRequestHeader('x-amz-tagging',
|
|
199
|
+
xhr.setRequestHeader('x-amz-tagging', tagline);
|
|
200
200
|
xhr.send(file);
|
|
201
201
|
});
|
|
202
202
|
if (!success) {
|
package/dist/index.js
CHANGED
|
@@ -7,7 +7,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import
|
|
10
|
+
import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
|
|
11
|
+
import { ExpirationStatus, GetObjectCommand, PutObjectCommand, S3 } from '@aws-sdk/client-s3';
|
|
11
12
|
import { AdminForthPlugin, AdminForthResourcePages } from "adminforth";
|
|
12
13
|
const ADMINFORTH_NOT_YET_USED_TAG = 'adminforth-candidate-for-cleanup';
|
|
13
14
|
export default class UploadPlugin extends AdminForthPlugin {
|
|
@@ -22,24 +23,26 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
22
23
|
return __awaiter(this, void 0, void 0, function* () {
|
|
23
24
|
// check that lifecyle rule "adminforth-unused-cleaner" exists
|
|
24
25
|
const CLEANUP_RULE_ID = 'adminforth-unused-cleaner';
|
|
25
|
-
const s3 = new
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
const s3 = new S3({
|
|
27
|
+
credentials: {
|
|
28
|
+
accessKeyId: this.options.s3AccessKeyId,
|
|
29
|
+
secretAccessKey: this.options.s3SecretAccessKey,
|
|
30
|
+
},
|
|
31
|
+
region: this.options.s3Region,
|
|
29
32
|
});
|
|
30
33
|
// check bucket exists
|
|
31
|
-
const bucketExists = s3.headBucket({ Bucket: this.options.s3Bucket })
|
|
34
|
+
const bucketExists = s3.headBucket({ Bucket: this.options.s3Bucket });
|
|
32
35
|
if (!bucketExists) {
|
|
33
36
|
throw new Error(`Bucket ${this.options.s3Bucket} does not exist`);
|
|
34
37
|
}
|
|
35
38
|
// check that lifecycle rule exists
|
|
36
39
|
let ruleExists = false;
|
|
37
40
|
try {
|
|
38
|
-
const lifecycleConfig = yield s3.getBucketLifecycleConfiguration({ Bucket: this.options.s3Bucket })
|
|
41
|
+
const lifecycleConfig = yield s3.getBucketLifecycleConfiguration({ Bucket: this.options.s3Bucket });
|
|
39
42
|
ruleExists = lifecycleConfig.Rules.some((rule) => rule.ID === CLEANUP_RULE_ID);
|
|
40
43
|
}
|
|
41
44
|
catch (e) {
|
|
42
|
-
if (e.
|
|
45
|
+
if (e.name !== 'NoSuchLifecycleConfiguration') {
|
|
43
46
|
throw e;
|
|
44
47
|
}
|
|
45
48
|
else {
|
|
@@ -55,7 +58,7 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
55
58
|
Rules: [
|
|
56
59
|
{
|
|
57
60
|
ID: CLEANUP_RULE_ID,
|
|
58
|
-
Status:
|
|
61
|
+
Status: ExpirationStatus.Enabled,
|
|
59
62
|
Filter: {
|
|
60
63
|
Tag: {
|
|
61
64
|
Key: ADMINFORTH_NOT_YET_USED_TAG,
|
|
@@ -69,7 +72,7 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
69
72
|
]
|
|
70
73
|
}
|
|
71
74
|
};
|
|
72
|
-
yield s3.putBucketLifecycleConfiguration(params)
|
|
75
|
+
yield s3.putBucketLifecycleConfiguration(params);
|
|
73
76
|
}
|
|
74
77
|
});
|
|
75
78
|
}
|
|
@@ -80,10 +83,10 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
80
83
|
record[`previewUrl_${this.pluginInstanceId}`] = this.options.preview.previewUrl({ s3Path: record[this.options.pathColumnName] });
|
|
81
84
|
return;
|
|
82
85
|
}
|
|
83
|
-
const previewUrl = yield
|
|
86
|
+
const previewUrl = yield yield getSignedUrl(s3, new GetObjectCommand({
|
|
84
87
|
Bucket: this.options.s3Bucket,
|
|
85
88
|
Key: record[this.options.pathColumnName],
|
|
86
|
-
});
|
|
89
|
+
}));
|
|
87
90
|
record[`previewUrl_${this.pluginInstanceId}`] = previewUrl;
|
|
88
91
|
});
|
|
89
92
|
}
|
|
@@ -154,10 +157,12 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
154
157
|
// in afterSave hook, aremove tag adminforth-not-yet-used from the file
|
|
155
158
|
resourceConfig.hooks.create.afterSave.push((_e) => __awaiter(this, [_e], void 0, function* ({ record }) {
|
|
156
159
|
if (record[pathColumnName]) {
|
|
157
|
-
const s3 = new
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
160
|
+
const s3 = new S3({
|
|
161
|
+
credentials: {
|
|
162
|
+
accessKeyId: this.options.s3AccessKeyId,
|
|
163
|
+
secretAccessKey: this.options.s3SecretAccessKey,
|
|
164
|
+
},
|
|
165
|
+
region: this.options.s3Region,
|
|
161
166
|
});
|
|
162
167
|
yield s3.putObjectTagging({
|
|
163
168
|
Bucket: this.options.s3Bucket,
|
|
@@ -165,7 +170,7 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
165
170
|
Tagging: {
|
|
166
171
|
TagSet: []
|
|
167
172
|
}
|
|
168
|
-
})
|
|
173
|
+
});
|
|
169
174
|
}
|
|
170
175
|
return { ok: true };
|
|
171
176
|
}));
|
|
@@ -177,10 +182,12 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
177
182
|
return { ok: true };
|
|
178
183
|
}
|
|
179
184
|
if (record[pathColumnName]) {
|
|
180
|
-
const s3 = new
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
185
|
+
const s3 = new S3({
|
|
186
|
+
credentials: {
|
|
187
|
+
accessKeyId: this.options.s3AccessKeyId,
|
|
188
|
+
secretAccessKey: this.options.s3SecretAccessKey,
|
|
189
|
+
},
|
|
190
|
+
region: this.options.s3Region,
|
|
184
191
|
});
|
|
185
192
|
yield this.genPreviewUrl(record, s3);
|
|
186
193
|
}
|
|
@@ -189,10 +196,12 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
189
196
|
// ** HOOKS FOR LIST **//
|
|
190
197
|
if ((_c = this.options.preview) === null || _c === void 0 ? void 0 : _c.showInList) {
|
|
191
198
|
resourceConfig.hooks.list.afterDatasourceResponse.push((_g) => __awaiter(this, [_g], void 0, function* ({ response }) {
|
|
192
|
-
const s3 = new
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
199
|
+
const s3 = new S3({
|
|
200
|
+
credentials: {
|
|
201
|
+
accessKeyId: this.options.s3AccessKeyId,
|
|
202
|
+
secretAccessKey: this.options.s3SecretAccessKey,
|
|
203
|
+
},
|
|
204
|
+
region: this.options.s3Region,
|
|
196
205
|
});
|
|
197
206
|
yield Promise.all(response.map((record) => __awaiter(this, void 0, void 0, function* () {
|
|
198
207
|
if (record[this.options.pathColumnName]) {
|
|
@@ -206,10 +215,12 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
206
215
|
// add delete hook which sets tag adminforth-candidate-for-cleanup to true
|
|
207
216
|
resourceConfig.hooks.delete.afterSave.push((_h) => __awaiter(this, [_h], void 0, function* ({ record }) {
|
|
208
217
|
if (record[pathColumnName]) {
|
|
209
|
-
const s3 = new
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
218
|
+
const s3 = new S3({
|
|
219
|
+
credentials: {
|
|
220
|
+
accessKeyId: this.options.s3AccessKeyId,
|
|
221
|
+
secretAccessKey: this.options.s3SecretAccessKey,
|
|
222
|
+
},
|
|
223
|
+
region: this.options.s3Region,
|
|
213
224
|
});
|
|
214
225
|
yield s3.putObjectTagging({
|
|
215
226
|
Bucket: this.options.s3Bucket,
|
|
@@ -222,7 +233,7 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
222
233
|
}
|
|
223
234
|
]
|
|
224
235
|
}
|
|
225
|
-
})
|
|
236
|
+
});
|
|
226
237
|
}
|
|
227
238
|
return { ok: true };
|
|
228
239
|
}));
|
|
@@ -238,10 +249,12 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
238
249
|
// add edit postSave hook to delete old file and remove tag from new file
|
|
239
250
|
resourceConfig.hooks.edit.afterSave.push((_k) => __awaiter(this, [_k], void 0, function* ({ record, oldRecord }) {
|
|
240
251
|
if (record[virtualColumn.name] || record[virtualColumn.name] === null) {
|
|
241
|
-
const s3 = new
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
252
|
+
const s3 = new S3({
|
|
253
|
+
credentials: {
|
|
254
|
+
accessKeyId: this.options.s3AccessKeyId,
|
|
255
|
+
secretAccessKey: this.options.s3SecretAccessKey,
|
|
256
|
+
},
|
|
257
|
+
region: this.options.s3Region,
|
|
245
258
|
});
|
|
246
259
|
if (oldRecord[pathColumnName]) {
|
|
247
260
|
// put tag to delete old file
|
|
@@ -256,7 +269,7 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
256
269
|
}
|
|
257
270
|
]
|
|
258
271
|
}
|
|
259
|
-
})
|
|
272
|
+
});
|
|
260
273
|
}
|
|
261
274
|
if (record[virtualColumn.name] !== null) {
|
|
262
275
|
// remove tag from new file
|
|
@@ -266,7 +279,7 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
266
279
|
Tagging: {
|
|
267
280
|
TagSet: []
|
|
268
281
|
}
|
|
269
|
-
})
|
|
282
|
+
});
|
|
270
283
|
}
|
|
271
284
|
}
|
|
272
285
|
return { ok: true };
|
|
@@ -290,22 +303,29 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
290
303
|
if (s3Path.startsWith('/')) {
|
|
291
304
|
throw new Error('s3Path should not start with /, please adjust s3path function to not return / at the start of the path');
|
|
292
305
|
}
|
|
293
|
-
const s3 = new
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
306
|
+
const s3 = new S3({
|
|
307
|
+
credentials: {
|
|
308
|
+
accessKeyId: this.options.s3AccessKeyId,
|
|
309
|
+
secretAccessKey: this.options.s3SecretAccessKey,
|
|
310
|
+
},
|
|
311
|
+
region: this.options.s3Region,
|
|
297
312
|
});
|
|
313
|
+
const tagline = `${ADMINFORTH_NOT_YET_USED_TAG}=true`;
|
|
298
314
|
const params = {
|
|
299
315
|
Bucket: this.options.s3Bucket,
|
|
300
316
|
Key: s3Path,
|
|
301
317
|
ContentType: contentType,
|
|
302
|
-
ACL: this.options.s3ACL || 'private',
|
|
303
|
-
Tagging:
|
|
318
|
+
ACL: (this.options.s3ACL || 'private'),
|
|
319
|
+
Tagging: tagline,
|
|
304
320
|
};
|
|
305
|
-
const uploadUrl = yield
|
|
321
|
+
const uploadUrl = yield yield getSignedUrl(s3, new PutObjectCommand(params), {
|
|
322
|
+
expiresIn: 1800,
|
|
323
|
+
unhoistableHeaders: new Set(['x-amz-tagging']),
|
|
324
|
+
});
|
|
306
325
|
return {
|
|
307
326
|
uploadUrl,
|
|
308
327
|
s3Path,
|
|
328
|
+
tagline,
|
|
309
329
|
};
|
|
310
330
|
})
|
|
311
331
|
});
|
package/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
import { PluginOptions } from './types.js';
|
|
3
|
-
import
|
|
3
|
+
import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
|
|
4
|
+
import { ExpirationStatus, GetObjectCommand, ObjectCannedACL, PutObjectCommand, S3 } from '@aws-sdk/client-s3';
|
|
4
5
|
import { AdminForthPlugin, AdminForthResourceColumn, AdminForthResourcePages, IAdminForth, IHttpServer } from "adminforth";
|
|
5
6
|
|
|
6
7
|
const ADMINFORTH_NOT_YET_USED_TAG = 'adminforth-candidate-for-cleanup';
|
|
@@ -20,13 +21,16 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
20
21
|
async setupLifecycleRule() {
|
|
21
22
|
// check that lifecyle rule "adminforth-unused-cleaner" exists
|
|
22
23
|
const CLEANUP_RULE_ID = 'adminforth-unused-cleaner';
|
|
23
|
-
const s3 = new
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
const s3 = new S3({
|
|
25
|
+
credentials: {
|
|
26
|
+
accessKeyId: this.options.s3AccessKeyId,
|
|
27
|
+
secretAccessKey: this.options.s3SecretAccessKey,
|
|
28
|
+
},
|
|
29
|
+
|
|
30
|
+
region: this.options.s3Region,
|
|
27
31
|
});
|
|
28
32
|
// check bucket exists
|
|
29
|
-
const bucketExists = s3.headBucket({ Bucket: this.options.s3Bucket })
|
|
33
|
+
const bucketExists = s3.headBucket({ Bucket: this.options.s3Bucket })
|
|
30
34
|
if (!bucketExists) {
|
|
31
35
|
throw new Error(`Bucket ${this.options.s3Bucket} does not exist`);
|
|
32
36
|
}
|
|
@@ -35,10 +39,10 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
35
39
|
let ruleExists: boolean = false;
|
|
36
40
|
|
|
37
41
|
try {
|
|
38
|
-
const lifecycleConfig: any = await s3.getBucketLifecycleConfiguration({ Bucket: this.options.s3Bucket })
|
|
42
|
+
const lifecycleConfig: any = await s3.getBucketLifecycleConfiguration({ Bucket: this.options.s3Bucket });
|
|
39
43
|
ruleExists = lifecycleConfig.Rules.some((rule: any) => rule.ID === CLEANUP_RULE_ID);
|
|
40
44
|
} catch (e: any) {
|
|
41
|
-
if (e.
|
|
45
|
+
if (e.name !== 'NoSuchLifecycleConfiguration') {
|
|
42
46
|
throw e;
|
|
43
47
|
} else {
|
|
44
48
|
ruleExists = false;
|
|
@@ -54,7 +58,7 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
54
58
|
Rules: [
|
|
55
59
|
{
|
|
56
60
|
ID: CLEANUP_RULE_ID,
|
|
57
|
-
Status:
|
|
61
|
+
Status: ExpirationStatus.Enabled,
|
|
58
62
|
Filter: {
|
|
59
63
|
Tag: {
|
|
60
64
|
Key: ADMINFORTH_NOT_YET_USED_TAG,
|
|
@@ -69,19 +73,19 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
69
73
|
}
|
|
70
74
|
};
|
|
71
75
|
|
|
72
|
-
await s3.putBucketLifecycleConfiguration(params)
|
|
76
|
+
await s3.putBucketLifecycleConfiguration(params);
|
|
73
77
|
}
|
|
74
78
|
}
|
|
75
79
|
|
|
76
|
-
async genPreviewUrl(record: any, s3:
|
|
80
|
+
async genPreviewUrl(record: any, s3: S3) {
|
|
77
81
|
if (this.options.preview?.previewUrl) {
|
|
78
82
|
record[`previewUrl_${this.pluginInstanceId}`] = this.options.preview.previewUrl({ s3Path: record[this.options.pathColumnName] });
|
|
79
83
|
return;
|
|
80
84
|
}
|
|
81
|
-
const previewUrl = await
|
|
85
|
+
const previewUrl = await await getSignedUrl(s3, new GetObjectCommand({
|
|
82
86
|
Bucket: this.options.s3Bucket,
|
|
83
87
|
Key: record[this.options.pathColumnName],
|
|
84
|
-
});
|
|
88
|
+
}));
|
|
85
89
|
|
|
86
90
|
record[`previewUrl_${this.pluginInstanceId}`] = previewUrl;
|
|
87
91
|
}
|
|
@@ -166,10 +170,13 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
166
170
|
// in afterSave hook, aremove tag adminforth-not-yet-used from the file
|
|
167
171
|
resourceConfig.hooks.create.afterSave.push(async ({ record }: { record: any }) => {
|
|
168
172
|
if (record[pathColumnName]) {
|
|
169
|
-
const s3 = new
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
+
const s3 = new S3({
|
|
174
|
+
credentials: {
|
|
175
|
+
accessKeyId: this.options.s3AccessKeyId,
|
|
176
|
+
secretAccessKey: this.options.s3SecretAccessKey,
|
|
177
|
+
},
|
|
178
|
+
|
|
179
|
+
region: this.options.s3Region,
|
|
173
180
|
});
|
|
174
181
|
|
|
175
182
|
await s3.putObjectTagging({
|
|
@@ -178,7 +185,7 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
178
185
|
Tagging: {
|
|
179
186
|
TagSet: []
|
|
180
187
|
}
|
|
181
|
-
})
|
|
188
|
+
});
|
|
182
189
|
}
|
|
183
190
|
return { ok: true };
|
|
184
191
|
});
|
|
@@ -193,10 +200,13 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
193
200
|
return { ok: true };
|
|
194
201
|
}
|
|
195
202
|
if (record[pathColumnName]) {
|
|
196
|
-
const s3 = new
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
203
|
+
const s3 = new S3({
|
|
204
|
+
credentials: {
|
|
205
|
+
accessKeyId: this.options.s3AccessKeyId,
|
|
206
|
+
secretAccessKey: this.options.s3SecretAccessKey,
|
|
207
|
+
},
|
|
208
|
+
|
|
209
|
+
region: this.options.s3Region,
|
|
200
210
|
});
|
|
201
211
|
|
|
202
212
|
await this.genPreviewUrl(record, s3);
|
|
@@ -209,10 +219,13 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
209
219
|
|
|
210
220
|
if (this.options.preview?.showInList) {
|
|
211
221
|
resourceConfig.hooks.list.afterDatasourceResponse.push(async ({ response }: { response: any }) => {
|
|
212
|
-
const s3 = new
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
222
|
+
const s3 = new S3({
|
|
223
|
+
credentials: {
|
|
224
|
+
accessKeyId: this.options.s3AccessKeyId,
|
|
225
|
+
secretAccessKey: this.options.s3SecretAccessKey,
|
|
226
|
+
},
|
|
227
|
+
|
|
228
|
+
region: this.options.s3Region,
|
|
216
229
|
});
|
|
217
230
|
|
|
218
231
|
await Promise.all(response.map(async (record: any) => {
|
|
@@ -229,10 +242,13 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
229
242
|
// add delete hook which sets tag adminforth-candidate-for-cleanup to true
|
|
230
243
|
resourceConfig.hooks.delete.afterSave.push(async ({ record }: { record: any }) => {
|
|
231
244
|
if (record[pathColumnName]) {
|
|
232
|
-
const s3 = new
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
245
|
+
const s3 = new S3({
|
|
246
|
+
credentials: {
|
|
247
|
+
accessKeyId: this.options.s3AccessKeyId,
|
|
248
|
+
secretAccessKey: this.options.s3SecretAccessKey,
|
|
249
|
+
},
|
|
250
|
+
|
|
251
|
+
region: this.options.s3Region,
|
|
236
252
|
});
|
|
237
253
|
|
|
238
254
|
await s3.putObjectTagging({
|
|
@@ -246,7 +262,7 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
246
262
|
}
|
|
247
263
|
]
|
|
248
264
|
}
|
|
249
|
-
})
|
|
265
|
+
});
|
|
250
266
|
}
|
|
251
267
|
return { ok: true };
|
|
252
268
|
});
|
|
@@ -268,10 +284,13 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
268
284
|
resourceConfig.hooks.edit.afterSave.push(async ({ record, oldRecord }: { record: any, oldRecord: any }) => {
|
|
269
285
|
|
|
270
286
|
if (record[virtualColumn.name] || record[virtualColumn.name] === null) {
|
|
271
|
-
const s3 = new
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
287
|
+
const s3 = new S3({
|
|
288
|
+
credentials: {
|
|
289
|
+
accessKeyId: this.options.s3AccessKeyId,
|
|
290
|
+
secretAccessKey: this.options.s3SecretAccessKey,
|
|
291
|
+
},
|
|
292
|
+
|
|
293
|
+
region: this.options.s3Region,
|
|
275
294
|
});
|
|
276
295
|
|
|
277
296
|
if (oldRecord[pathColumnName]) {
|
|
@@ -287,7 +306,7 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
287
306
|
}
|
|
288
307
|
]
|
|
289
308
|
}
|
|
290
|
-
})
|
|
309
|
+
});
|
|
291
310
|
}
|
|
292
311
|
if (record[virtualColumn.name] !== null) {
|
|
293
312
|
// remove tag from new file
|
|
@@ -297,7 +316,7 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
297
316
|
Tagging: {
|
|
298
317
|
TagSet: []
|
|
299
318
|
}
|
|
300
|
-
})
|
|
319
|
+
});
|
|
301
320
|
}
|
|
302
321
|
}
|
|
303
322
|
return { ok: true };
|
|
@@ -326,26 +345,34 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
326
345
|
if (s3Path.startsWith('/')) {
|
|
327
346
|
throw new Error('s3Path should not start with /, please adjust s3path function to not return / at the start of the path');
|
|
328
347
|
}
|
|
329
|
-
const s3 = new
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
348
|
+
const s3 = new S3({
|
|
349
|
+
credentials: {
|
|
350
|
+
accessKeyId: this.options.s3AccessKeyId,
|
|
351
|
+
secretAccessKey: this.options.s3SecretAccessKey,
|
|
352
|
+
},
|
|
353
|
+
|
|
354
|
+
region: this.options.s3Region,
|
|
333
355
|
});
|
|
334
356
|
|
|
357
|
+
const tagline = `${ADMINFORTH_NOT_YET_USED_TAG}=true`;
|
|
335
358
|
const params = {
|
|
336
359
|
Bucket: this.options.s3Bucket,
|
|
337
360
|
Key: s3Path,
|
|
338
361
|
ContentType: contentType,
|
|
339
|
-
ACL: this.options.s3ACL || 'private',
|
|
340
|
-
Tagging:
|
|
362
|
+
ACL: (this.options.s3ACL || 'private') as ObjectCannedACL,
|
|
363
|
+
Tagging: tagline,
|
|
341
364
|
};
|
|
342
365
|
|
|
343
|
-
const uploadUrl = await
|
|
366
|
+
const uploadUrl = await await getSignedUrl(s3, new PutObjectCommand(params), {
|
|
367
|
+
expiresIn: 1800,
|
|
368
|
+
unhoistableHeaders: new Set(['x-amz-tagging']),
|
|
369
|
+
})
|
|
344
370
|
|
|
345
371
|
|
|
346
372
|
return {
|
|
347
373
|
uploadUrl,
|
|
348
374
|
s3Path,
|
|
375
|
+
tagline,
|
|
349
376
|
};
|
|
350
377
|
}
|
|
351
378
|
});
|
package/package.json
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adminforth/upload",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.13",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"rollout": "tsc && cp -rf custom dist/ && npm version patch && npm publish --access public",
|
|
9
|
-
"
|
|
9
|
+
"prepare": "npm link adminforth",
|
|
10
10
|
"build": "tsc"
|
|
11
11
|
},
|
|
12
12
|
"type": "module",
|
|
13
13
|
"author": "",
|
|
14
14
|
"license": "ISC",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"aws-sdk": "^
|
|
16
|
+
"@aws-sdk/client-s3": "^3.629.0",
|
|
17
|
+
"@aws-sdk/s3-request-presigner": "^3.629.0"
|
|
17
18
|
}
|
|
18
19
|
}
|