@visulima/storage 1.0.0-alpha.17 → 1.0.0-alpha.19
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/CHANGELOG.md +21 -0
- package/LICENSE.md +3 -0
- package/dist/adapter/nuxt/module.d.ts +3 -3
- package/dist/adapter/nuxt/module.js +1 -93
- package/dist/handler/http/fetch/index.d.ts +6 -6
- package/dist/handler/http/fetch/index.js +1 -4
- package/dist/handler/http/hono/index.d.ts +3 -3
- package/dist/handler/http/hono/index.js +1 -65
- package/dist/handler/http/nextjs/index.d.ts +4 -4
- package/dist/handler/http/nextjs/index.js +1 -37
- package/dist/handler/http/node/index.d.ts +6 -6
- package/dist/handler/http/node/index.js +1 -8
- package/dist/handler/http/solid-start/index.d.ts +4 -4
- package/dist/handler/http/solid-start/index.js +1 -44
- package/dist/index.js +1 -13
- package/dist/openapi/index.js +1 -5
- package/dist/packem_shared/AwsLightFile-BTLiRxXj.js +1 -0
- package/dist/packem_shared/AwsLightMetaStorage-DHz1nf_H.js +1 -0
- package/dist/packem_shared/AwsLightStorage-CA9cdfJ6.js +1 -0
- package/dist/packem_shared/AzureFile-BKHru1zB.js +1 -0
- package/dist/packem_shared/AzureSMetaStorage-BqA4jUDJ.js +1 -0
- package/dist/packem_shared/AzureStorage-BKUjCymW.js +1 -0
- package/dist/packem_shared/BaseTransformer-D68eLyz1.js +1 -0
- package/dist/packem_shared/DiskStorage-DNjpDMX9.js +1 -0
- package/dist/packem_shared/DiskStorageWithChecksum-Bb6JX_tC.js +1 -0
- package/dist/packem_shared/ERRORS-B9jkvKwx.js +1 -0
- package/dist/packem_shared/File-alcSNpLq.js +1 -0
- package/dist/packem_shared/GCSConfig-BQ0OpVhe.js +1 -0
- package/dist/packem_shared/GCSFile-CHjX_fJk.js +1 -0
- package/dist/packem_shared/GCSMetaStorage-CpxQ8wM9.js +1 -0
- package/dist/packem_shared/GCStorage-DAg1V55T.js +1 -0
- package/dist/packem_shared/LocalMetaStorage-BWuFvWn4.js +1 -0
- package/dist/packem_shared/MediaTransformer-2C8MJeAg.js +1 -0
- package/dist/packem_shared/MetaStorage-Y4m1dWgd.js +1 -0
- package/dist/packem_shared/Metadata-B6Ir0KO7.js +1 -0
- package/dist/packem_shared/Multipart-Bd9YFFn0.js +1 -0
- package/dist/packem_shared/Multipart-D5bcEvga.js +1 -0
- package/dist/packem_shared/NetlifyBlobFile-CpzkMKng.js +1 -0
- package/dist/packem_shared/NetlifyBlobMetaStorage-dD0oBLom.js +1 -0
- package/dist/packem_shared/NetlifyBlobStorage-ByTwCN-h.js +1 -0
- package/dist/packem_shared/NoOpMetrics-Dky06sf1.js +1 -0
- package/dist/packem_shared/OpenTelemetryMetrics-9uxQMSlg.js +1 -0
- package/dist/packem_shared/Rest-CYEBbtCD.js +1 -0
- package/dist/packem_shared/Rest-DoonVU7B.js +1 -0
- package/dist/packem_shared/S3File-Du6wP0Sz.js +1 -0
- package/dist/packem_shared/S3MetaStorage-vcriiosn.js +1 -0
- package/dist/packem_shared/S3Storage-Fx6-OSc-.js +1 -0
- package/dist/packem_shared/TUS_RESUMABLE-B7KtPVeC.js +1 -0
- package/dist/packem_shared/Tus-Bd_2Ki2G.js +1 -0
- package/dist/packem_shared/Tus-CUBCkuPE.js +1 -0
- package/dist/packem_shared/ValidationError-D8KKJiKA.js +1 -0
- package/dist/packem_shared/VercelBlobFile-CL9MjKcY.js +1 -0
- package/dist/packem_shared/VercelBlobMetaStorage-BsOTx-Su.js +1 -0
- package/dist/packem_shared/VercelBlobStorage-kNkk5Cn4.js +1 -0
- package/dist/packem_shared/_commonjsHelpers-D6W6KoPK.js +1 -0
- package/dist/packem_shared/aws-light-meta-storage-TPyQwLvk.js +4 -0
- package/dist/packem_shared/backblaze-DEflv87m.js +1 -0
- package/dist/packem_shared/base-handler-core-DaggCVsq.js +1 -0
- package/dist/packem_shared/base-handler-fetch-DnarP64X.js +1 -0
- package/dist/packem_shared/base-handler-node-BTes6sql.js +1 -0
- package/dist/packem_shared/cache-qV_5Umeq.js +1 -0
- package/dist/packem_shared/cloudflare-DLAeQvgD.js +1 -0
- package/dist/packem_shared/defaultCloudStorageFileNameValidation-yiM9GxHr.js +1 -0
- package/dist/packem_shared/digitalOcean-nhZUds87.js +1 -0
- package/dist/packem_shared/disk-storage-BvdK4bqF.js +5 -0
- package/dist/packem_shared/gcs-meta-storage-CvGkpzVE.js +1 -0
- package/dist/packem_shared/has-content-Bx2p8Okx.js +1 -0
- package/dist/packem_shared/headers-DC2MEOrK.js +27 -0
- package/dist/packem_shared/is-expired-1JuZjDtb.js +1 -0
- package/dist/packem_shared/isRetryableError-DQNSZiBc.js +1 -0
- package/dist/packem_shared/isValidMediaType-B-2UKjZx.js +1 -0
- package/dist/packem_shared/local-meta-storage-Bkwqi_gi.js +1 -0
- package/dist/packem_shared/{media-transformer.d-ChmjTvjc.d.ts → media-transformer.d-CY9CsEOe.d.ts} +1 -1
- package/dist/packem_shared/minio-BWwgGXeE.js +1 -0
- package/dist/packem_shared/multipart-base-C6OjBwMS.js +1 -0
- package/dist/packem_shared/part-match-DqD5U7An.js +1 -0
- package/dist/packem_shared/path-D7rMc9nq-B718mbm6.js +1 -0
- package/dist/packem_shared/response-builder-Wdo_fvcF.js +1 -0
- package/dist/packem_shared/rest-base-B2Dv7esY.js +1 -0
- package/dist/packem_shared/restOpenApiSpec-PaIVbESh.js +1 -0
- package/dist/packem_shared/s3-base-storage-xHZNtsGe.js +1 -0
- package/dist/packem_shared/sharedGet-Ce7WGAsc.js +1 -0
- package/dist/packem_shared/storage-m_Cxgiih.js +1 -0
- package/dist/packem_shared/tigris-DZoyrMNd.js +1 -0
- package/dist/packem_shared/transformOpenApiSpec-C0vEbDTO.js +1 -0
- package/dist/packem_shared/{tus-base.d-CpLzyd-S.d.ts → tus-base.d-DNZRXR9X.d.ts} +2 -2
- package/dist/packem_shared/tusOpenApiSpec-DF0-hlWV.js +1 -0
- package/dist/packem_shared/{types.d-DBjmJvIT.d.ts → types.d-BCN94sB_.d.ts} +1 -1
- package/dist/packem_shared/{types.d-DviSTLOg.d.ts → types.d-D4caL2Fp.d.ts} +1 -1
- package/dist/packem_shared/update-size-DANV7aa2.js +1 -0
- package/dist/packem_shared/validator-DK41xp8N.js +1 -0
- package/dist/packem_shared/waitForStorage-ChSBLhLc.js +1 -0
- package/dist/packem_shared/wasabi-Dmce4x9s.js +1 -0
- package/dist/packem_shared/xhrOpenApiSpec-nyoboz83.js +1 -0
- package/dist/storage/aws/clients/index.js +1 -6
- package/dist/storage/aws/index.js +1 -3
- package/dist/storage/aws-light/index.js +1 -3
- package/dist/storage/azure/index.js +1 -3
- package/dist/storage/gcs/index.js +1 -4
- package/dist/storage/local/index.js +1 -3
- package/dist/storage/netlify-blob/index.js +1 -3
- package/dist/storage/vercel-blob/index.js +1 -3
- package/dist/transformer/audio-transformer.d.ts +1 -1
- package/dist/transformer/audio-transformer.js +1 -278
- package/dist/transformer/image-transformer.d.ts +1 -1
- package/dist/transformer/image-transformer.js +1 -1100
- package/dist/transformer/index.d.ts +2 -2
- package/dist/transformer/index.js +1 -4
- package/dist/transformer/video-transformer.d.ts +1 -1
- package/dist/transformer/video-transformer.js +1 -310
- package/package.json +18 -18
- package/dist/packem_shared/AwsLightFile-C-Nd5rtl.js +0 -11
- package/dist/packem_shared/AwsLightMetaStorage-BIDb5EPg.js +0 -4
- package/dist/packem_shared/AwsLightStorage-CMuKw4bI.js +0 -133
- package/dist/packem_shared/AzureFile-C0kug4w4.js +0 -8
- package/dist/packem_shared/AzureSMetaStorage-BEbXX9Uk.js +0 -89
- package/dist/packem_shared/AzureStorage-98-LRZ1e.js +0 -359
- package/dist/packem_shared/BaseTransformer-9965D4pb.js +0 -83
- package/dist/packem_shared/DiskStorage-COMe_G42.js +0 -12
- package/dist/packem_shared/DiskStorageWithChecksum-BVaaZiyS.js +0 -249
- package/dist/packem_shared/ERRORS-D0apMqnc.js +0 -97
- package/dist/packem_shared/File-CPUhj3DI.js +0 -69
- package/dist/packem_shared/GCSConfig-vPP22kN6.js +0 -11
- package/dist/packem_shared/GCSFile-DaDiCKE2.js +0 -8
- package/dist/packem_shared/GCSMetaStorage-BygVH0Ee.js +0 -7
- package/dist/packem_shared/GCStorage-4hSx_bN1.js +0 -410
- package/dist/packem_shared/LocalMetaStorage-DvnZqf61.js +0 -7
- package/dist/packem_shared/MediaTransformer-BRRqYA0E.js +0 -1202
- package/dist/packem_shared/MetaStorage-pECeFOad.js +0 -46
- package/dist/packem_shared/Metadata-DRLXeJ0F.js +0 -89
- package/dist/packem_shared/Multipart-BzzvNxt4.js +0 -128
- package/dist/packem_shared/Multipart-DLtFLQ8s.js +0 -163
- package/dist/packem_shared/NetlifyBlobFile-CfyJtGWN.js +0 -14
- package/dist/packem_shared/NetlifyBlobMetaStorage-eJT6RFy9.js +0 -9
- package/dist/packem_shared/NetlifyBlobStorage-nPv7iIAG.js +0 -376
- package/dist/packem_shared/NoOpMetrics-DhAk5rXc.js +0 -10
- package/dist/packem_shared/OpenTelemetryMetrics-BnxhqIaH.js +0 -67
- package/dist/packem_shared/Rest-DEa7IA9R.js +0 -267
- package/dist/packem_shared/Rest-qhMbCn5a.js +0 -228
- package/dist/packem_shared/S3File-BXCuJaQZ.js +0 -11
- package/dist/packem_shared/S3MetaStorage-yT4CznlV.js +0 -77
- package/dist/packem_shared/S3Storage-wi5XT-yu.js +0 -317
- package/dist/packem_shared/TUS_RESUMABLE-Dtfsffnj.js +0 -434
- package/dist/packem_shared/Tus-Ck0Hdle5.js +0 -195
- package/dist/packem_shared/Tus-_0vCdHyB.js +0 -200
- package/dist/packem_shared/ValidationError-BfF1aE4h.js +0 -26
- package/dist/packem_shared/VercelBlobFile-DkFIIb9Q.js +0 -18
- package/dist/packem_shared/VercelBlobMetaStorage-DjFmi4vp.js +0 -9
- package/dist/packem_shared/VercelBlobStorage-CmMgiDgr.js +0 -261
- package/dist/packem_shared/_commonjsHelpers-BqLXS_qQ.js +0 -5
- package/dist/packem_shared/aws-light-meta-storage-BGZEiY3y.js +0 -447
- package/dist/packem_shared/backblaze-BlMnIcBC.js +0 -20
- package/dist/packem_shared/base-handler-core-lVB-D59L.js +0 -306
- package/dist/packem_shared/base-handler-fetch-CitgN-Aw.js +0 -291
- package/dist/packem_shared/base-handler-node-BiO2DF87.js +0 -731
- package/dist/packem_shared/cache-B88MXQ_2.js +0 -18
- package/dist/packem_shared/cloudflare-Bi1q8wXE.js +0 -21
- package/dist/packem_shared/defaultCloudStorageFileNameValidation-Brw40ZEP.js +0 -11
- package/dist/packem_shared/digitalOcean-CWQRJM3L.js +0 -21
- package/dist/packem_shared/disk-storage-D9RfoKjW.js +0 -832
- package/dist/packem_shared/gcs-meta-storage-8FovEDbW.js +0 -159
- package/dist/packem_shared/has-content-CY66ehMK.js +0 -3
- package/dist/packem_shared/headers-YLRp1dLo.js +0 -1318
- package/dist/packem_shared/is-expired-CTThU1q5.js +0 -8
- package/dist/packem_shared/isRetryableError-Dycp7127.js +0 -82
- package/dist/packem_shared/isValidMediaType-BeDgiObq.js +0 -35
- package/dist/packem_shared/local-meta-storage-D-pPc3FI.js +0 -658
- package/dist/packem_shared/minio-C2YBZQOw.js +0 -22
- package/dist/packem_shared/multipart-base-C994naBi.js +0 -102
- package/dist/packem_shared/part-match-Dt738Ddb.js +0 -96
- package/dist/packem_shared/path-aV9lMdcn-DMU5H1-h.js +0 -162
- package/dist/packem_shared/response-builder-BtnRiBUI.js +0 -45
- package/dist/packem_shared/rest-base-k1ory8uB.js +0 -457
- package/dist/packem_shared/restOpenApiSpec-BBJ_SiPE.js +0 -800
- package/dist/packem_shared/s3-base-storage-zUO8u8Cp.js +0 -510
- package/dist/packem_shared/sharedGet-CkSLSnMd.js +0 -1022
- package/dist/packem_shared/storage-5XW1E7XU.js +0 -1188
- package/dist/packem_shared/tigris-Hac8TKnX.js +0 -21
- package/dist/packem_shared/transformOpenApiSpec-BodFhFls.js +0 -975
- package/dist/packem_shared/tusOpenApiSpec-DzppyJTW.js +0 -740
- package/dist/packem_shared/update-size-CCGm6i1J.js +0 -8
- package/dist/packem_shared/validator-DuO17wFF.js +0 -79
- package/dist/packem_shared/waitForStorage-Cscw85sx.js +0 -18
- package/dist/packem_shared/wasabi-DIyflHSd.js +0 -21
- package/dist/packem_shared/xhrOpenApiSpec-CXz7BC5J.js +0 -264
|
@@ -1,317 +0,0 @@
|
|
|
1
|
-
import { Readable } from 'node:stream';
|
|
2
|
-
import { CreateMultipartUploadCommand, UploadPartCommand, CompleteMultipartUploadCommand, AbortMultipartUploadCommand, ListPartsCommand, GetObjectCommand, HeadObjectCommand, DeleteObjectCommand, CopyObjectCommand, ListObjectsV2Command, waitUntilBucketExists, S3Client } from '@aws-sdk/client-s3';
|
|
3
|
-
import { fromIni } from '@aws-sdk/credential-providers';
|
|
4
|
-
import { S as S3BaseStorage } from './s3-base-storage-zUO8u8Cp.js';
|
|
5
|
-
import { ReadableStream } from 'node:stream/web';
|
|
6
|
-
import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
|
|
7
|
-
import S3File from './S3File-BXCuJaQZ.js';
|
|
8
|
-
import S3MetaStorage from './S3MetaStorage-yT4CznlV.js';
|
|
9
|
-
|
|
10
|
-
class S3ClientAdapter {
|
|
11
|
-
constructor(client, _bucket) {
|
|
12
|
-
this.client = client;
|
|
13
|
-
}
|
|
14
|
-
client;
|
|
15
|
-
async createMultipartUpload(params) {
|
|
16
|
-
const command = new CreateMultipartUploadCommand({
|
|
17
|
-
ACL: params.ACL,
|
|
18
|
-
Bucket: params.Bucket,
|
|
19
|
-
ContentType: params.ContentType,
|
|
20
|
-
Key: params.Key,
|
|
21
|
-
Metadata: params.Metadata
|
|
22
|
-
});
|
|
23
|
-
const response = await this.client.send(command);
|
|
24
|
-
if (!response.UploadId) {
|
|
25
|
-
throw new Error("Failed to create multipart upload");
|
|
26
|
-
}
|
|
27
|
-
return { UploadId: response.UploadId };
|
|
28
|
-
}
|
|
29
|
-
async uploadPart(params) {
|
|
30
|
-
const body = params.Body instanceof ReadableStream ? Readable.fromWeb(params.Body) : params.Body;
|
|
31
|
-
const command = new UploadPartCommand({
|
|
32
|
-
Body: body,
|
|
33
|
-
Bucket: params.Bucket,
|
|
34
|
-
ContentLength: params.ContentLength,
|
|
35
|
-
ContentMD5: params.ContentMD5,
|
|
36
|
-
Key: params.Key,
|
|
37
|
-
PartNumber: params.PartNumber,
|
|
38
|
-
UploadId: params.UploadId
|
|
39
|
-
});
|
|
40
|
-
const response = await this.client.send(command);
|
|
41
|
-
if (!response.ETag) {
|
|
42
|
-
throw new Error("Failed to upload part");
|
|
43
|
-
}
|
|
44
|
-
return { ETag: response.ETag };
|
|
45
|
-
}
|
|
46
|
-
async completeMultipartUpload(params) {
|
|
47
|
-
const command = new CompleteMultipartUploadCommand({
|
|
48
|
-
Bucket: params.Bucket,
|
|
49
|
-
Key: params.Key,
|
|
50
|
-
MultipartUpload: {
|
|
51
|
-
Parts: params.Parts.map(({ ETag, PartNumber }) => {
|
|
52
|
-
return { ETag, PartNumber };
|
|
53
|
-
})
|
|
54
|
-
},
|
|
55
|
-
UploadId: params.UploadId
|
|
56
|
-
});
|
|
57
|
-
const response = await this.client.send(command);
|
|
58
|
-
if (!response.Location) {
|
|
59
|
-
throw new Error("Failed to complete multipart upload");
|
|
60
|
-
}
|
|
61
|
-
return {
|
|
62
|
-
ETag: response.ETag,
|
|
63
|
-
Location: response.Location
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
async abortMultipartUpload(params) {
|
|
67
|
-
const command = new AbortMultipartUploadCommand({
|
|
68
|
-
Bucket: params.Bucket,
|
|
69
|
-
Key: params.Key,
|
|
70
|
-
UploadId: params.UploadId
|
|
71
|
-
});
|
|
72
|
-
await this.client.send(command);
|
|
73
|
-
}
|
|
74
|
-
async listParts(params) {
|
|
75
|
-
const command = new ListPartsCommand({
|
|
76
|
-
Bucket: params.Bucket,
|
|
77
|
-
Key: params.Key,
|
|
78
|
-
UploadId: params.UploadId
|
|
79
|
-
});
|
|
80
|
-
const response = await this.client.send(command);
|
|
81
|
-
const parts = [];
|
|
82
|
-
if (response.Parts) {
|
|
83
|
-
for (const part of response.Parts) {
|
|
84
|
-
if (part.ETag && part.PartNumber) {
|
|
85
|
-
parts.push({
|
|
86
|
-
ETag: part.ETag,
|
|
87
|
-
PartNumber: part.PartNumber,
|
|
88
|
-
Size: part.Size
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
return { Parts: parts.length > 0 ? parts : void 0 };
|
|
94
|
-
}
|
|
95
|
-
async getObject(params) {
|
|
96
|
-
const command = new GetObjectCommand({
|
|
97
|
-
Bucket: params.Bucket,
|
|
98
|
-
Key: params.Key
|
|
99
|
-
});
|
|
100
|
-
const response = await this.client.send(command);
|
|
101
|
-
let body;
|
|
102
|
-
if (response.Body) {
|
|
103
|
-
const sdkStream = response.Body;
|
|
104
|
-
if (sdkStream instanceof Readable) {
|
|
105
|
-
body = sdkStream;
|
|
106
|
-
} else if (typeof sdkStream === "object" && "transform" in sdkStream && sdkStream instanceof ReadableStream) {
|
|
107
|
-
body = sdkStream;
|
|
108
|
-
} else {
|
|
109
|
-
body = Readable.from(sdkStream);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
return {
|
|
113
|
-
Body: body,
|
|
114
|
-
ContentLength: response.ContentLength,
|
|
115
|
-
ContentType: response.ContentType,
|
|
116
|
-
ETag: response.ETag,
|
|
117
|
-
Expires: response.Expires,
|
|
118
|
-
LastModified: response.LastModified,
|
|
119
|
-
Metadata: response.Metadata
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
async headObject(params) {
|
|
123
|
-
const command = new HeadObjectCommand({
|
|
124
|
-
Bucket: params.Bucket,
|
|
125
|
-
Key: params.Key
|
|
126
|
-
});
|
|
127
|
-
const response = await this.client.send(command);
|
|
128
|
-
return {
|
|
129
|
-
ContentLength: response.ContentLength,
|
|
130
|
-
ContentType: response.ContentType,
|
|
131
|
-
ETag: response.ETag,
|
|
132
|
-
Expires: response.Expires,
|
|
133
|
-
LastModified: response.LastModified
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
async deleteObject(params) {
|
|
137
|
-
const command = new DeleteObjectCommand({
|
|
138
|
-
Bucket: params.Bucket,
|
|
139
|
-
Key: params.Key
|
|
140
|
-
});
|
|
141
|
-
await this.client.send(command);
|
|
142
|
-
}
|
|
143
|
-
async copyObject(params) {
|
|
144
|
-
const commandInput = {
|
|
145
|
-
Bucket: params.Bucket,
|
|
146
|
-
CopySource: params.CopySource,
|
|
147
|
-
Key: params.Key
|
|
148
|
-
};
|
|
149
|
-
if (params.StorageClass) {
|
|
150
|
-
commandInput.StorageClass = params.StorageClass;
|
|
151
|
-
}
|
|
152
|
-
const command = new CopyObjectCommand(commandInput);
|
|
153
|
-
await this.client.send(command);
|
|
154
|
-
}
|
|
155
|
-
async listObjectsV2(params) {
|
|
156
|
-
const command = new ListObjectsV2Command({
|
|
157
|
-
Bucket: params.Bucket,
|
|
158
|
-
ContinuationToken: params.ContinuationToken,
|
|
159
|
-
MaxKeys: params.MaxKeys
|
|
160
|
-
});
|
|
161
|
-
const response = await this.client.send(command);
|
|
162
|
-
return {
|
|
163
|
-
Contents: response.Contents?.map((item) => {
|
|
164
|
-
return {
|
|
165
|
-
Key: item.Key,
|
|
166
|
-
LastModified: item.LastModified
|
|
167
|
-
};
|
|
168
|
-
}),
|
|
169
|
-
IsTruncated: response.IsTruncated,
|
|
170
|
-
NextContinuationToken: response.NextContinuationToken
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
async getPresignedUrl(params) {
|
|
174
|
-
const command = new UploadPartCommand({
|
|
175
|
-
Bucket: params.Bucket,
|
|
176
|
-
Key: params.Key,
|
|
177
|
-
PartNumber: params.PartNumber,
|
|
178
|
-
UploadId: params.UploadId
|
|
179
|
-
});
|
|
180
|
-
return getSignedUrl(this.client, command, { expiresIn: params.expiresIn });
|
|
181
|
-
}
|
|
182
|
-
async checkBucketAccess(params) {
|
|
183
|
-
await waitUntilBucketExists({ client: this.client, maxWaitTime: 30 }, { Bucket: params.Bucket });
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
class S3Storage extends S3BaseStorage {
|
|
188
|
-
static name = "s3";
|
|
189
|
-
s3Api;
|
|
190
|
-
constructor(config) {
|
|
191
|
-
const { bucket = process.env.S3_BUCKET, region = process.env.S3_REGION } = config;
|
|
192
|
-
if (!bucket) {
|
|
193
|
-
throw new Error("S3 bucket is not defined");
|
|
194
|
-
}
|
|
195
|
-
if (!region) {
|
|
196
|
-
throw new Error("S3 region is not defined");
|
|
197
|
-
}
|
|
198
|
-
config.region = region;
|
|
199
|
-
const keyFile = config.keyFile || process.env.S3_KEYFILE;
|
|
200
|
-
if (keyFile) {
|
|
201
|
-
config.credentials = fromIni({ configFilepath: keyFile });
|
|
202
|
-
}
|
|
203
|
-
const client = new S3Client(config);
|
|
204
|
-
super({
|
|
205
|
-
bucket,
|
|
206
|
-
clientDirectUpload: config.clientDirectUpload,
|
|
207
|
-
expiration: config.expiration?.maxAge ? { maxAge: String(config.expiration.maxAge) } : void 0,
|
|
208
|
-
filename: config.filename,
|
|
209
|
-
logger: config.logger,
|
|
210
|
-
metaStorage: config.metaStorage,
|
|
211
|
-
metaStorageConfig: config.metaStorageConfig ? { ...config.metaStorageConfig, ...config } : { ...config },
|
|
212
|
-
partSize: config.partSize,
|
|
213
|
-
retryConfig: {
|
|
214
|
-
...config.retryConfig,
|
|
215
|
-
shouldRetry: (error) => {
|
|
216
|
-
const errorWithMetadata = error;
|
|
217
|
-
if (errorWithMetadata.$metadata) {
|
|
218
|
-
const statusCode = errorWithMetadata.$metadata.httpStatusCode;
|
|
219
|
-
if (statusCode && [408, 429, 500, 502, 503, 504].includes(statusCode)) {
|
|
220
|
-
return true;
|
|
221
|
-
}
|
|
222
|
-
if (errorWithMetadata.$fault === "server") {
|
|
223
|
-
return true;
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
return errorWithMetadata.retryable ?? false;
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
});
|
|
230
|
-
this.s3Api = new S3ClientAdapter(client, bucket);
|
|
231
|
-
const { metaStorage, metaStorageConfig } = config;
|
|
232
|
-
if (!metaStorage) {
|
|
233
|
-
const metaConfig = { ...config, ...metaStorageConfig, logger: this.logger };
|
|
234
|
-
const localMeta = "directory" in metaConfig;
|
|
235
|
-
if (!localMeta) {
|
|
236
|
-
this.meta = new S3MetaStorage(metaConfig);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
if (this.config.clientDirectUpload) {
|
|
240
|
-
this.onCreate = async () => {
|
|
241
|
-
};
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
/**
|
|
245
|
-
* Normalizes AWS S3 errors with S3-specific context.
|
|
246
|
-
*/
|
|
247
|
-
normalizeError(error) {
|
|
248
|
-
if (error.$metadata) {
|
|
249
|
-
return {
|
|
250
|
-
code: error.Code || error.name,
|
|
251
|
-
message: error.message,
|
|
252
|
-
name: error.name,
|
|
253
|
-
statusCode: error.$metadata.httpStatusCode || 500
|
|
254
|
-
};
|
|
255
|
-
}
|
|
256
|
-
return super.normalizeError(error);
|
|
257
|
-
}
|
|
258
|
-
async update({ id }, metadata) {
|
|
259
|
-
if (this.config.clientDirectUpload) {
|
|
260
|
-
const file = await this.getMeta(id);
|
|
261
|
-
return this.buildPresigned({ ...file, ...metadata });
|
|
262
|
-
}
|
|
263
|
-
return super.update({ id }, metadata);
|
|
264
|
-
}
|
|
265
|
-
async getStream({ id }) {
|
|
266
|
-
return this.instrumentOperation("getStream", async () => {
|
|
267
|
-
const s3Api = this.getS3Api();
|
|
268
|
-
const { Body, ContentLength, ContentType, ETag, Expires, LastModified } = await this.retry(
|
|
269
|
-
() => s3Api.getObject({
|
|
270
|
-
Bucket: this.bucket,
|
|
271
|
-
Key: id
|
|
272
|
-
})
|
|
273
|
-
);
|
|
274
|
-
await this.checkIfExpired({ expiredAt: Expires });
|
|
275
|
-
const stream = Body;
|
|
276
|
-
const readableStream = new Readable({
|
|
277
|
-
read() {
|
|
278
|
-
stream.on("data", (chunk) => {
|
|
279
|
-
this.push(chunk);
|
|
280
|
-
});
|
|
281
|
-
stream.on("end", () => {
|
|
282
|
-
this.push(null);
|
|
283
|
-
});
|
|
284
|
-
stream.on("error", (error) => {
|
|
285
|
-
this.destroy(error);
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
});
|
|
289
|
-
return {
|
|
290
|
-
headers: {
|
|
291
|
-
"Content-Length": ContentLength?.toString() ?? "0",
|
|
292
|
-
"Content-Type": ContentType,
|
|
293
|
-
...ETag && { ETag },
|
|
294
|
-
...Expires && { "X-Upload-Expires": Expires.toString() },
|
|
295
|
-
...LastModified && { "Last-Modified": LastModified.toString() }
|
|
296
|
-
},
|
|
297
|
-
size: Number(ContentLength),
|
|
298
|
-
stream: readableStream
|
|
299
|
-
};
|
|
300
|
-
});
|
|
301
|
-
}
|
|
302
|
-
getS3Api() {
|
|
303
|
-
return this.s3Api;
|
|
304
|
-
}
|
|
305
|
-
// eslint-disable-next-line class-methods-use-this
|
|
306
|
-
getFileClass() {
|
|
307
|
-
return S3File;
|
|
308
|
-
}
|
|
309
|
-
getAcl() {
|
|
310
|
-
return this.config.acl;
|
|
311
|
-
}
|
|
312
|
-
async accessCheck(_maxWaitTime = 30) {
|
|
313
|
-
await this.s3Api.checkBucketAccess({ Bucket: this.bucket });
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
export { S3Storage as default };
|