streamby-core 0.9.14 → 0.9.16
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/adapters/s3.js +27 -17
- package/dist/types/index.d.ts +1 -1
- package/package.json +1 -1
package/dist/adapters/s3.js
CHANGED
|
@@ -18,8 +18,8 @@ function createS3Adapter(config) {
|
|
|
18
18
|
return {
|
|
19
19
|
async getPresignedUrl(filename, contentType, projectId) {
|
|
20
20
|
const salt = await bcrypt_1.default.genSalt();
|
|
21
|
-
const
|
|
22
|
-
const key = `${projectId}/${contentType}/file-${Date.now()}-${
|
|
21
|
+
const hashed = await bcrypt_1.default.hash(filename, salt);
|
|
22
|
+
const key = `${projectId}/${contentType}/file-${Date.now()}-${hashed.replace(/\//g, '-')}`;
|
|
23
23
|
const command = new client_s3_1.PutObjectCommand({
|
|
24
24
|
Bucket: config.bucket,
|
|
25
25
|
Key: key,
|
|
@@ -38,20 +38,30 @@ function createS3Adapter(config) {
|
|
|
38
38
|
return result.Contents || [];
|
|
39
39
|
},
|
|
40
40
|
async deleteProjectDirectory(projectId) {
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
41
|
+
const prefix = `${projectId}/`;
|
|
42
|
+
let continuationToken = undefined;
|
|
43
|
+
while (true) {
|
|
44
|
+
const listCommand = new client_s3_1.ListObjectsV2Command({
|
|
45
|
+
Bucket: config.bucket,
|
|
46
|
+
Prefix: prefix,
|
|
47
|
+
ContinuationToken: continuationToken
|
|
48
|
+
});
|
|
49
|
+
const listedObjects = await s3.send(listCommand);
|
|
50
|
+
const contents = listedObjects.Contents || [];
|
|
51
|
+
if (contents.length > 0) {
|
|
52
|
+
const objectsToDelete = contents.map((item) => ({
|
|
53
|
+
Key: item.Key
|
|
54
|
+
}));
|
|
55
|
+
const deleteCommand = new client_s3_1.DeleteObjectsCommand({
|
|
56
|
+
Bucket: config.bucket,
|
|
57
|
+
Delete: { Objects: objectsToDelete },
|
|
58
|
+
});
|
|
59
|
+
await s3.send(deleteCommand);
|
|
60
|
+
}
|
|
61
|
+
if (!listedObjects.IsTruncated)
|
|
62
|
+
break;
|
|
63
|
+
continuationToken = listedObjects.NextContinuationToken;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
56
66
|
};
|
|
57
67
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export type StorageProviderType = 's3';
|
|
|
10
10
|
export interface StorageAdapter {
|
|
11
11
|
listFiles(projectId: string): Promise<any[]>;
|
|
12
12
|
getPresignedUrl?: (filename: string, contentType: string, projectId: string) => Promise<any>;
|
|
13
|
-
deleteProjectDirectory: (projectId: string) => Promise<
|
|
13
|
+
deleteProjectDirectory: (projectId: string) => Promise<any>;
|
|
14
14
|
}
|
|
15
15
|
export interface ProjectInfo {
|
|
16
16
|
id: string;
|