@travetto/model-s3 3.3.5 → 3.3.7
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/package.json +3 -3
- package/src/service.ts +21 -15
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/model-s3",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.7",
|
|
4
4
|
"description": "S3 backing for the travetto model module.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"s3",
|
|
@@ -25,10 +25,10 @@
|
|
|
25
25
|
"directory": "module/model-s3"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@aws-sdk/client-s3": "^3.
|
|
28
|
+
"@aws-sdk/client-s3": "^3.417.0",
|
|
29
29
|
"@aws-sdk/credential-provider-ini": "^3.218.0",
|
|
30
30
|
"@travetto/config": "^3.3.4",
|
|
31
|
-
"@travetto/model": "^3.3.
|
|
31
|
+
"@travetto/model": "^3.3.7"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
34
|
"@travetto/command": "^3.3.3"
|
package/src/service.ts
CHANGED
|
@@ -14,9 +14,9 @@ import { ModelCrudUtil } from '@travetto/model/src/internal/service/crud';
|
|
|
14
14
|
import { ModelExpirySupport } from '@travetto/model/src/service/expiry';
|
|
15
15
|
import { ModelExpiryUtil } from '@travetto/model/src/internal/service/expiry';
|
|
16
16
|
import { ModelStorageUtil } from '@travetto/model/src/internal/service/storage';
|
|
17
|
+
import { ModelStreamUtil } from '@travetto/model/src/internal/service/stream';
|
|
17
18
|
|
|
18
19
|
import { S3ModelConfig } from './config';
|
|
19
|
-
import { ModelStreamUtil } from '@travetto/model/src/internal/service/stream';
|
|
20
20
|
|
|
21
21
|
function isMetadataBearer(o: unknown): o is MetadataBearer {
|
|
22
22
|
return !!o && typeof o === 'object' && '$metadata' in o;
|
|
@@ -28,6 +28,10 @@ function hasContentType<T>(o: T): o is T & { contenttype?: string } {
|
|
|
28
28
|
|
|
29
29
|
const STREAM_SPACE = '@travetto/model-s3:stream';
|
|
30
30
|
|
|
31
|
+
type MetaBase = Pick<s3.CreateMultipartUploadRequest,
|
|
32
|
+
'ContentType' | 'Metadata' | 'ContentEncoding' | 'ContentLanguage' | 'CacheControl' | 'ContentDisposition'
|
|
33
|
+
>;
|
|
34
|
+
|
|
31
35
|
/**
|
|
32
36
|
* Asset source backed by S3
|
|
33
37
|
*/
|
|
@@ -39,6 +43,19 @@ export class S3ModelService implements ModelCrudSupport, ModelStreamSupport, Mod
|
|
|
39
43
|
|
|
40
44
|
constructor(public readonly config: S3ModelConfig) { }
|
|
41
45
|
|
|
46
|
+
#getMetaBase(meta: StreamMeta): MetaBase {
|
|
47
|
+
return {
|
|
48
|
+
ContentType: meta.contentType,
|
|
49
|
+
...(meta.contentEncoding ? { ContentEncoding: meta.contentEncoding } : {}),
|
|
50
|
+
...(meta.contentLanguage ? { ContentLanguage: meta.contentLanguage } : {}),
|
|
51
|
+
...(meta.cacheControl ? { CacheControl: meta.cacheControl } : {}),
|
|
52
|
+
Metadata: {
|
|
53
|
+
...meta,
|
|
54
|
+
size: `${meta.size}`
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
42
59
|
#resolveKey(cls: Class | string, id?: string): string {
|
|
43
60
|
let key: string;
|
|
44
61
|
if (cls === STREAM_SPACE) { // If we are streaming, treat as primary use case
|
|
@@ -91,14 +108,7 @@ export class S3ModelService implements ModelCrudSupport, ModelStreamSupport, Mod
|
|
|
91
108
|
* Write multipart file upload, in chunks
|
|
92
109
|
*/
|
|
93
110
|
async #writeMultipart(id: string, input: Readable, meta: StreamMeta): Promise<void> {
|
|
94
|
-
const { UploadId } = await this.client.createMultipartUpload(this.#q(STREAM_SPACE, id,
|
|
95
|
-
ContentType: meta.contentType,
|
|
96
|
-
ContentLength: meta.size,
|
|
97
|
-
Metadata: {
|
|
98
|
-
...meta,
|
|
99
|
-
size: `${meta.size}`
|
|
100
|
-
}
|
|
101
|
-
}));
|
|
111
|
+
const { UploadId } = await this.client.createMultipartUpload(this.#q(STREAM_SPACE, id, this.#getMetaBase(meta)));
|
|
102
112
|
|
|
103
113
|
const parts: s3.CompletedPart[] = [];
|
|
104
114
|
let buffers: Buffer[] = [];
|
|
@@ -276,16 +286,12 @@ export class S3ModelService implements ModelCrudSupport, ModelStreamSupport, Mod
|
|
|
276
286
|
}
|
|
277
287
|
|
|
278
288
|
async upsertStream(location: string, input: Readable, meta: StreamMeta): Promise<void> {
|
|
279
|
-
if (meta.size < this.config.chunkSize) { // If
|
|
289
|
+
if (meta.size < this.config.chunkSize) { // If smaller than chunk size
|
|
280
290
|
// Upload to s3
|
|
281
291
|
await this.client.putObject(this.#q(STREAM_SPACE, location, {
|
|
282
292
|
Body: await StreamUtil.toBuffer(input),
|
|
283
|
-
ContentType: meta.contentType,
|
|
284
293
|
ContentLength: meta.size,
|
|
285
|
-
|
|
286
|
-
...meta,
|
|
287
|
-
size: `${meta.size}`
|
|
288
|
-
}
|
|
294
|
+
...this.#getMetaBase(meta),
|
|
289
295
|
}));
|
|
290
296
|
} else {
|
|
291
297
|
await this.#writeMultipart(location, input, meta);
|