@qrvey/object-storage 1.0.1-beta → 1.0.3-535
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/README.md +1 -1
- package/dist/cjs/index.js +592 -126
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.d.mts +46 -20
- package/dist/esm/index.mjs +590 -124
- package/dist/esm/index.mjs.map +1 -1
- package/dist/types/index.d.ts +46 -20
- package/package.json +34 -29
package/dist/esm/index.mjs
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import
|
|
1
|
+
import stream2, { Readable, PassThrough } from 'stream';
|
|
2
2
|
import { BlobServiceClient, BlobSASPermissions } from '@azure/storage-blob';
|
|
3
3
|
import { S3Client, S3, ListObjectsV2Command, HeadObjectCommand, GetObjectCommand, PutObjectCommand, DeleteObjectCommand, HeadBucketCommand, UploadPartCommand } from '@aws-sdk/client-s3';
|
|
4
|
+
import { defaultProvider } from '@aws-sdk/credential-provider-node';
|
|
4
5
|
import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
|
|
5
6
|
import { Upload } from '@aws-sdk/lib-storage';
|
|
6
7
|
import { Agent, request as request$1 } from 'http';
|
|
7
8
|
import { Agent as Agent$1, request } from 'https';
|
|
9
|
+
import { Client } from 'basic-ftp';
|
|
8
10
|
|
|
9
11
|
var __defProp = Object.defineProperty;
|
|
10
12
|
var __defProps = Object.defineProperties;
|
|
@@ -30,6 +32,13 @@ var __spreadValues = (a, b) => {
|
|
|
30
32
|
return a;
|
|
31
33
|
};
|
|
32
34
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
35
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
36
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
37
|
+
}) : x)(function(x) {
|
|
38
|
+
if (typeof require !== "undefined")
|
|
39
|
+
return require.apply(this, arguments);
|
|
40
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
41
|
+
});
|
|
33
42
|
var __objRest = (source, exclude) => {
|
|
34
43
|
var target = {};
|
|
35
44
|
for (var prop in source)
|
|
@@ -131,12 +140,13 @@ var BlobStorageService = class {
|
|
|
131
140
|
* Retrieves the properties of a blob from the container by its name.
|
|
132
141
|
*
|
|
133
142
|
* @param {string} blobName - The name of the blob.
|
|
143
|
+
* @param {ObjectStorageOptions} options - The options for the object storage service.
|
|
134
144
|
* @return {Promise<GetObjectResponse>} A promise that resolves to the blob properties.
|
|
135
145
|
*/
|
|
136
|
-
constructor(containerName) {
|
|
146
|
+
constructor(containerName, options) {
|
|
137
147
|
this.containerName = containerName;
|
|
138
148
|
this.blobServiceClient = BlobServiceClient.fromConnectionString(
|
|
139
|
-
process.env.AZURE_STORAGE_CONNECTION_STRING
|
|
149
|
+
(options == null ? void 0 : options.connectionString) || process.env.AZURE_STORAGE_CONNECTION_STRING
|
|
140
150
|
);
|
|
141
151
|
}
|
|
142
152
|
/**
|
|
@@ -145,21 +155,20 @@ var BlobStorageService = class {
|
|
|
145
155
|
* @param {string} blobName - The name of the blob to upload.
|
|
146
156
|
* @return {CreateUploadWriteStreamResponse} An object containing the key of the uploaded blob, the writable stream, and a promise that resolves when the upload is complete.
|
|
147
157
|
*/
|
|
148
|
-
createUploadWriteStream(blobName
|
|
149
|
-
const
|
|
150
|
-
const streamResponse = streamPassThrough != null ? streamPassThrough : streamPass;
|
|
158
|
+
createUploadWriteStream(blobName) {
|
|
159
|
+
const streamPassThrough = new stream2.PassThrough();
|
|
151
160
|
const containerClient = this.blobServiceClient.getContainerClient(
|
|
152
161
|
this.containerName
|
|
153
162
|
);
|
|
154
163
|
const blockBlobClient = containerClient.getBlockBlobClient(blobName);
|
|
155
|
-
const uploadPromise = blockBlobClient.uploadStream(
|
|
164
|
+
const uploadPromise = blockBlobClient.uploadStream(streamPassThrough, void 0, void 0, {
|
|
156
165
|
onProgress: (ev) => console.log(ev)
|
|
157
166
|
}).then(() => {
|
|
158
167
|
return { Bucket: this.containerName, Key: blobName };
|
|
159
168
|
});
|
|
160
169
|
return {
|
|
161
170
|
key: blobName,
|
|
162
|
-
stream:
|
|
171
|
+
stream: streamPassThrough,
|
|
163
172
|
promise: uploadPromise
|
|
164
173
|
};
|
|
165
174
|
}
|
|
@@ -557,11 +566,10 @@ var BlobStorageService = class {
|
|
|
557
566
|
* Completes a multipart upload by committing the blocks to create the blob.
|
|
558
567
|
*
|
|
559
568
|
* @param {string} blobName - The name of the blob for which the multipart upload is being completed.
|
|
560
|
-
* @param {string} uploadId - The ID of the multipart upload to be completed.
|
|
561
569
|
* @return {Promise<void>} A Promise that resolves when the multipart upload is successfully completed.
|
|
562
570
|
* @throws {Error} If no block IDs are found in the metadata.
|
|
563
571
|
*/
|
|
564
|
-
async completeMultipartUpload(blobName
|
|
572
|
+
async completeMultipartUpload(blobName) {
|
|
565
573
|
var _a;
|
|
566
574
|
const containerClient = this.blobServiceClient.getContainerClient(
|
|
567
575
|
this.containerName
|
|
@@ -629,28 +637,28 @@ function s3ObjectToObjectResponse(s3Object) {
|
|
|
629
637
|
};
|
|
630
638
|
}
|
|
631
639
|
|
|
632
|
-
//
|
|
640
|
+
// node_modules/@smithy/types/dist-es/auth/auth.js
|
|
633
641
|
var HttpAuthLocation;
|
|
634
642
|
(function(HttpAuthLocation2) {
|
|
635
643
|
HttpAuthLocation2["HEADER"] = "header";
|
|
636
644
|
HttpAuthLocation2["QUERY"] = "query";
|
|
637
645
|
})(HttpAuthLocation || (HttpAuthLocation = {}));
|
|
638
646
|
|
|
639
|
-
//
|
|
647
|
+
// node_modules/@smithy/types/dist-es/auth/HttpApiKeyAuth.js
|
|
640
648
|
var HttpApiKeyAuthLocation;
|
|
641
649
|
(function(HttpApiKeyAuthLocation2) {
|
|
642
650
|
HttpApiKeyAuthLocation2["HEADER"] = "header";
|
|
643
651
|
HttpApiKeyAuthLocation2["QUERY"] = "query";
|
|
644
652
|
})(HttpApiKeyAuthLocation || (HttpApiKeyAuthLocation = {}));
|
|
645
653
|
|
|
646
|
-
//
|
|
654
|
+
// node_modules/@smithy/types/dist-es/endpoint.js
|
|
647
655
|
var EndpointURLScheme;
|
|
648
656
|
(function(EndpointURLScheme2) {
|
|
649
657
|
EndpointURLScheme2["HTTP"] = "http";
|
|
650
658
|
EndpointURLScheme2["HTTPS"] = "https";
|
|
651
659
|
})(EndpointURLScheme || (EndpointURLScheme = {}));
|
|
652
660
|
|
|
653
|
-
//
|
|
661
|
+
// node_modules/@smithy/types/dist-es/extensions/checksum.js
|
|
654
662
|
var AlgorithmId;
|
|
655
663
|
(function(AlgorithmId2) {
|
|
656
664
|
AlgorithmId2["MD5"] = "md5";
|
|
@@ -660,14 +668,14 @@ var AlgorithmId;
|
|
|
660
668
|
AlgorithmId2["SHA256"] = "sha256";
|
|
661
669
|
})(AlgorithmId || (AlgorithmId = {}));
|
|
662
670
|
|
|
663
|
-
//
|
|
671
|
+
// node_modules/@smithy/types/dist-es/http.js
|
|
664
672
|
var FieldPosition;
|
|
665
673
|
(function(FieldPosition2) {
|
|
666
674
|
FieldPosition2[FieldPosition2["HEADER"] = 0] = "HEADER";
|
|
667
675
|
FieldPosition2[FieldPosition2["TRAILER"] = 1] = "TRAILER";
|
|
668
676
|
})(FieldPosition || (FieldPosition = {}));
|
|
669
677
|
|
|
670
|
-
//
|
|
678
|
+
// node_modules/@smithy/types/dist-es/profile.js
|
|
671
679
|
var IniSectionType;
|
|
672
680
|
(function(IniSectionType2) {
|
|
673
681
|
IniSectionType2["PROFILE"] = "profile";
|
|
@@ -675,7 +683,7 @@ var IniSectionType;
|
|
|
675
683
|
IniSectionType2["SERVICES"] = "services";
|
|
676
684
|
})(IniSectionType || (IniSectionType = {}));
|
|
677
685
|
|
|
678
|
-
//
|
|
686
|
+
// node_modules/@smithy/types/dist-es/transfer.js
|
|
679
687
|
var RequestHandlerProtocol;
|
|
680
688
|
(function(RequestHandlerProtocol2) {
|
|
681
689
|
RequestHandlerProtocol2["HTTP_0_9"] = "http/0.9";
|
|
@@ -683,7 +691,7 @@ var RequestHandlerProtocol;
|
|
|
683
691
|
RequestHandlerProtocol2["TDS_8_0"] = "tds/8.0";
|
|
684
692
|
})(RequestHandlerProtocol || (RequestHandlerProtocol = {}));
|
|
685
693
|
|
|
686
|
-
//
|
|
694
|
+
// node_modules/@smithy/protocol-http/dist-es/httpResponse.js
|
|
687
695
|
var HttpResponse = class {
|
|
688
696
|
constructor(options) {
|
|
689
697
|
this.statusCode = options.statusCode;
|
|
@@ -699,11 +707,11 @@ var HttpResponse = class {
|
|
|
699
707
|
}
|
|
700
708
|
};
|
|
701
709
|
|
|
702
|
-
//
|
|
710
|
+
// node_modules/@smithy/util-uri-escape/dist-es/escape-uri.js
|
|
703
711
|
var escapeUri = (uri) => encodeURIComponent(uri).replace(/[!'()*]/g, hexEncode);
|
|
704
712
|
var hexEncode = (c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`;
|
|
705
713
|
|
|
706
|
-
//
|
|
714
|
+
// node_modules/@smithy/querystring-builder/dist-es/index.js
|
|
707
715
|
function buildQueryString(query) {
|
|
708
716
|
const parts = [];
|
|
709
717
|
for (let key of Object.keys(query).sort()) {
|
|
@@ -724,10 +732,10 @@ function buildQueryString(query) {
|
|
|
724
732
|
return parts.join("&");
|
|
725
733
|
}
|
|
726
734
|
|
|
727
|
-
//
|
|
735
|
+
// node_modules/@smithy/node-http-handler/dist-es/constants.js
|
|
728
736
|
var NODEJS_TIMEOUT_ERROR_CODES = ["ECONNRESET", "EPIPE", "ETIMEDOUT"];
|
|
729
737
|
|
|
730
|
-
//
|
|
738
|
+
// node_modules/@smithy/node-http-handler/dist-es/get-transformed-headers.js
|
|
731
739
|
var getTransformedHeaders = (headers) => {
|
|
732
740
|
const transformedHeaders = {};
|
|
733
741
|
for (const name of Object.keys(headers)) {
|
|
@@ -737,71 +745,123 @@ var getTransformedHeaders = (headers) => {
|
|
|
737
745
|
return transformedHeaders;
|
|
738
746
|
};
|
|
739
747
|
|
|
740
|
-
//
|
|
748
|
+
// node_modules/@smithy/node-http-handler/dist-es/timing.js
|
|
749
|
+
var timing = {
|
|
750
|
+
setTimeout: (cb, ms) => setTimeout(cb, ms),
|
|
751
|
+
clearTimeout: (timeoutId) => clearTimeout(timeoutId)
|
|
752
|
+
};
|
|
753
|
+
|
|
754
|
+
// node_modules/@smithy/node-http-handler/dist-es/set-connection-timeout.js
|
|
755
|
+
var DEFER_EVENT_LISTENER_TIME = 1e3;
|
|
741
756
|
var setConnectionTimeout = (request, reject, timeoutInMs = 0) => {
|
|
742
757
|
if (!timeoutInMs) {
|
|
743
|
-
return;
|
|
758
|
+
return -1;
|
|
744
759
|
}
|
|
745
|
-
const
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
socket.
|
|
754
|
-
|
|
755
|
-
|
|
760
|
+
const registerTimeout = (offset) => {
|
|
761
|
+
const timeoutId = timing.setTimeout(() => {
|
|
762
|
+
request.destroy();
|
|
763
|
+
reject(Object.assign(new Error(`Socket timed out without establishing a connection within ${timeoutInMs} ms`), {
|
|
764
|
+
name: "TimeoutError"
|
|
765
|
+
}));
|
|
766
|
+
}, timeoutInMs - offset);
|
|
767
|
+
const doWithSocket = (socket) => {
|
|
768
|
+
if (socket == null ? void 0 : socket.connecting) {
|
|
769
|
+
socket.on("connect", () => {
|
|
770
|
+
timing.clearTimeout(timeoutId);
|
|
771
|
+
});
|
|
772
|
+
} else {
|
|
773
|
+
timing.clearTimeout(timeoutId);
|
|
774
|
+
}
|
|
775
|
+
};
|
|
776
|
+
if (request.socket) {
|
|
777
|
+
doWithSocket(request.socket);
|
|
756
778
|
} else {
|
|
757
|
-
|
|
779
|
+
request.on("socket", doWithSocket);
|
|
758
780
|
}
|
|
759
|
-
}
|
|
781
|
+
};
|
|
782
|
+
if (timeoutInMs < 2e3) {
|
|
783
|
+
registerTimeout(0);
|
|
784
|
+
return 0;
|
|
785
|
+
}
|
|
786
|
+
return timing.setTimeout(registerTimeout.bind(null, DEFER_EVENT_LISTENER_TIME), DEFER_EVENT_LISTENER_TIME);
|
|
760
787
|
};
|
|
761
788
|
|
|
762
|
-
//
|
|
763
|
-
var
|
|
789
|
+
// node_modules/@smithy/node-http-handler/dist-es/set-socket-keep-alive.js
|
|
790
|
+
var DEFER_EVENT_LISTENER_TIME2 = 3e3;
|
|
791
|
+
var setSocketKeepAlive = (request, { keepAlive, keepAliveMsecs }, deferTimeMs = DEFER_EVENT_LISTENER_TIME2) => {
|
|
764
792
|
if (keepAlive !== true) {
|
|
765
|
-
return;
|
|
793
|
+
return -1;
|
|
766
794
|
}
|
|
767
|
-
|
|
768
|
-
socket
|
|
769
|
-
|
|
795
|
+
const registerListener = () => {
|
|
796
|
+
if (request.socket) {
|
|
797
|
+
request.socket.setKeepAlive(keepAlive, keepAliveMsecs || 0);
|
|
798
|
+
} else {
|
|
799
|
+
request.on("socket", (socket) => {
|
|
800
|
+
socket.setKeepAlive(keepAlive, keepAliveMsecs || 0);
|
|
801
|
+
});
|
|
802
|
+
}
|
|
803
|
+
};
|
|
804
|
+
if (deferTimeMs === 0) {
|
|
805
|
+
registerListener();
|
|
806
|
+
return 0;
|
|
807
|
+
}
|
|
808
|
+
return timing.setTimeout(registerListener, deferTimeMs);
|
|
770
809
|
};
|
|
771
810
|
|
|
772
|
-
//
|
|
773
|
-
var
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
811
|
+
// node_modules/@smithy/node-http-handler/dist-es/set-socket-timeout.js
|
|
812
|
+
var DEFER_EVENT_LISTENER_TIME3 = 3e3;
|
|
813
|
+
var setSocketTimeout = (request, reject, timeoutInMs = DEFAULT_REQUEST_TIMEOUT) => {
|
|
814
|
+
const registerTimeout = (offset) => {
|
|
815
|
+
const timeout = timeoutInMs - offset;
|
|
816
|
+
const onTimeout = () => {
|
|
817
|
+
request.destroy();
|
|
818
|
+
reject(Object.assign(new Error(`Connection timed out after ${timeoutInMs} ms`), { name: "TimeoutError" }));
|
|
819
|
+
};
|
|
820
|
+
if (request.socket) {
|
|
821
|
+
request.socket.setTimeout(timeout, onTimeout);
|
|
822
|
+
request.on("close", () => {
|
|
823
|
+
var _a;
|
|
824
|
+
return (_a = request.socket) == null ? void 0 : _a.removeListener("timeout", onTimeout);
|
|
825
|
+
});
|
|
826
|
+
} else {
|
|
827
|
+
request.setTimeout(timeout, onTimeout);
|
|
828
|
+
}
|
|
829
|
+
};
|
|
830
|
+
if (0 < timeoutInMs && timeoutInMs < 6e3) {
|
|
831
|
+
registerTimeout(0);
|
|
832
|
+
return 0;
|
|
833
|
+
}
|
|
834
|
+
return timing.setTimeout(registerTimeout.bind(null, timeoutInMs === 0 ? 0 : DEFER_EVENT_LISTENER_TIME3), DEFER_EVENT_LISTENER_TIME3);
|
|
778
835
|
};
|
|
779
|
-
var MIN_WAIT_TIME =
|
|
836
|
+
var MIN_WAIT_TIME = 6e3;
|
|
780
837
|
async function writeRequestBody(httpRequest, request, maxContinueTimeoutMs = MIN_WAIT_TIME) {
|
|
781
838
|
var _a;
|
|
782
839
|
const headers = (_a = request.headers) != null ? _a : {};
|
|
783
840
|
const expect = headers["Expect"] || headers["expect"];
|
|
784
841
|
let timeoutId = -1;
|
|
785
|
-
let
|
|
842
|
+
let sendBody = true;
|
|
786
843
|
if (expect === "100-continue") {
|
|
787
|
-
await Promise.race([
|
|
844
|
+
sendBody = await Promise.race([
|
|
788
845
|
new Promise((resolve) => {
|
|
789
|
-
timeoutId = Number(setTimeout(resolve, Math.max(MIN_WAIT_TIME, maxContinueTimeoutMs)));
|
|
846
|
+
timeoutId = Number(timing.setTimeout(() => resolve(true), Math.max(MIN_WAIT_TIME, maxContinueTimeoutMs)));
|
|
790
847
|
}),
|
|
791
848
|
new Promise((resolve) => {
|
|
792
849
|
httpRequest.on("continue", () => {
|
|
793
|
-
clearTimeout(timeoutId);
|
|
794
|
-
resolve();
|
|
850
|
+
timing.clearTimeout(timeoutId);
|
|
851
|
+
resolve(true);
|
|
852
|
+
});
|
|
853
|
+
httpRequest.on("response", () => {
|
|
854
|
+
timing.clearTimeout(timeoutId);
|
|
855
|
+
resolve(false);
|
|
795
856
|
});
|
|
796
857
|
httpRequest.on("error", () => {
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
resolve();
|
|
858
|
+
timing.clearTimeout(timeoutId);
|
|
859
|
+
resolve(false);
|
|
800
860
|
});
|
|
801
861
|
})
|
|
802
862
|
]);
|
|
803
863
|
}
|
|
804
|
-
if (
|
|
864
|
+
if (sendBody) {
|
|
805
865
|
writeBody(httpRequest, request.body);
|
|
806
866
|
}
|
|
807
867
|
}
|
|
@@ -826,7 +886,8 @@ function writeBody(httpRequest, body) {
|
|
|
826
886
|
httpRequest.end();
|
|
827
887
|
}
|
|
828
888
|
|
|
829
|
-
//
|
|
889
|
+
// node_modules/@smithy/node-http-handler/dist-es/node-http-handler.js
|
|
890
|
+
var DEFAULT_REQUEST_TIMEOUT = 0;
|
|
830
891
|
var NodeHttpHandler = class _NodeHttpHandler {
|
|
831
892
|
static create(instanceOrOptions) {
|
|
832
893
|
if (typeof (instanceOrOptions == null ? void 0 : instanceOrOptions.handle) === "function") {
|
|
@@ -834,8 +895,8 @@ var NodeHttpHandler = class _NodeHttpHandler {
|
|
|
834
895
|
}
|
|
835
896
|
return new _NodeHttpHandler(instanceOrOptions);
|
|
836
897
|
}
|
|
837
|
-
static checkSocketUsage(agent, socketWarningTimestamp) {
|
|
838
|
-
var _a, _b, _c, _d;
|
|
898
|
+
static checkSocketUsage(agent, socketWarningTimestamp, logger = console) {
|
|
899
|
+
var _a, _b, _c, _d, _e;
|
|
839
900
|
const { sockets, requests, maxSockets } = agent;
|
|
840
901
|
if (typeof maxSockets !== "number" || maxSockets === Infinity) {
|
|
841
902
|
return socketWarningTimestamp;
|
|
@@ -849,7 +910,9 @@ var NodeHttpHandler = class _NodeHttpHandler {
|
|
|
849
910
|
const socketsInUse = (_b = (_a = sockets[origin]) == null ? void 0 : _a.length) != null ? _b : 0;
|
|
850
911
|
const requestsEnqueued = (_d = (_c = requests[origin]) == null ? void 0 : _c.length) != null ? _d : 0;
|
|
851
912
|
if (socketsInUse >= maxSockets && requestsEnqueued >= 2 * maxSockets) {
|
|
852
|
-
|
|
913
|
+
(_e = logger == null ? void 0 : logger.warn) == null ? void 0 : _e.call(logger, `@smithy/node-http-handler:WARN - socket usage at capacity=${socketsInUse} and ${requestsEnqueued} additional requests are enqueued.
|
|
914
|
+
See https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/node-configuring-maxsockets.html
|
|
915
|
+
or increase socketAcquisitionWarningTimeout=(millis) in the NodeHttpHandler config.`);
|
|
853
916
|
return Date.now();
|
|
854
917
|
}
|
|
855
918
|
}
|
|
@@ -870,12 +933,13 @@ var NodeHttpHandler = class _NodeHttpHandler {
|
|
|
870
933
|
});
|
|
871
934
|
}
|
|
872
935
|
resolveDefaultConfig(options) {
|
|
873
|
-
const { requestTimeout, connectionTimeout, socketTimeout, httpAgent, httpsAgent } = options || {};
|
|
936
|
+
const { requestTimeout, connectionTimeout, socketTimeout, socketAcquisitionWarningTimeout, httpAgent, httpsAgent } = options || {};
|
|
874
937
|
const keepAlive = true;
|
|
875
938
|
const maxSockets = 50;
|
|
876
939
|
return {
|
|
877
940
|
connectionTimeout,
|
|
878
941
|
requestTimeout: requestTimeout != null ? requestTimeout : socketTimeout,
|
|
942
|
+
socketAcquisitionWarningTimeout,
|
|
879
943
|
httpAgent: (() => {
|
|
880
944
|
if (httpAgent instanceof Agent || typeof (httpAgent == null ? void 0 : httpAgent.destroy) === "function") {
|
|
881
945
|
return httpAgent;
|
|
@@ -887,7 +951,8 @@ var NodeHttpHandler = class _NodeHttpHandler {
|
|
|
887
951
|
return httpsAgent;
|
|
888
952
|
}
|
|
889
953
|
return new Agent$1(__spreadValues({ keepAlive, maxSockets }, httpsAgent));
|
|
890
|
-
})()
|
|
954
|
+
})(),
|
|
955
|
+
logger: console
|
|
891
956
|
};
|
|
892
957
|
}
|
|
893
958
|
destroy() {
|
|
@@ -895,21 +960,22 @@ var NodeHttpHandler = class _NodeHttpHandler {
|
|
|
895
960
|
(_b = (_a = this.config) == null ? void 0 : _a.httpAgent) == null ? void 0 : _b.destroy();
|
|
896
961
|
(_d = (_c = this.config) == null ? void 0 : _c.httpsAgent) == null ? void 0 : _d.destroy();
|
|
897
962
|
}
|
|
898
|
-
async handle(request$2, { abortSignal } = {}) {
|
|
963
|
+
async handle(request$2, { abortSignal, requestTimeout } = {}) {
|
|
899
964
|
if (!this.config) {
|
|
900
965
|
this.config = await this.configProvider;
|
|
901
966
|
}
|
|
902
|
-
let socketCheckTimeoutId;
|
|
903
967
|
return new Promise((_resolve, _reject) => {
|
|
904
|
-
var _a, _b, _c, _d, _e;
|
|
968
|
+
var _a, _b, _c, _d, _e, _f;
|
|
905
969
|
let writeRequestBodyPromise = void 0;
|
|
970
|
+
const timeouts = [];
|
|
906
971
|
const resolve = async (arg) => {
|
|
907
972
|
await writeRequestBodyPromise;
|
|
908
|
-
clearTimeout
|
|
973
|
+
timeouts.forEach(timing.clearTimeout);
|
|
909
974
|
_resolve(arg);
|
|
910
975
|
};
|
|
911
976
|
const reject = async (arg) => {
|
|
912
977
|
await writeRequestBodyPromise;
|
|
978
|
+
timeouts.forEach(timing.clearTimeout);
|
|
913
979
|
_reject(arg);
|
|
914
980
|
};
|
|
915
981
|
if (!this.config) {
|
|
@@ -923,9 +989,9 @@ var NodeHttpHandler = class _NodeHttpHandler {
|
|
|
923
989
|
}
|
|
924
990
|
const isSSL = request$2.protocol === "https:";
|
|
925
991
|
const agent = isSSL ? this.config.httpsAgent : this.config.httpAgent;
|
|
926
|
-
|
|
927
|
-
this.socketWarningTimestamp = _NodeHttpHandler.checkSocketUsage(agent, this.socketWarningTimestamp);
|
|
928
|
-
}, (_c = this.config.socketAcquisitionWarningTimeout) != null ? _c : ((_a = this.config.requestTimeout) != null ? _a : 2e3) + ((_b = this.config.connectionTimeout) != null ? _b : 1e3));
|
|
992
|
+
timeouts.push(timing.setTimeout(() => {
|
|
993
|
+
this.socketWarningTimestamp = _NodeHttpHandler.checkSocketUsage(agent, this.socketWarningTimestamp, this.config.logger);
|
|
994
|
+
}, (_c = this.config.socketAcquisitionWarningTimeout) != null ? _c : ((_a = this.config.requestTimeout) != null ? _a : 2e3) + ((_b = this.config.connectionTimeout) != null ? _b : 1e3)));
|
|
929
995
|
const queryString = buildQueryString(request$2.query || {});
|
|
930
996
|
let auth = void 0;
|
|
931
997
|
if (request$2.username != null || request$2.password != null) {
|
|
@@ -940,9 +1006,15 @@ var NodeHttpHandler = class _NodeHttpHandler {
|
|
|
940
1006
|
if (request$2.fragment) {
|
|
941
1007
|
path += `#${request$2.fragment}`;
|
|
942
1008
|
}
|
|
1009
|
+
let hostname = (_f = request$2.hostname) != null ? _f : "";
|
|
1010
|
+
if (hostname[0] === "[" && hostname.endsWith("]")) {
|
|
1011
|
+
hostname = request$2.hostname.slice(1, -1);
|
|
1012
|
+
} else {
|
|
1013
|
+
hostname = request$2.hostname;
|
|
1014
|
+
}
|
|
943
1015
|
const nodeHttpsOptions = {
|
|
944
1016
|
headers: request$2.headers,
|
|
945
|
-
host:
|
|
1017
|
+
host: hostname,
|
|
946
1018
|
method: request$2.method,
|
|
947
1019
|
path,
|
|
948
1020
|
port: request$2.port,
|
|
@@ -966,24 +1038,35 @@ var NodeHttpHandler = class _NodeHttpHandler {
|
|
|
966
1038
|
reject(err);
|
|
967
1039
|
}
|
|
968
1040
|
});
|
|
969
|
-
setConnectionTimeout(req, reject, this.config.connectionTimeout);
|
|
970
|
-
setSocketTimeout(req, reject, this.config.requestTimeout);
|
|
971
1041
|
if (abortSignal) {
|
|
972
|
-
|
|
973
|
-
req.
|
|
1042
|
+
const onAbort = () => {
|
|
1043
|
+
req.destroy();
|
|
974
1044
|
const abortError = new Error("Request aborted");
|
|
975
1045
|
abortError.name = "AbortError";
|
|
976
1046
|
reject(abortError);
|
|
977
1047
|
};
|
|
1048
|
+
if (typeof abortSignal.addEventListener === "function") {
|
|
1049
|
+
const signal = abortSignal;
|
|
1050
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
1051
|
+
req.once("close", () => signal.removeEventListener("abort", onAbort));
|
|
1052
|
+
} else {
|
|
1053
|
+
abortSignal.onabort = onAbort;
|
|
1054
|
+
}
|
|
978
1055
|
}
|
|
1056
|
+
const effectiveRequestTimeout = requestTimeout != null ? requestTimeout : this.config.requestTimeout;
|
|
1057
|
+
timeouts.push(setConnectionTimeout(req, reject, this.config.connectionTimeout));
|
|
1058
|
+
timeouts.push(setSocketTimeout(req, reject, effectiveRequestTimeout));
|
|
979
1059
|
const httpAgent = nodeHttpsOptions.agent;
|
|
980
1060
|
if (typeof httpAgent === "object" && "keepAlive" in httpAgent) {
|
|
981
|
-
setSocketKeepAlive(req, {
|
|
1061
|
+
timeouts.push(setSocketKeepAlive(req, {
|
|
982
1062
|
keepAlive: httpAgent.keepAlive,
|
|
983
1063
|
keepAliveMsecs: httpAgent.keepAliveMsecs
|
|
984
|
-
});
|
|
1064
|
+
}));
|
|
985
1065
|
}
|
|
986
|
-
writeRequestBodyPromise = writeRequestBody(req, request$2,
|
|
1066
|
+
writeRequestBodyPromise = writeRequestBody(req, request$2, effectiveRequestTimeout).catch((e) => {
|
|
1067
|
+
timeouts.forEach(timing.clearTimeout);
|
|
1068
|
+
return _reject(e);
|
|
1069
|
+
});
|
|
987
1070
|
});
|
|
988
1071
|
}
|
|
989
1072
|
updateHttpClientConfig(key, value) {
|
|
@@ -1008,11 +1091,13 @@ var S3StorageService = class {
|
|
|
1008
1091
|
});
|
|
1009
1092
|
this.s3Client = new S3Client({
|
|
1010
1093
|
region: process.env.AWS_DEFAULT_REGION,
|
|
1011
|
-
requestHandler: this.httpHandler
|
|
1094
|
+
requestHandler: this.httpHandler,
|
|
1095
|
+
credentials: defaultProvider()
|
|
1012
1096
|
});
|
|
1013
1097
|
this.s3 = new S3({
|
|
1014
1098
|
region: process.env.AWS_DEFAULT_REGION,
|
|
1015
|
-
requestHandler: this.httpHandler
|
|
1099
|
+
requestHandler: this.httpHandler,
|
|
1100
|
+
credentials: defaultProvider()
|
|
1016
1101
|
});
|
|
1017
1102
|
var _a, _b, _c, _d;
|
|
1018
1103
|
this.bucketName = bucketName;
|
|
@@ -1180,6 +1265,22 @@ var S3StorageService = class {
|
|
|
1180
1265
|
* @returns A promise that resolves to the response containing the key of the uploaded object.
|
|
1181
1266
|
*/
|
|
1182
1267
|
async upload(key, body, metadata) {
|
|
1268
|
+
if (body instanceof stream2.Readable) {
|
|
1269
|
+
const upload = new Upload({
|
|
1270
|
+
client: this.s3Client,
|
|
1271
|
+
params: {
|
|
1272
|
+
Bucket: this.bucketName,
|
|
1273
|
+
Key: key,
|
|
1274
|
+
Body: body,
|
|
1275
|
+
Metadata: metadata
|
|
1276
|
+
},
|
|
1277
|
+
queueSize: 5,
|
|
1278
|
+
partSize: 8 * 1024 * 1024
|
|
1279
|
+
// 8MB parts
|
|
1280
|
+
});
|
|
1281
|
+
await upload.done();
|
|
1282
|
+
return { key };
|
|
1283
|
+
}
|
|
1183
1284
|
const command = new PutObjectCommand({
|
|
1184
1285
|
Bucket: this.bucketName,
|
|
1185
1286
|
Key: key,
|
|
@@ -1195,13 +1296,12 @@ var S3StorageService = class {
|
|
|
1195
1296
|
* @param {string} key - The key of the object to upload.
|
|
1196
1297
|
* @return {CreateUploadWriteStreamResponse} An object containing the key of the uploaded object, the writable stream, and a promise that resolves when the upload is complete.
|
|
1197
1298
|
*/
|
|
1198
|
-
createUploadWriteStream(key
|
|
1199
|
-
const
|
|
1200
|
-
const streamResponse = streamPassThrough != null ? streamPassThrough : streamPass;
|
|
1299
|
+
createUploadWriteStream(key) {
|
|
1300
|
+
const streamPassThrough = new stream2.PassThrough();
|
|
1201
1301
|
const params = {
|
|
1202
1302
|
Bucket: this.bucketName,
|
|
1203
1303
|
Key: key,
|
|
1204
|
-
Body:
|
|
1304
|
+
Body: streamPassThrough
|
|
1205
1305
|
};
|
|
1206
1306
|
const upload = new Upload({
|
|
1207
1307
|
client: this.s3Client,
|
|
@@ -1211,7 +1311,7 @@ var S3StorageService = class {
|
|
|
1211
1311
|
});
|
|
1212
1312
|
return {
|
|
1213
1313
|
key,
|
|
1214
|
-
stream:
|
|
1314
|
+
stream: streamPassThrough,
|
|
1215
1315
|
promise: upload.done()
|
|
1216
1316
|
};
|
|
1217
1317
|
}
|
|
@@ -1359,11 +1459,341 @@ var S3StorageService = class {
|
|
|
1359
1459
|
return presignedUrl;
|
|
1360
1460
|
}
|
|
1361
1461
|
};
|
|
1462
|
+
var SftpClient = __require("ssh2-sftp-client");
|
|
1463
|
+
var SftpStorageService = class {
|
|
1464
|
+
constructor(bucketName, options) {
|
|
1465
|
+
this.bucketName = bucketName;
|
|
1466
|
+
this.options = options || {};
|
|
1467
|
+
this.client = new SftpClient();
|
|
1468
|
+
}
|
|
1469
|
+
async initializeClient() {
|
|
1470
|
+
const host = this.options.host || process.env.SFTP_HOST;
|
|
1471
|
+
const port = parseInt(
|
|
1472
|
+
String(this.options.port || process.env.SFTP_PORT)
|
|
1473
|
+
);
|
|
1474
|
+
const user = this.options.user || process.env.SFTP_USER;
|
|
1475
|
+
const password = this.options.password || process.env.SFTP_PASSWORD;
|
|
1476
|
+
const privateKey = this.options.privateKey || process.env.SFTP_PRIVATE_KEY;
|
|
1477
|
+
if (!password && !privateKey) {
|
|
1478
|
+
throw new Error(
|
|
1479
|
+
"Either password or private key must be provided for SFTP connection"
|
|
1480
|
+
);
|
|
1481
|
+
}
|
|
1482
|
+
await this.client.connect({
|
|
1483
|
+
host,
|
|
1484
|
+
port,
|
|
1485
|
+
username: user,
|
|
1486
|
+
password,
|
|
1487
|
+
privateKey,
|
|
1488
|
+
readyTimeout: 4e3,
|
|
1489
|
+
retries: 1,
|
|
1490
|
+
retry_factor: 2,
|
|
1491
|
+
retry_minTimeout: 2e3
|
|
1492
|
+
});
|
|
1493
|
+
}
|
|
1494
|
+
async withClient(fn) {
|
|
1495
|
+
try {
|
|
1496
|
+
await this.initializeClient();
|
|
1497
|
+
return await fn();
|
|
1498
|
+
} finally {
|
|
1499
|
+
await this.client.end().catch(() => {
|
|
1500
|
+
});
|
|
1501
|
+
}
|
|
1502
|
+
}
|
|
1503
|
+
async list(options) {
|
|
1504
|
+
return this.withClient(async () => {
|
|
1505
|
+
const prefix = options.prefix || "";
|
|
1506
|
+
const path = this.bucketName + (prefix ? "/" + prefix : "");
|
|
1507
|
+
const list = await this.client.list(path);
|
|
1508
|
+
const items = list.map((item) => ({
|
|
1509
|
+
key: item.name,
|
|
1510
|
+
lastModified: item.modifyTime ? new Date(item.modifyTime) : /* @__PURE__ */ new Date(),
|
|
1511
|
+
size: item.size,
|
|
1512
|
+
eTag: ""
|
|
1513
|
+
}));
|
|
1514
|
+
return {
|
|
1515
|
+
items,
|
|
1516
|
+
pagination: null,
|
|
1517
|
+
count: items.length
|
|
1518
|
+
};
|
|
1519
|
+
});
|
|
1520
|
+
}
|
|
1521
|
+
async ensureDirectoriesExist(remotePath) {
|
|
1522
|
+
var _a, _b;
|
|
1523
|
+
const parts = remotePath.split("/");
|
|
1524
|
+
parts.pop();
|
|
1525
|
+
let current = "";
|
|
1526
|
+
for (const part of parts) {
|
|
1527
|
+
if (!part)
|
|
1528
|
+
continue;
|
|
1529
|
+
current += `/${part}`;
|
|
1530
|
+
try {
|
|
1531
|
+
await this.client.stat(current);
|
|
1532
|
+
} catch (err) {
|
|
1533
|
+
const isNoEntry = err.code === "ENOENT" || ((_a = err.message) == null ? void 0 : _a.includes("No such file")) || ((_b = err.message) == null ? void 0 : _b.includes("does not exist"));
|
|
1534
|
+
if (isNoEntry) {
|
|
1535
|
+
try {
|
|
1536
|
+
await this.client.mkdir(current);
|
|
1537
|
+
} catch (mkdirErr) {
|
|
1538
|
+
throw new Error(
|
|
1539
|
+
`Failed to create directory ${current}: ${mkdirErr.message}`
|
|
1540
|
+
);
|
|
1541
|
+
}
|
|
1542
|
+
} else {
|
|
1543
|
+
throw new Error(
|
|
1544
|
+
`Failed to check directory ${current}: ${err.message}`
|
|
1545
|
+
);
|
|
1546
|
+
}
|
|
1547
|
+
}
|
|
1548
|
+
}
|
|
1549
|
+
}
|
|
1550
|
+
async upload(key, body) {
|
|
1551
|
+
return this.withClient(async () => {
|
|
1552
|
+
let remotePath = `${this.bucketName}/${key}`;
|
|
1553
|
+
remotePath = remotePath + "";
|
|
1554
|
+
await this.ensureDirectoriesExist(remotePath);
|
|
1555
|
+
if (body instanceof Readable) {
|
|
1556
|
+
await this.client.put(body, remotePath);
|
|
1557
|
+
} else if (body instanceof Buffer) {
|
|
1558
|
+
await this.client.put(Buffer.from(body), remotePath);
|
|
1559
|
+
} else {
|
|
1560
|
+
await this.client.put(Buffer.from(String(body)), remotePath);
|
|
1561
|
+
}
|
|
1562
|
+
return { key };
|
|
1563
|
+
});
|
|
1564
|
+
}
|
|
1565
|
+
async delete(key) {
|
|
1566
|
+
return this.withClient(async () => {
|
|
1567
|
+
await this.client.delete(`${this.bucketName}/${key}`);
|
|
1568
|
+
return true;
|
|
1569
|
+
});
|
|
1570
|
+
}
|
|
1571
|
+
async getObject(key) {
|
|
1572
|
+
await this.initializeClient();
|
|
1573
|
+
const remotePath = `${this.bucketName}/${key}`;
|
|
1574
|
+
const stats = await this.client.stat(remotePath);
|
|
1575
|
+
const data = await this.client.get(remotePath);
|
|
1576
|
+
let stream3;
|
|
1577
|
+
if (Buffer.isBuffer(data) || typeof data === "string") {
|
|
1578
|
+
stream3 = Readable.from(data);
|
|
1579
|
+
} else if (data instanceof Readable) {
|
|
1580
|
+
stream3 = data;
|
|
1581
|
+
} else {
|
|
1582
|
+
throw new Error("Unsupported stream type returned by SFTP client");
|
|
1583
|
+
}
|
|
1584
|
+
const cleanup = async () => {
|
|
1585
|
+
try {
|
|
1586
|
+
await this.client.end();
|
|
1587
|
+
} catch (e) {
|
|
1588
|
+
}
|
|
1589
|
+
};
|
|
1590
|
+
stream3.on("end", cleanup);
|
|
1591
|
+
stream3.on("error", cleanup);
|
|
1592
|
+
return {
|
|
1593
|
+
body: stream3,
|
|
1594
|
+
contentLength: stats.size,
|
|
1595
|
+
lastModified: stats.modifyTime ? new Date(stats.modifyTime) : /* @__PURE__ */ new Date(),
|
|
1596
|
+
metadata: {}
|
|
1597
|
+
};
|
|
1598
|
+
}
|
|
1599
|
+
listAll(options) {
|
|
1600
|
+
throw new Error("Method not implemented.");
|
|
1601
|
+
}
|
|
1602
|
+
getHeadObject(key) {
|
|
1603
|
+
throw new Error("Method not implemented.");
|
|
1604
|
+
}
|
|
1605
|
+
getDownloadUrl(key, expiresInMinutes) {
|
|
1606
|
+
throw new Error("Method not implemented.");
|
|
1607
|
+
}
|
|
1608
|
+
getUploadUrl(key, expiresInMinutes) {
|
|
1609
|
+
throw new Error("Method not implemented.");
|
|
1610
|
+
}
|
|
1611
|
+
createUploadWriteStream(key) {
|
|
1612
|
+
throw new Error("Method not implemented.");
|
|
1613
|
+
}
|
|
1614
|
+
getHeadBucket() {
|
|
1615
|
+
throw new Error("Method not implemented.");
|
|
1616
|
+
}
|
|
1617
|
+
generateUploadIdMultipart(key) {
|
|
1618
|
+
throw new Error("Method not implemented.");
|
|
1619
|
+
}
|
|
1620
|
+
listMultipartUploadsForBucket() {
|
|
1621
|
+
throw new Error("Method not implemented.");
|
|
1622
|
+
}
|
|
1623
|
+
listMultipartUploadsForKey(key, uploadId) {
|
|
1624
|
+
throw new Error("Method not implemented.");
|
|
1625
|
+
}
|
|
1626
|
+
uploadMultipart(key, file, partNumber, uploadId) {
|
|
1627
|
+
throw new Error("Method not implemented.");
|
|
1628
|
+
}
|
|
1629
|
+
completeMultipartUpload(key, uploadId) {
|
|
1630
|
+
throw new Error("Method not implemented.");
|
|
1631
|
+
}
|
|
1632
|
+
abortMultipartUpload(key, uploadId) {
|
|
1633
|
+
throw new Error("Method not implemented.");
|
|
1634
|
+
}
|
|
1635
|
+
getMultipartUploadPresignedUrl(key, uploadId, partNumber, expiresInMinutes) {
|
|
1636
|
+
throw new Error("Method not implemented.");
|
|
1637
|
+
}
|
|
1638
|
+
};
|
|
1639
|
+
var FtpStorageService = class {
|
|
1640
|
+
constructor(bucketName, options) {
|
|
1641
|
+
this.bucketName = bucketName;
|
|
1642
|
+
this.options = options || {};
|
|
1643
|
+
this.client = new Client();
|
|
1644
|
+
}
|
|
1645
|
+
listAll(options) {
|
|
1646
|
+
throw new Error("Method not implemented.");
|
|
1647
|
+
}
|
|
1648
|
+
async initializeClient() {
|
|
1649
|
+
var _a, _b, _c, _d, _e;
|
|
1650
|
+
const host = ((_a = this == null ? void 0 : this.options) == null ? void 0 : _a.host) || process.env.FTP_HOST;
|
|
1651
|
+
const port = parseInt(
|
|
1652
|
+
String(((_b = this == null ? void 0 : this.options) == null ? void 0 : _b.port) || process.env.FTP_PORT),
|
|
1653
|
+
10
|
|
1654
|
+
);
|
|
1655
|
+
const user = ((_c = this == null ? void 0 : this.options) == null ? void 0 : _c.user) || process.env.FTP_USER;
|
|
1656
|
+
const password = ((_d = this == null ? void 0 : this.options) == null ? void 0 : _d.password) || process.env.FTP_PASSWORD;
|
|
1657
|
+
await this.client.access({
|
|
1658
|
+
host,
|
|
1659
|
+
port,
|
|
1660
|
+
user,
|
|
1661
|
+
password,
|
|
1662
|
+
secure: ((_e = this == null ? void 0 : this.options) == null ? void 0 : _e.secure) || false
|
|
1663
|
+
});
|
|
1664
|
+
}
|
|
1665
|
+
async withClient(fn) {
|
|
1666
|
+
try {
|
|
1667
|
+
await this.initializeClient();
|
|
1668
|
+
return await fn();
|
|
1669
|
+
} finally {
|
|
1670
|
+
this.client.close();
|
|
1671
|
+
}
|
|
1672
|
+
}
|
|
1673
|
+
async list(options) {
|
|
1674
|
+
return this.withClient(async () => {
|
|
1675
|
+
const prefix = options.prefix || "";
|
|
1676
|
+
const path = `${this.bucketName}/${prefix}`;
|
|
1677
|
+
try {
|
|
1678
|
+
const list = await this.client.list(path);
|
|
1679
|
+
const items = list.map(
|
|
1680
|
+
(item) => ({
|
|
1681
|
+
key: prefix + item.name,
|
|
1682
|
+
lastModified: item.modifiedAt || /* @__PURE__ */ new Date(),
|
|
1683
|
+
size: item.size,
|
|
1684
|
+
eTag: ""
|
|
1685
|
+
})
|
|
1686
|
+
);
|
|
1687
|
+
return {
|
|
1688
|
+
items,
|
|
1689
|
+
pagination: null,
|
|
1690
|
+
count: items.length
|
|
1691
|
+
};
|
|
1692
|
+
} catch (e) {
|
|
1693
|
+
return { items: [], pagination: null, count: 0 };
|
|
1694
|
+
}
|
|
1695
|
+
});
|
|
1696
|
+
}
|
|
1697
|
+
async getObject(key) {
|
|
1698
|
+
await this.initializeClient();
|
|
1699
|
+
const passThrough = new PassThrough();
|
|
1700
|
+
const path = `${this.bucketName}/${key}`;
|
|
1701
|
+
const stats = await this.client.size(path);
|
|
1702
|
+
this.client.downloadTo(passThrough, path).then(() => passThrough.end()).catch((err) => passThrough.emit("error", err));
|
|
1703
|
+
const cleanup = () => {
|
|
1704
|
+
this.client.close();
|
|
1705
|
+
};
|
|
1706
|
+
passThrough.on("end", cleanup);
|
|
1707
|
+
passThrough.on("error", cleanup);
|
|
1708
|
+
return {
|
|
1709
|
+
body: passThrough,
|
|
1710
|
+
contentLength: stats,
|
|
1711
|
+
lastModified: /* @__PURE__ */ new Date(),
|
|
1712
|
+
metadata: {}
|
|
1713
|
+
};
|
|
1714
|
+
}
|
|
1715
|
+
async upload(key, body) {
|
|
1716
|
+
return this.withClient(async () => {
|
|
1717
|
+
await this.client.cd("/");
|
|
1718
|
+
try {
|
|
1719
|
+
await this.client.cd(this.bucketName);
|
|
1720
|
+
} catch (e) {
|
|
1721
|
+
await this.client.send(`MKD ${this.bucketName}`);
|
|
1722
|
+
await this.client.cd(this.bucketName);
|
|
1723
|
+
}
|
|
1724
|
+
const parts = key.split("/");
|
|
1725
|
+
parts.pop();
|
|
1726
|
+
for (const part of parts) {
|
|
1727
|
+
if (!part)
|
|
1728
|
+
continue;
|
|
1729
|
+
try {
|
|
1730
|
+
await this.client.cd(part);
|
|
1731
|
+
} catch (e) {
|
|
1732
|
+
await this.client.send(`MKD ${part}`);
|
|
1733
|
+
await this.client.cd(part);
|
|
1734
|
+
}
|
|
1735
|
+
}
|
|
1736
|
+
await this.client.cd("/");
|
|
1737
|
+
const fullPath = `${this.bucketName}/${key}`;
|
|
1738
|
+
const stream3 = body instanceof Readable ? body : Readable.from([body]);
|
|
1739
|
+
await this.client.uploadFrom(stream3, fullPath);
|
|
1740
|
+
return { key };
|
|
1741
|
+
});
|
|
1742
|
+
}
|
|
1743
|
+
async delete(key) {
|
|
1744
|
+
return this.withClient(async () => {
|
|
1745
|
+
await this.client.remove(`${this.bucketName}/${key}`);
|
|
1746
|
+
return true;
|
|
1747
|
+
});
|
|
1748
|
+
}
|
|
1749
|
+
async close() {
|
|
1750
|
+
this.client.close();
|
|
1751
|
+
}
|
|
1752
|
+
// Unsupported Operations
|
|
1753
|
+
async getDownloadUrl(_key, _expiresInMinutes) {
|
|
1754
|
+
throw new Error("FTP does not support pre-signed URLs");
|
|
1755
|
+
}
|
|
1756
|
+
async getUploadUrl(_key, _expiresInMinutes) {
|
|
1757
|
+
throw new Error("FTP does not support pre-signed URLs");
|
|
1758
|
+
}
|
|
1759
|
+
async getHeadObject(_key) {
|
|
1760
|
+
throw new Error("Operation not supported");
|
|
1761
|
+
}
|
|
1762
|
+
createUploadWriteStream(_key) {
|
|
1763
|
+
throw new Error("Operation not supported");
|
|
1764
|
+
}
|
|
1765
|
+
async getHeadBucket() {
|
|
1766
|
+
throw new Error("Operation not supported");
|
|
1767
|
+
}
|
|
1768
|
+
async generateUploadIdMultipart(_key) {
|
|
1769
|
+
throw new Error("Multipart upload is not supported");
|
|
1770
|
+
}
|
|
1771
|
+
async listMultipartUploadsForBucket() {
|
|
1772
|
+
throw new Error("Multipart upload is not supported");
|
|
1773
|
+
}
|
|
1774
|
+
async listMultipartUploadsForKey(_key, _uploadId) {
|
|
1775
|
+
throw new Error("Multipart upload is not supported");
|
|
1776
|
+
}
|
|
1777
|
+
async uploadMultipart(_key, _file, _partNumber, _uploadId) {
|
|
1778
|
+
throw new Error("Multipart upload is not supported");
|
|
1779
|
+
}
|
|
1780
|
+
async completeMultipartUpload(_key, _uploadId) {
|
|
1781
|
+
throw new Error("Multipart upload is not supported");
|
|
1782
|
+
}
|
|
1783
|
+
async abortMultipartUpload(_key, _uploadId) {
|
|
1784
|
+
throw new Error("Method not implemented.");
|
|
1785
|
+
}
|
|
1786
|
+
async getMultipartUploadPresignedUrl(_key, _uploadId, _partNumber, _expiresInMinutes) {
|
|
1787
|
+
throw new Error("Multipart upload is not supported");
|
|
1788
|
+
}
|
|
1789
|
+
};
|
|
1362
1790
|
|
|
1363
1791
|
// src/shared/utils/constants.ts
|
|
1364
1792
|
var OBJECT_STORAGE_SERVICE_TYPES = {
|
|
1365
1793
|
AWS_S3: "aws_s3",
|
|
1366
|
-
AZURE_BLOB_STORAGE: "azure_blob_storage"
|
|
1794
|
+
AZURE_BLOB_STORAGE: "azure_blob_storage",
|
|
1795
|
+
FTP: "ftp",
|
|
1796
|
+
SFTP: "sftp"
|
|
1367
1797
|
};
|
|
1368
1798
|
|
|
1369
1799
|
// src/services/objectStorageFactory.service.ts
|
|
@@ -1375,7 +1805,11 @@ var ObjectStorageFactory = class {
|
|
|
1375
1805
|
case OBJECT_STORAGE_SERVICE_TYPES.AWS_S3:
|
|
1376
1806
|
return new S3StorageService(bucketName, options);
|
|
1377
1807
|
case OBJECT_STORAGE_SERVICE_TYPES.AZURE_BLOB_STORAGE:
|
|
1378
|
-
return new BlobStorageService(bucketName);
|
|
1808
|
+
return new BlobStorageService(bucketName, options);
|
|
1809
|
+
case OBJECT_STORAGE_SERVICE_TYPES.FTP:
|
|
1810
|
+
return new FtpStorageService(bucketName, options);
|
|
1811
|
+
case OBJECT_STORAGE_SERVICE_TYPES.SFTP:
|
|
1812
|
+
return new SftpStorageService(bucketName, options);
|
|
1379
1813
|
default:
|
|
1380
1814
|
throw new Error(
|
|
1381
1815
|
`Unsupported object storage provider: ${provider}`
|
|
@@ -1401,11 +1835,13 @@ var ObjectStorageService = class _ObjectStorageService {
|
|
|
1401
1835
|
*
|
|
1402
1836
|
* @param {ListRequestOptions} options - The options to apply to the list operation.
|
|
1403
1837
|
* @param {string} [bucketName] - The name of the bucket to list objects from. If not provided, the default bucket name will be used.
|
|
1838
|
+
* @param {ObjectStorageOptions} [objectStorageOptions] - The options for the object storage service.
|
|
1404
1839
|
* @return {Promise<ListResponse>} A promise that resolves to the list of objects.
|
|
1405
1840
|
*/
|
|
1406
|
-
static async list(options, bucketName) {
|
|
1841
|
+
static async list(options, bucketName, objectStorageOptions) {
|
|
1407
1842
|
return _ObjectStorageService.getObjectStorageServiceInstance(
|
|
1408
|
-
bucketName
|
|
1843
|
+
bucketName,
|
|
1844
|
+
objectStorageOptions
|
|
1409
1845
|
).then((instance) => instance.list(options));
|
|
1410
1846
|
}
|
|
1411
1847
|
/**
|
|
@@ -1413,11 +1849,13 @@ var ObjectStorageService = class _ObjectStorageService {
|
|
|
1413
1849
|
*
|
|
1414
1850
|
* @param {ListRequestOptions} options - The options to apply to the list operation.
|
|
1415
1851
|
* @param {string} [bucketName] - The name of the bucket to list objects from. If not provided, the default bucket name will be used.
|
|
1852
|
+
* @param {ObjectStorageOptions} [objectStorageOptions] - The options for the object storage service.
|
|
1416
1853
|
* @return {Promise<ListResponse>} A promise that resolves to the list of all objects.
|
|
1417
1854
|
*/
|
|
1418
|
-
static async listAll(options, bucketName) {
|
|
1855
|
+
static async listAll(options, bucketName, objectStorageOptions) {
|
|
1419
1856
|
return _ObjectStorageService.getObjectStorageServiceInstance(
|
|
1420
|
-
bucketName
|
|
1857
|
+
bucketName,
|
|
1858
|
+
objectStorageOptions
|
|
1421
1859
|
).then((instance) => instance.listAll(options));
|
|
1422
1860
|
}
|
|
1423
1861
|
/**
|
|
@@ -1425,21 +1863,27 @@ var ObjectStorageService = class _ObjectStorageService {
|
|
|
1425
1863
|
*
|
|
1426
1864
|
* @param {string} key - The key of the object to retrieve.
|
|
1427
1865
|
* @param {string} [bucketName] - The name of the bucket where the object is stored. If not provided, the default bucket name will be used.
|
|
1866
|
+
* @param {IGetObjectOptions} [options] - The options to apply to the get operation.
|
|
1867
|
+
* @param {ObjectStorageOptions} [objectStorageOptions] - The options for the object storage service.
|
|
1428
1868
|
* @return {Promise<GetObjectResponse>} A promise that resolves to the retrieved object.
|
|
1429
1869
|
*/
|
|
1430
|
-
static async getObject(key, bucketName, options) {
|
|
1870
|
+
static async getObject(key, bucketName, options, objectStorageOptions) {
|
|
1431
1871
|
return _ObjectStorageService.getObjectStorageServiceInstance(
|
|
1432
|
-
bucketName
|
|
1872
|
+
bucketName,
|
|
1873
|
+
objectStorageOptions
|
|
1433
1874
|
).then((instance) => instance.getObject(key, options));
|
|
1434
1875
|
}
|
|
1435
1876
|
/**
|
|
1436
1877
|
* Retrieves an object info (without file content) from the object storage service.
|
|
1437
1878
|
* @param key - The key of the object to retrieve.
|
|
1879
|
+
* @param bucketName - The name of the bucket where the object is stored. If not provided, the default bucket name will be used.
|
|
1880
|
+
* @param objectStorageOptions - The options for the object storage service.
|
|
1438
1881
|
* @returns A promise that resolves to the info of the file.
|
|
1439
1882
|
*/
|
|
1440
|
-
static async getHeadObject(key, bucketName) {
|
|
1883
|
+
static async getHeadObject(key, bucketName, objectStorageOptions) {
|
|
1441
1884
|
return _ObjectStorageService.getObjectStorageServiceInstance(
|
|
1442
|
-
bucketName
|
|
1885
|
+
bucketName,
|
|
1886
|
+
objectStorageOptions
|
|
1443
1887
|
).then((instance) => instance.getHeadObject(key));
|
|
1444
1888
|
}
|
|
1445
1889
|
/**
|
|
@@ -1448,11 +1892,13 @@ var ObjectStorageService = class _ObjectStorageService {
|
|
|
1448
1892
|
* @param {string} key - The key of the object for which to generate the signed URL.
|
|
1449
1893
|
* @param {number} expiresInMinutes - The number of minutes until the signed URL expires.
|
|
1450
1894
|
* @param {string} [bucketName] - The name of the bucket where the object is stored. If not provided, the default bucket name will be used.
|
|
1895
|
+
* @param {ObjectStorageOptions} [objectStorageOptions] - The options for the object storage service.
|
|
1451
1896
|
* @return {Promise<string>} A promise that resolves to the generated signed URL.
|
|
1452
1897
|
*/
|
|
1453
|
-
static async getDownloadUrl(key, expiresInMinutes, bucketName) {
|
|
1898
|
+
static async getDownloadUrl(key, expiresInMinutes, bucketName, objectStorageOptions) {
|
|
1454
1899
|
return _ObjectStorageService.getObjectStorageServiceInstance(
|
|
1455
|
-
bucketName
|
|
1900
|
+
bucketName,
|
|
1901
|
+
objectStorageOptions
|
|
1456
1902
|
).then((instance) => instance.getDownloadUrl(key, expiresInMinutes));
|
|
1457
1903
|
}
|
|
1458
1904
|
/**
|
|
@@ -1461,11 +1907,13 @@ var ObjectStorageService = class _ObjectStorageService {
|
|
|
1461
1907
|
* @param {string} key - The key of the object for which to generate the upload URL.
|
|
1462
1908
|
* @param {number} expiresInMinutes - The number of minutes until the upload URL expires.
|
|
1463
1909
|
* @param {string} [bucketName] - The name of the bucket where the object will be stored. If not provided, the default bucket name will be used.
|
|
1910
|
+
* @param {ObjectStorageOptions} [objectStorageOptions] - The options for the object storage service.
|
|
1464
1911
|
* @return {Promise<string>} A promise that resolves to the generated upload URL.
|
|
1465
1912
|
*/
|
|
1466
|
-
static async getUploadUrl(key, expiresInMinutes, bucketName) {
|
|
1913
|
+
static async getUploadUrl(key, expiresInMinutes, bucketName, objectStorageOptions) {
|
|
1467
1914
|
return _ObjectStorageService.getObjectStorageServiceInstance(
|
|
1468
|
-
bucketName
|
|
1915
|
+
bucketName,
|
|
1916
|
+
objectStorageOptions
|
|
1469
1917
|
).then((instance) => instance.getUploadUrl(key, expiresInMinutes));
|
|
1470
1918
|
}
|
|
1471
1919
|
/**
|
|
@@ -1475,11 +1923,13 @@ var ObjectStorageService = class _ObjectStorageService {
|
|
|
1475
1923
|
* @param {FileContent} body - The content of the file to upload.
|
|
1476
1924
|
* @param {Object} [metadata] - Optional metadata to associate with the object.
|
|
1477
1925
|
* @param {string} [bucketName] - The name of the bucket where the object will be stored. If not provided, the default bucket name will be used.
|
|
1926
|
+
* @param {ObjectStorageOptions} [objectStorageOptions] - The options for the object storage service.
|
|
1478
1927
|
* @return {Promise<UploadResponse>} A promise that resolves to the response of the upload operation.
|
|
1479
1928
|
*/
|
|
1480
|
-
static async upload(key, body, metadata, bucketName) {
|
|
1929
|
+
static async upload(key, body, metadata, bucketName, objectStorageOptions) {
|
|
1481
1930
|
return _ObjectStorageService.getObjectStorageServiceInstance(
|
|
1482
|
-
bucketName
|
|
1931
|
+
bucketName,
|
|
1932
|
+
objectStorageOptions
|
|
1483
1933
|
).then((instance) => instance.upload(key, body, metadata));
|
|
1484
1934
|
}
|
|
1485
1935
|
/**
|
|
@@ -1487,25 +1937,27 @@ var ObjectStorageService = class _ObjectStorageService {
|
|
|
1487
1937
|
*
|
|
1488
1938
|
* @param {string} key - The key of the object to create the upload write stream for.
|
|
1489
1939
|
* @param {string} [bucketName] - The name of the bucket where the object will be stored. If not provided, the default bucket name will be used.
|
|
1940
|
+
* @param {ObjectStorageOptions} [objectStorageOptions] - The options for the object storage service.
|
|
1490
1941
|
* @return {Promise<CreateUploadWriteStreamResponse>} A promise that resolves to the response of the upload operation.
|
|
1491
1942
|
*/
|
|
1492
|
-
static async createUploadWriteStream(key, bucketName,
|
|
1943
|
+
static async createUploadWriteStream(key, bucketName, objectStorageOptions) {
|
|
1493
1944
|
return _ObjectStorageService.getObjectStorageServiceInstance(
|
|
1494
|
-
bucketName
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
);
|
|
1945
|
+
bucketName,
|
|
1946
|
+
objectStorageOptions
|
|
1947
|
+
).then((instance) => instance.createUploadWriteStream(key));
|
|
1498
1948
|
}
|
|
1499
1949
|
/**
|
|
1500
1950
|
* Deletes an object or multiple objects from the object storage service.
|
|
1501
1951
|
*
|
|
1502
1952
|
* @param {string | string[]} key - The key or array of keys of the objects to delete.
|
|
1503
1953
|
* @param {string} [bucketName] - The name of the bucket where the objects are stored. If not provided, the default bucket name will be used.
|
|
1954
|
+
* @param {ObjectStorageOptions} [objectStorageOptions] - The options for the object storage service.
|
|
1504
1955
|
* @return {Promise<{ key: string; deleted: boolean; error?: string }[] | boolean>} A promise that resolves to an array of objects containing the key, deleted status, and an optional error message for each object deleted, or a boolean value indicating the success of the deletion.
|
|
1505
1956
|
*/
|
|
1506
|
-
static async delete(key, bucketName) {
|
|
1957
|
+
static async delete(key, bucketName, objectStorageOptions) {
|
|
1507
1958
|
return _ObjectStorageService.getObjectStorageServiceInstance(
|
|
1508
|
-
bucketName
|
|
1959
|
+
bucketName,
|
|
1960
|
+
objectStorageOptions
|
|
1509
1961
|
).then(async (instance) => {
|
|
1510
1962
|
if (Array.isArray(key)) {
|
|
1511
1963
|
const deleteBlobPromises = key.map(async (blobName) => {
|
|
@@ -1531,11 +1983,13 @@ var ObjectStorageService = class _ObjectStorageService {
|
|
|
1531
1983
|
* Retrieves the head bucket from the object storage service.
|
|
1532
1984
|
*
|
|
1533
1985
|
* @param {string} [bucketName] - The name of the bucket. If not provided, the default bucket name will be used.
|
|
1986
|
+
* @param {ObjectStorageOptions} [objectStorageOptions] - The options for the object storage service.
|
|
1534
1987
|
* @return {Promise<HeadBucketResponse>} A promise that resolves to the head bucket response.
|
|
1535
1988
|
*/
|
|
1536
|
-
static async getHeadBucket(bucketName) {
|
|
1989
|
+
static async getHeadBucket(bucketName, objectStorageOptions) {
|
|
1537
1990
|
return _ObjectStorageService.getObjectStorageServiceInstance(
|
|
1538
|
-
bucketName
|
|
1991
|
+
bucketName,
|
|
1992
|
+
objectStorageOptions
|
|
1539
1993
|
).then((instance) => instance.getHeadBucket());
|
|
1540
1994
|
}
|
|
1541
1995
|
/**
|
|
@@ -1543,11 +1997,13 @@ var ObjectStorageService = class _ObjectStorageService {
|
|
|
1543
1997
|
*
|
|
1544
1998
|
* @param {string} key - The key of the object to upload.
|
|
1545
1999
|
* @param {string} [bucketName] - The name of the bucket. If not provided, the default bucket name will be used.
|
|
2000
|
+
* @param {ObjectStorageOptions} [objectStorageOptions] - The options for the object storage service.
|
|
1546
2001
|
* @return {Promise<string>} A promise that resolves to the generated upload ID.
|
|
1547
2002
|
*/
|
|
1548
|
-
static async generateUploadIdMultipart(key, bucketName) {
|
|
2003
|
+
static async generateUploadIdMultipart(key, bucketName, objectStorageOptions) {
|
|
1549
2004
|
return _ObjectStorageService.getObjectStorageServiceInstance(
|
|
1550
|
-
bucketName
|
|
2005
|
+
bucketName,
|
|
2006
|
+
objectStorageOptions
|
|
1551
2007
|
).then((instance) => instance.generateUploadIdMultipart(key));
|
|
1552
2008
|
}
|
|
1553
2009
|
/**
|
|
@@ -1556,11 +2012,13 @@ var ObjectStorageService = class _ObjectStorageService {
|
|
|
1556
2012
|
* @param {string} key - The key of the object to retrieve uploads for.
|
|
1557
2013
|
* @param {string} [bucketName] - The name of the bucket. If not provided, the default bucket name will be used.
|
|
1558
2014
|
* @param {string} [uploadId] - The upload ID to filter the results by.
|
|
2015
|
+
* @param {ObjectStorageOptions} [objectStorageOptions] - The options for the object storage service.
|
|
1559
2016
|
* @return {Promise<ListPartsMultipartUploadResponse>} A promise that resolves to the list of multipart uploads for the specified key.
|
|
1560
2017
|
*/
|
|
1561
|
-
static async listMultipartUploadsForKey(key, bucketName, uploadId) {
|
|
2018
|
+
static async listMultipartUploadsForKey(key, bucketName, uploadId, objectStorageOptions) {
|
|
1562
2019
|
return _ObjectStorageService.getObjectStorageServiceInstance(
|
|
1563
|
-
bucketName
|
|
2020
|
+
bucketName,
|
|
2021
|
+
objectStorageOptions
|
|
1564
2022
|
).then(
|
|
1565
2023
|
(instance) => instance.listMultipartUploadsForKey(key, uploadId)
|
|
1566
2024
|
);
|
|
@@ -1569,11 +2027,13 @@ var ObjectStorageService = class _ObjectStorageService {
|
|
|
1569
2027
|
* Retrieves a list of all multipart uploads for a specified bucket in the object storage service.
|
|
1570
2028
|
*
|
|
1571
2029
|
* @param {string} [bucketName] - The name of the bucket. If not provided, the default bucket name will be used.
|
|
2030
|
+
* @param {ObjectStorageOptions} [objectStorageOptions] - The options for the object storage service.
|
|
1572
2031
|
* @return {Promise<ListMultipartUploadsResponse>} A promise that resolves to the list of multipart uploads for the specified bucket.
|
|
1573
2032
|
*/
|
|
1574
|
-
static async listMultipartUploadsForBucket(bucketName) {
|
|
2033
|
+
static async listMultipartUploadsForBucket(bucketName, objectStorageOptions) {
|
|
1575
2034
|
return _ObjectStorageService.getObjectStorageServiceInstance(
|
|
1576
|
-
bucketName
|
|
2035
|
+
bucketName,
|
|
2036
|
+
objectStorageOptions
|
|
1577
2037
|
).then((instance) => instance.listMultipartUploadsForBucket());
|
|
1578
2038
|
}
|
|
1579
2039
|
/**
|
|
@@ -1584,11 +2044,13 @@ var ObjectStorageService = class _ObjectStorageService {
|
|
|
1584
2044
|
* @param {number} partNumber - The number of the part being uploaded.
|
|
1585
2045
|
* @param {string} [uploadId] - The ID of the multipart upload.
|
|
1586
2046
|
* @param {string} [bucketName] - The name of the bucket to upload the file to. If not provided, the default bucket name will be used.
|
|
2047
|
+
* @param {ObjectStorageOptions} [objectStorageOptions] - The options for the object storage service.
|
|
1587
2048
|
* @return {Promise<string>} A Promise that resolves to the base64 encoded block ID of the uploaded part.
|
|
1588
2049
|
*/
|
|
1589
|
-
static async uploadMultipart(key, file, partNumber, uploadId, bucketName) {
|
|
2050
|
+
static async uploadMultipart(key, file, partNumber, uploadId, bucketName, objectStorageOptions) {
|
|
1590
2051
|
return _ObjectStorageService.getObjectStorageServiceInstance(
|
|
1591
|
-
bucketName
|
|
2052
|
+
bucketName,
|
|
2053
|
+
objectStorageOptions
|
|
1592
2054
|
).then(
|
|
1593
2055
|
(instance) => instance.uploadMultipart(key, file, partNumber, uploadId)
|
|
1594
2056
|
);
|
|
@@ -1599,11 +2061,13 @@ var ObjectStorageService = class _ObjectStorageService {
|
|
|
1599
2061
|
* @param {string} key - The key of the object to complete the multipart upload for.
|
|
1600
2062
|
* @param {string} uploadId - The ID of the multipart upload to complete.
|
|
1601
2063
|
* @param {string} [bucketName] - The name of the bucket to complete the multipart upload in. If not provided, the default bucket name will be used.
|
|
2064
|
+
* @param {ObjectStorageOptions} [objectStorageOptions] - The options for the object storage service.
|
|
1602
2065
|
* @return {Promise<void>} A Promise that resolves when the multipart upload is completed.
|
|
1603
2066
|
*/
|
|
1604
|
-
static async completeMultipartUpload(key, uploadId, bucketName) {
|
|
2067
|
+
static async completeMultipartUpload(key, uploadId, bucketName, objectStorageOptions) {
|
|
1605
2068
|
return _ObjectStorageService.getObjectStorageServiceInstance(
|
|
1606
|
-
bucketName
|
|
2069
|
+
bucketName,
|
|
2070
|
+
objectStorageOptions
|
|
1607
2071
|
).then((instance) => instance.completeMultipartUpload(key, uploadId));
|
|
1608
2072
|
}
|
|
1609
2073
|
/**
|
|
@@ -1612,11 +2076,13 @@ var ObjectStorageService = class _ObjectStorageService {
|
|
|
1612
2076
|
* @param {string} key - The key of the object to abort the multipart upload for.
|
|
1613
2077
|
* @param {string} uploadId - The ID of the multipart upload to abort.
|
|
1614
2078
|
* @param {string} [bucketName] - The name of the bucket to abort the multipart upload in. If not provided, the default bucket name will be used.
|
|
2079
|
+
* @param {ObjectStorageOptions} [objectStorageOptions] - The options for the object storage service.
|
|
1615
2080
|
* @return {Promise<void>} A Promise that resolves when the multipart upload is aborted.
|
|
1616
2081
|
*/
|
|
1617
|
-
static async abortMultipartUpload(key, uploadId, bucketName) {
|
|
2082
|
+
static async abortMultipartUpload(key, uploadId, bucketName, objectStorageOptions) {
|
|
1618
2083
|
return _ObjectStorageService.getObjectStorageServiceInstance(
|
|
1619
|
-
bucketName
|
|
2084
|
+
bucketName,
|
|
2085
|
+
objectStorageOptions
|
|
1620
2086
|
).then((instance) => instance.abortMultipartUpload(key, uploadId));
|
|
1621
2087
|
}
|
|
1622
2088
|
/**
|