@directus/storage-driver-s3 10.0.4 → 10.0.6
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 +21 -9
- package/package.json +4 -3
package/dist/index.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { CopyObjectCommand, DeleteObjectCommand, GetObjectCommand, HeadObjectCommand, ListObjectsV2Command, S3Client, } from '@aws-sdk/client-s3';
|
|
2
2
|
import { Upload } from '@aws-sdk/lib-storage';
|
|
3
|
+
import { NodeHttpHandler } from '@aws-sdk/node-http-handler';
|
|
3
4
|
import { normalizePath } from '@directus/utils';
|
|
4
5
|
import { isReadableStream } from '@directus/utils/node';
|
|
6
|
+
import { Agent as HttpAgent } from 'node:http';
|
|
7
|
+
import { Agent as HttpsAgent } from 'node:https';
|
|
5
8
|
import { join } from 'node:path';
|
|
6
9
|
export class DriverS3 {
|
|
7
10
|
config;
|
|
@@ -13,7 +16,23 @@ export class DriverS3 {
|
|
|
13
16
|
this.root = this.config.root ? normalizePath(this.config.root, { removeLeading: true }) : '';
|
|
14
17
|
}
|
|
15
18
|
getClient() {
|
|
16
|
-
|
|
19
|
+
/*
|
|
20
|
+
* AWS' client default socket reusing can cause performance issues when using it very
|
|
21
|
+
* often in rapid succession, hitting the maxSockets limit of 50.
|
|
22
|
+
* The requestHandler is customized to get around this.
|
|
23
|
+
*/
|
|
24
|
+
const connectionTimeout = 5000;
|
|
25
|
+
const socketTimeout = 120000;
|
|
26
|
+
const maxSockets = 500;
|
|
27
|
+
const keepAlive = true;
|
|
28
|
+
const s3ClientConfig = {
|
|
29
|
+
requestHandler: new NodeHttpHandler({
|
|
30
|
+
connectionTimeout,
|
|
31
|
+
socketTimeout,
|
|
32
|
+
httpAgent: new HttpAgent({ maxSockets, keepAlive }),
|
|
33
|
+
httpsAgent: new HttpsAgent({ maxSockets, keepAlive }),
|
|
34
|
+
}),
|
|
35
|
+
};
|
|
17
36
|
if ((this.config.key && !this.config.secret) || (this.config.secret && !this.config.key)) {
|
|
18
37
|
throw new Error('Both `key` and `secret` are required when defined');
|
|
19
38
|
}
|
|
@@ -44,12 +63,6 @@ export class DriverS3 {
|
|
|
44
63
|
return normalizePath(join(this.root, filepath));
|
|
45
64
|
}
|
|
46
65
|
async read(filepath, range) {
|
|
47
|
-
/*
|
|
48
|
-
* AWS' client default socket reusing and keepalive can cause performance issues when using it
|
|
49
|
-
* very often in rapid succession. For reads, where it's more likely to hit this limitation,
|
|
50
|
-
* we'll use a new non-shared S3 client to get around this.
|
|
51
|
-
*/
|
|
52
|
-
const client = this.getClient();
|
|
53
66
|
const commandInput = {
|
|
54
67
|
Key: this.fullPath(filepath),
|
|
55
68
|
Bucket: this.config.bucket,
|
|
@@ -57,11 +70,10 @@ export class DriverS3 {
|
|
|
57
70
|
if (range) {
|
|
58
71
|
commandInput.Range = `bytes=${range.start ?? ''}-${range.end ?? ''}`;
|
|
59
72
|
}
|
|
60
|
-
const { Body: stream } = await client.send(new GetObjectCommand(commandInput));
|
|
73
|
+
const { Body: stream } = await this.client.send(new GetObjectCommand(commandInput));
|
|
61
74
|
if (!stream || !isReadableStream(stream)) {
|
|
62
75
|
throw new Error(`No stream returned for file "${filepath}"`);
|
|
63
76
|
}
|
|
64
|
-
stream.on('finished', () => client.destroy());
|
|
65
77
|
return stream;
|
|
66
78
|
}
|
|
67
79
|
async stat(filepath) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@directus/storage-driver-s3",
|
|
3
|
-
"version": "10.0.
|
|
3
|
+
"version": "10.0.6",
|
|
4
4
|
"description": "S3 file storage abstraction for `@directus/storage`",
|
|
5
5
|
"homepage": "https://directus.io",
|
|
6
6
|
"repository": {
|
|
@@ -24,8 +24,9 @@
|
|
|
24
24
|
"@aws-sdk/abort-controller": "3.329.0",
|
|
25
25
|
"@aws-sdk/client-s3": "3.332.0",
|
|
26
26
|
"@aws-sdk/lib-storage": "3.332.0",
|
|
27
|
-
"@
|
|
28
|
-
"@directus/
|
|
27
|
+
"@aws-sdk/node-http-handler": "3.344.0",
|
|
28
|
+
"@directus/storage": "10.0.4",
|
|
29
|
+
"@directus/utils": "10.0.6"
|
|
29
30
|
},
|
|
30
31
|
"devDependencies": {
|
|
31
32
|
"@ngneat/falso": "6.4.0",
|