@qrvey/object-storage 2.0.4-1170 → 2.0.5-1175
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/cjs/index-v2.js +23 -5
- package/dist/cjs/index-v2.js.map +1 -1
- package/dist/cjs/index.js +426 -42
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/{chunk-66BQA4WX.mjs → chunk-V3CZ5PB2.mjs} +9 -2
- package/dist/esm/index-v2.mjs +24 -6
- package/dist/esm/index-v2.mjs.map +1 -1
- package/dist/esm/index.d.mts +45 -19
- package/dist/esm/index.mjs +419 -42
- package/dist/esm/index.mjs.map +1 -1
- package/dist/types/index.d.ts +45 -19
- package/package.json +5 -2
- /package/dist/esm/{chunk-66BQA4WX.mjs.map → chunk-V3CZ5PB2.mjs.map} +0 -0
package/dist/cjs/index.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var stream2 = require('stream');
|
|
4
4
|
var storageBlob = require('@azure/storage-blob');
|
|
5
5
|
var clientS3 = require('@aws-sdk/client-s3');
|
|
6
6
|
var credentialProviderNode = require('@aws-sdk/credential-provider-node');
|
|
7
7
|
var s3RequestPresigner = require('@aws-sdk/s3-request-presigner');
|
|
8
8
|
var libStorage = require('@aws-sdk/lib-storage');
|
|
9
9
|
var nodeHttpHandler = require('@smithy/node-http-handler');
|
|
10
|
+
var basicFtp = require('basic-ftp');
|
|
10
11
|
|
|
11
12
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
13
|
|
|
13
|
-
var
|
|
14
|
+
var stream2__default = /*#__PURE__*/_interopDefault(stream2);
|
|
14
15
|
|
|
15
16
|
var __defProp = Object.defineProperty;
|
|
16
17
|
var __defProps = Object.defineProperties;
|
|
@@ -37,6 +38,13 @@ var __spreadValues = (a, b) => {
|
|
|
37
38
|
};
|
|
38
39
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
39
40
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
41
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
42
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
43
|
+
}) : x)(function(x) {
|
|
44
|
+
if (typeof require !== "undefined")
|
|
45
|
+
return require.apply(this, arguments);
|
|
46
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
47
|
+
});
|
|
40
48
|
var __objRest = (source, exclude) => {
|
|
41
49
|
var target = {};
|
|
42
50
|
for (var prop in source)
|
|
@@ -148,9 +156,10 @@ var _BlobStorageService = class _BlobStorageService {
|
|
|
148
156
|
* Retrieves the properties of a blob from the container by its name.
|
|
149
157
|
*
|
|
150
158
|
* @param {string} blobName - The name of the blob.
|
|
159
|
+
* @param {ObjectStorageOptions} options - The options for the object storage service.
|
|
151
160
|
* @return {Promise<GetObjectResponse>} A promise that resolves to the blob properties.
|
|
152
161
|
*/
|
|
153
|
-
constructor(containerName) {
|
|
162
|
+
constructor(containerName, options) {
|
|
154
163
|
__publicField(this, "blobServiceClient");
|
|
155
164
|
__publicField(this, "containerName");
|
|
156
165
|
this.containerName = containerName;
|
|
@@ -161,7 +170,7 @@ var _BlobStorageService = class _BlobStorageService {
|
|
|
161
170
|
if (!connectionString) {
|
|
162
171
|
connectionString = process.env.AZURE_STORAGE_CONNECTION_STRING;
|
|
163
172
|
}
|
|
164
|
-
this.blobServiceClient = storageBlob.BlobServiceClient.fromConnectionString(connectionString);
|
|
173
|
+
this.blobServiceClient = storageBlob.BlobServiceClient.fromConnectionString((options == null ? void 0 : options.connectionString) || connectionString);
|
|
165
174
|
}
|
|
166
175
|
/**
|
|
167
176
|
* Creates a writable stream for uploading a file to the Blob storage.
|
|
@@ -170,7 +179,7 @@ var _BlobStorageService = class _BlobStorageService {
|
|
|
170
179
|
* @return {CreateUploadWriteStreamResponse} An object containing the key of the uploaded blob, the writable stream, and a promise that resolves when the upload is complete.
|
|
171
180
|
*/
|
|
172
181
|
createUploadWriteStream(blobName) {
|
|
173
|
-
const streamPassThrough = new
|
|
182
|
+
const streamPassThrough = new stream2__default.default.PassThrough();
|
|
174
183
|
const containerClient = this.blobServiceClient.getContainerClient(this.containerName);
|
|
175
184
|
const blockBlobClient = containerClient.getBlockBlobClient(blobName);
|
|
176
185
|
const uploadPromise = blockBlobClient.uploadStream(streamPassThrough, void 0, void 0, {
|
|
@@ -553,11 +562,10 @@ var _BlobStorageService = class _BlobStorageService {
|
|
|
553
562
|
* Completes a multipart upload by committing the blocks to create the blob.
|
|
554
563
|
*
|
|
555
564
|
* @param {string} blobName - The name of the blob for which the multipart upload is being completed.
|
|
556
|
-
* @param {string} uploadId - The ID of the multipart upload to be completed.
|
|
557
565
|
* @return {Promise<void>} A Promise that resolves when the multipart upload is successfully completed.
|
|
558
566
|
* @throws {Error} If no block IDs are found in the metadata.
|
|
559
567
|
*/
|
|
560
|
-
async completeMultipartUpload(blobName
|
|
568
|
+
async completeMultipartUpload(blobName) {
|
|
561
569
|
var _a;
|
|
562
570
|
const containerClient = this.blobServiceClient.getContainerClient(this.containerName);
|
|
563
571
|
const blobClient = containerClient.getBlockBlobClient(blobName);
|
|
@@ -806,6 +814,23 @@ var _S3StorageService = class _S3StorageService {
|
|
|
806
814
|
* @returns A promise that resolves to the response containing the key of the uploaded object.
|
|
807
815
|
*/
|
|
808
816
|
async upload(key, body, metadata) {
|
|
817
|
+
if (body instanceof stream2__default.default.Readable) {
|
|
818
|
+
const upload = new libStorage.Upload({
|
|
819
|
+
client: this.s3Client,
|
|
820
|
+
params: {
|
|
821
|
+
Bucket: this.bucketName,
|
|
822
|
+
Key: key,
|
|
823
|
+
Body: body,
|
|
824
|
+
Metadata: metadata
|
|
825
|
+
},
|
|
826
|
+
queueSize: 5,
|
|
827
|
+
partSize: 8 * 1024 * 1024
|
|
828
|
+
});
|
|
829
|
+
await upload.done();
|
|
830
|
+
return {
|
|
831
|
+
key
|
|
832
|
+
};
|
|
833
|
+
}
|
|
809
834
|
const command = new clientS3.PutObjectCommand({
|
|
810
835
|
Bucket: this.bucketName,
|
|
811
836
|
Key: key,
|
|
@@ -824,7 +849,7 @@ var _S3StorageService = class _S3StorageService {
|
|
|
824
849
|
* @return {CreateUploadWriteStreamResponse} An object containing the key of the uploaded object, the writable stream, and a promise that resolves when the upload is complete.
|
|
825
850
|
*/
|
|
826
851
|
createUploadWriteStream(key) {
|
|
827
|
-
const streamPassThrough = new
|
|
852
|
+
const streamPassThrough = new stream2__default.default.PassThrough();
|
|
828
853
|
const params = {
|
|
829
854
|
Bucket: this.bucketName,
|
|
830
855
|
Key: key,
|
|
@@ -981,11 +1006,348 @@ var _S3StorageService = class _S3StorageService {
|
|
|
981
1006
|
};
|
|
982
1007
|
__name(_S3StorageService, "S3StorageService");
|
|
983
1008
|
var S3StorageService = _S3StorageService;
|
|
1009
|
+
var SftpClient = __require("ssh2-sftp-client");
|
|
1010
|
+
var _SftpStorageService = class _SftpStorageService {
|
|
1011
|
+
constructor(bucketName, options) {
|
|
1012
|
+
__publicField(this, "client");
|
|
1013
|
+
__publicField(this, "bucketName");
|
|
1014
|
+
__publicField(this, "options");
|
|
1015
|
+
this.bucketName = bucketName;
|
|
1016
|
+
this.options = options || {};
|
|
1017
|
+
this.client = new SftpClient();
|
|
1018
|
+
}
|
|
1019
|
+
async initializeClient() {
|
|
1020
|
+
const host = this.options.host || process.env.SFTP_HOST;
|
|
1021
|
+
const port = parseInt(String(this.options.port || process.env.SFTP_PORT));
|
|
1022
|
+
const user = this.options.user || process.env.SFTP_USER;
|
|
1023
|
+
const password = this.options.password || process.env.SFTP_PASSWORD;
|
|
1024
|
+
const privateKey = this.options.privateKey || process.env.SFTP_PRIVATE_KEY;
|
|
1025
|
+
if (!password && !privateKey) {
|
|
1026
|
+
throw new Error("Either password or private key must be provided for SFTP connection");
|
|
1027
|
+
}
|
|
1028
|
+
await this.client.connect({
|
|
1029
|
+
host,
|
|
1030
|
+
port,
|
|
1031
|
+
username: user,
|
|
1032
|
+
password,
|
|
1033
|
+
privateKey,
|
|
1034
|
+
readyTimeout: 4e3,
|
|
1035
|
+
retries: 1,
|
|
1036
|
+
retry_factor: 2,
|
|
1037
|
+
retry_minTimeout: 2e3
|
|
1038
|
+
});
|
|
1039
|
+
}
|
|
1040
|
+
async withClient(fn) {
|
|
1041
|
+
try {
|
|
1042
|
+
await this.initializeClient();
|
|
1043
|
+
return await fn();
|
|
1044
|
+
} finally {
|
|
1045
|
+
await this.client.end().catch(() => {
|
|
1046
|
+
});
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
async list(options) {
|
|
1050
|
+
return this.withClient(async () => {
|
|
1051
|
+
const prefix = options.prefix || "";
|
|
1052
|
+
const path = this.bucketName + (prefix ? "/" + prefix : "");
|
|
1053
|
+
const list = await this.client.list(path);
|
|
1054
|
+
const items = list.map((item) => ({
|
|
1055
|
+
key: item.name,
|
|
1056
|
+
lastModified: item.modifyTime ? new Date(item.modifyTime) : /* @__PURE__ */ new Date(),
|
|
1057
|
+
size: item.size,
|
|
1058
|
+
eTag: ""
|
|
1059
|
+
}));
|
|
1060
|
+
return {
|
|
1061
|
+
items,
|
|
1062
|
+
pagination: null,
|
|
1063
|
+
count: items.length
|
|
1064
|
+
};
|
|
1065
|
+
});
|
|
1066
|
+
}
|
|
1067
|
+
async ensureDirectoriesExist(remotePath) {
|
|
1068
|
+
var _a, _b;
|
|
1069
|
+
const parts = remotePath.split("/");
|
|
1070
|
+
parts.pop();
|
|
1071
|
+
let current = "";
|
|
1072
|
+
for (const part of parts) {
|
|
1073
|
+
if (!part)
|
|
1074
|
+
continue;
|
|
1075
|
+
current += `/${part}`;
|
|
1076
|
+
try {
|
|
1077
|
+
await this.client.stat(current);
|
|
1078
|
+
} catch (err) {
|
|
1079
|
+
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"));
|
|
1080
|
+
if (isNoEntry) {
|
|
1081
|
+
try {
|
|
1082
|
+
await this.client.mkdir(current);
|
|
1083
|
+
} catch (mkdirErr) {
|
|
1084
|
+
throw new Error(`Failed to create directory ${current}: ${mkdirErr.message}`);
|
|
1085
|
+
}
|
|
1086
|
+
} else {
|
|
1087
|
+
throw new Error(`Failed to check directory ${current}: ${err.message}`);
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
async upload(key, body) {
|
|
1093
|
+
return this.withClient(async () => {
|
|
1094
|
+
let remotePath = `${this.bucketName}/${key}`;
|
|
1095
|
+
remotePath = remotePath + "";
|
|
1096
|
+
await this.ensureDirectoriesExist(remotePath);
|
|
1097
|
+
if (body instanceof stream2.Readable) {
|
|
1098
|
+
await this.client.put(body, remotePath);
|
|
1099
|
+
} else if (body instanceof Buffer) {
|
|
1100
|
+
await this.client.put(Buffer.from(body), remotePath);
|
|
1101
|
+
} else {
|
|
1102
|
+
await this.client.put(Buffer.from(String(body)), remotePath);
|
|
1103
|
+
}
|
|
1104
|
+
return {
|
|
1105
|
+
key
|
|
1106
|
+
};
|
|
1107
|
+
});
|
|
1108
|
+
}
|
|
1109
|
+
async delete(key) {
|
|
1110
|
+
return this.withClient(async () => {
|
|
1111
|
+
await this.client.delete(`${this.bucketName}/${key}`);
|
|
1112
|
+
return true;
|
|
1113
|
+
});
|
|
1114
|
+
}
|
|
1115
|
+
async getObject(key) {
|
|
1116
|
+
await this.initializeClient();
|
|
1117
|
+
const remotePath = `${this.bucketName}/${key}`;
|
|
1118
|
+
const stats = await this.client.stat(remotePath);
|
|
1119
|
+
const data = await this.client.get(remotePath);
|
|
1120
|
+
let stream3;
|
|
1121
|
+
if (Buffer.isBuffer(data) || typeof data === "string") {
|
|
1122
|
+
stream3 = stream2.Readable.from(data);
|
|
1123
|
+
} else if (data instanceof stream2.Readable) {
|
|
1124
|
+
stream3 = data;
|
|
1125
|
+
} else {
|
|
1126
|
+
throw new Error("Unsupported stream type returned by SFTP client");
|
|
1127
|
+
}
|
|
1128
|
+
const cleanup = /* @__PURE__ */ __name(async () => {
|
|
1129
|
+
try {
|
|
1130
|
+
await this.client.end();
|
|
1131
|
+
} catch (e) {
|
|
1132
|
+
}
|
|
1133
|
+
}, "cleanup");
|
|
1134
|
+
stream3.on("end", cleanup);
|
|
1135
|
+
stream3.on("error", cleanup);
|
|
1136
|
+
return {
|
|
1137
|
+
body: stream3,
|
|
1138
|
+
contentLength: stats.size,
|
|
1139
|
+
lastModified: stats.modifyTime ? new Date(stats.modifyTime) : /* @__PURE__ */ new Date(),
|
|
1140
|
+
metadata: {}
|
|
1141
|
+
};
|
|
1142
|
+
}
|
|
1143
|
+
listAll(options) {
|
|
1144
|
+
throw new Error("Method not implemented.");
|
|
1145
|
+
}
|
|
1146
|
+
getHeadObject(key) {
|
|
1147
|
+
throw new Error("Method not implemented.");
|
|
1148
|
+
}
|
|
1149
|
+
getDownloadUrl(key, expiresInMinutes) {
|
|
1150
|
+
throw new Error("Method not implemented.");
|
|
1151
|
+
}
|
|
1152
|
+
getUploadUrl(key, expiresInMinutes) {
|
|
1153
|
+
throw new Error("Method not implemented.");
|
|
1154
|
+
}
|
|
1155
|
+
createUploadWriteStream(key) {
|
|
1156
|
+
throw new Error("Method not implemented.");
|
|
1157
|
+
}
|
|
1158
|
+
getHeadBucket() {
|
|
1159
|
+
throw new Error("Method not implemented.");
|
|
1160
|
+
}
|
|
1161
|
+
generateUploadIdMultipart(key) {
|
|
1162
|
+
throw new Error("Method not implemented.");
|
|
1163
|
+
}
|
|
1164
|
+
listMultipartUploadsForBucket() {
|
|
1165
|
+
throw new Error("Method not implemented.");
|
|
1166
|
+
}
|
|
1167
|
+
listMultipartUploadsForKey(key, uploadId) {
|
|
1168
|
+
throw new Error("Method not implemented.");
|
|
1169
|
+
}
|
|
1170
|
+
uploadMultipart(key, file, partNumber, uploadId) {
|
|
1171
|
+
throw new Error("Method not implemented.");
|
|
1172
|
+
}
|
|
1173
|
+
completeMultipartUpload(key, uploadId) {
|
|
1174
|
+
throw new Error("Method not implemented.");
|
|
1175
|
+
}
|
|
1176
|
+
abortMultipartUpload(key, uploadId) {
|
|
1177
|
+
throw new Error("Method not implemented.");
|
|
1178
|
+
}
|
|
1179
|
+
getMultipartUploadPresignedUrl(key, uploadId, partNumber, expiresInMinutes) {
|
|
1180
|
+
throw new Error("Method not implemented.");
|
|
1181
|
+
}
|
|
1182
|
+
};
|
|
1183
|
+
__name(_SftpStorageService, "SftpStorageService");
|
|
1184
|
+
var SftpStorageService = _SftpStorageService;
|
|
1185
|
+
var _FtpStorageService = class _FtpStorageService {
|
|
1186
|
+
constructor(bucketName, options) {
|
|
1187
|
+
__publicField(this, "client");
|
|
1188
|
+
__publicField(this, "bucketName");
|
|
1189
|
+
__publicField(this, "options");
|
|
1190
|
+
this.bucketName = bucketName;
|
|
1191
|
+
this.options = options || {};
|
|
1192
|
+
this.client = new basicFtp.Client();
|
|
1193
|
+
}
|
|
1194
|
+
listAll(options) {
|
|
1195
|
+
throw new Error("Method not implemented.");
|
|
1196
|
+
}
|
|
1197
|
+
async initializeClient() {
|
|
1198
|
+
var _a, _b, _c, _d, _e;
|
|
1199
|
+
const host = ((_a = this == null ? void 0 : this.options) == null ? void 0 : _a.host) || process.env.FTP_HOST;
|
|
1200
|
+
const port = parseInt(String(((_b = this == null ? void 0 : this.options) == null ? void 0 : _b.port) || process.env.FTP_PORT), 10);
|
|
1201
|
+
const user = ((_c = this == null ? void 0 : this.options) == null ? void 0 : _c.user) || process.env.FTP_USER;
|
|
1202
|
+
const password = ((_d = this == null ? void 0 : this.options) == null ? void 0 : _d.password) || process.env.FTP_PASSWORD;
|
|
1203
|
+
await this.client.access({
|
|
1204
|
+
host,
|
|
1205
|
+
port,
|
|
1206
|
+
user,
|
|
1207
|
+
password,
|
|
1208
|
+
secure: ((_e = this == null ? void 0 : this.options) == null ? void 0 : _e.secure) || false
|
|
1209
|
+
});
|
|
1210
|
+
}
|
|
1211
|
+
async withClient(fn) {
|
|
1212
|
+
try {
|
|
1213
|
+
await this.initializeClient();
|
|
1214
|
+
return await fn();
|
|
1215
|
+
} finally {
|
|
1216
|
+
this.client.close();
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
async list(options) {
|
|
1220
|
+
return this.withClient(async () => {
|
|
1221
|
+
const prefix = options.prefix || "";
|
|
1222
|
+
const path = `${this.bucketName}/${prefix}`;
|
|
1223
|
+
try {
|
|
1224
|
+
const list = await this.client.list(path);
|
|
1225
|
+
const items = list.map((item) => ({
|
|
1226
|
+
key: prefix + item.name,
|
|
1227
|
+
lastModified: item.modifiedAt || /* @__PURE__ */ new Date(),
|
|
1228
|
+
size: item.size,
|
|
1229
|
+
eTag: ""
|
|
1230
|
+
}));
|
|
1231
|
+
return {
|
|
1232
|
+
items,
|
|
1233
|
+
pagination: null,
|
|
1234
|
+
count: items.length
|
|
1235
|
+
};
|
|
1236
|
+
} catch (e) {
|
|
1237
|
+
return {
|
|
1238
|
+
items: [],
|
|
1239
|
+
pagination: null,
|
|
1240
|
+
count: 0
|
|
1241
|
+
};
|
|
1242
|
+
}
|
|
1243
|
+
});
|
|
1244
|
+
}
|
|
1245
|
+
async getObject(key) {
|
|
1246
|
+
await this.initializeClient();
|
|
1247
|
+
const passThrough = new stream2.PassThrough();
|
|
1248
|
+
const path = `${this.bucketName}/${key}`;
|
|
1249
|
+
const stats = await this.client.size(path);
|
|
1250
|
+
this.client.downloadTo(passThrough, path).then(() => passThrough.end()).catch((err) => passThrough.emit("error", err));
|
|
1251
|
+
const cleanup = /* @__PURE__ */ __name(() => {
|
|
1252
|
+
this.client.close();
|
|
1253
|
+
}, "cleanup");
|
|
1254
|
+
passThrough.on("end", cleanup);
|
|
1255
|
+
passThrough.on("error", cleanup);
|
|
1256
|
+
return {
|
|
1257
|
+
body: passThrough,
|
|
1258
|
+
contentLength: stats,
|
|
1259
|
+
lastModified: /* @__PURE__ */ new Date(),
|
|
1260
|
+
metadata: {}
|
|
1261
|
+
};
|
|
1262
|
+
}
|
|
1263
|
+
async upload(key, body) {
|
|
1264
|
+
return this.withClient(async () => {
|
|
1265
|
+
await this.client.cd("/");
|
|
1266
|
+
try {
|
|
1267
|
+
await this.client.cd(this.bucketName);
|
|
1268
|
+
} catch (e) {
|
|
1269
|
+
await this.client.send(`MKD ${this.bucketName}`);
|
|
1270
|
+
await this.client.cd(this.bucketName);
|
|
1271
|
+
}
|
|
1272
|
+
const parts = key.split("/");
|
|
1273
|
+
parts.pop();
|
|
1274
|
+
for (const part of parts) {
|
|
1275
|
+
if (!part)
|
|
1276
|
+
continue;
|
|
1277
|
+
try {
|
|
1278
|
+
await this.client.cd(part);
|
|
1279
|
+
} catch (e) {
|
|
1280
|
+
await this.client.send(`MKD ${part}`);
|
|
1281
|
+
await this.client.cd(part);
|
|
1282
|
+
}
|
|
1283
|
+
}
|
|
1284
|
+
await this.client.cd("/");
|
|
1285
|
+
const fullPath = `${this.bucketName}/${key}`;
|
|
1286
|
+
const stream3 = body instanceof stream2.Readable ? body : stream2.Readable.from([
|
|
1287
|
+
body
|
|
1288
|
+
]);
|
|
1289
|
+
await this.client.uploadFrom(stream3, fullPath);
|
|
1290
|
+
return {
|
|
1291
|
+
key
|
|
1292
|
+
};
|
|
1293
|
+
});
|
|
1294
|
+
}
|
|
1295
|
+
async delete(key) {
|
|
1296
|
+
return this.withClient(async () => {
|
|
1297
|
+
await this.client.remove(`${this.bucketName}/${key}`);
|
|
1298
|
+
return true;
|
|
1299
|
+
});
|
|
1300
|
+
}
|
|
1301
|
+
async close() {
|
|
1302
|
+
this.client.close();
|
|
1303
|
+
}
|
|
1304
|
+
// Unsupported Operations
|
|
1305
|
+
async getDownloadUrl(_key, _expiresInMinutes) {
|
|
1306
|
+
throw new Error("FTP does not support pre-signed URLs");
|
|
1307
|
+
}
|
|
1308
|
+
async getUploadUrl(_key, _expiresInMinutes) {
|
|
1309
|
+
throw new Error("FTP does not support pre-signed URLs");
|
|
1310
|
+
}
|
|
1311
|
+
async getHeadObject(_key) {
|
|
1312
|
+
throw new Error("Operation not supported");
|
|
1313
|
+
}
|
|
1314
|
+
createUploadWriteStream(_key) {
|
|
1315
|
+
throw new Error("Operation not supported");
|
|
1316
|
+
}
|
|
1317
|
+
async getHeadBucket() {
|
|
1318
|
+
throw new Error("Operation not supported");
|
|
1319
|
+
}
|
|
1320
|
+
async generateUploadIdMultipart(_key) {
|
|
1321
|
+
throw new Error("Multipart upload is not supported");
|
|
1322
|
+
}
|
|
1323
|
+
async listMultipartUploadsForBucket() {
|
|
1324
|
+
throw new Error("Multipart upload is not supported");
|
|
1325
|
+
}
|
|
1326
|
+
async listMultipartUploadsForKey(_key, _uploadId) {
|
|
1327
|
+
throw new Error("Multipart upload is not supported");
|
|
1328
|
+
}
|
|
1329
|
+
async uploadMultipart(_key, _file, _partNumber, _uploadId) {
|
|
1330
|
+
throw new Error("Multipart upload is not supported");
|
|
1331
|
+
}
|
|
1332
|
+
async completeMultipartUpload(_key, _uploadId) {
|
|
1333
|
+
throw new Error("Multipart upload is not supported");
|
|
1334
|
+
}
|
|
1335
|
+
async abortMultipartUpload(_key, _uploadId) {
|
|
1336
|
+
throw new Error("Method not implemented.");
|
|
1337
|
+
}
|
|
1338
|
+
async getMultipartUploadPresignedUrl(_key, _uploadId, _partNumber, _expiresInMinutes) {
|
|
1339
|
+
throw new Error("Multipart upload is not supported");
|
|
1340
|
+
}
|
|
1341
|
+
};
|
|
1342
|
+
__name(_FtpStorageService, "FtpStorageService");
|
|
1343
|
+
var FtpStorageService = _FtpStorageService;
|
|
984
1344
|
|
|
985
1345
|
// src/shared/utils/constants.ts
|
|
986
1346
|
var OBJECT_STORAGE_SERVICE_TYPES = {
|
|
987
1347
|
AWS_S3: "aws_s3",
|
|
988
|
-
AZURE_BLOB_STORAGE: "azure_blob_storage"
|
|
1348
|
+
AZURE_BLOB_STORAGE: "azure_blob_storage",
|
|
1349
|
+
FTP: "ftp",
|
|
1350
|
+
SFTP: "sftp"
|
|
989
1351
|
};
|
|
990
1352
|
|
|
991
1353
|
// src/services/objectStorageFactory.service.ts
|
|
@@ -997,7 +1359,11 @@ var _ObjectStorageFactory = class _ObjectStorageFactory {
|
|
|
997
1359
|
case OBJECT_STORAGE_SERVICE_TYPES.AWS_S3:
|
|
998
1360
|
return new S3StorageService(bucketName, options);
|
|
999
1361
|
case OBJECT_STORAGE_SERVICE_TYPES.AZURE_BLOB_STORAGE:
|
|
1000
|
-
return new BlobStorageService(bucketName);
|
|
1362
|
+
return new BlobStorageService(bucketName, options);
|
|
1363
|
+
case OBJECT_STORAGE_SERVICE_TYPES.FTP:
|
|
1364
|
+
return new FtpStorageService(bucketName, options);
|
|
1365
|
+
case OBJECT_STORAGE_SERVICE_TYPES.SFTP:
|
|
1366
|
+
return new SftpStorageService(bucketName, options);
|
|
1001
1367
|
default:
|
|
1002
1368
|
throw new Error(`Unsupported object storage provider: ${provider}`);
|
|
1003
1369
|
}
|
|
@@ -1023,38 +1389,44 @@ var _ObjectStorageService = class _ObjectStorageService {
|
|
|
1023
1389
|
*
|
|
1024
1390
|
* @param {ListRequestOptions} options - The options to apply to the list operation.
|
|
1025
1391
|
* @param {string} [bucketName] - The name of the bucket to list objects from. If not provided, the default bucket name will be used.
|
|
1392
|
+
* @param {ObjectStorageOptions} [objectStorageOptions] - The options for the object storage service.
|
|
1026
1393
|
* @return {Promise<ListResponse>} A promise that resolves to the list of objects.
|
|
1027
1394
|
*/
|
|
1028
|
-
static async list(options, bucketName) {
|
|
1029
|
-
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName).then((instance) => instance.list(options));
|
|
1395
|
+
static async list(options, bucketName, objectStorageOptions) {
|
|
1396
|
+
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName, objectStorageOptions).then((instance) => instance.list(options));
|
|
1030
1397
|
}
|
|
1031
1398
|
/**
|
|
1032
1399
|
* Retrieves a list of all objects from the object storage service.
|
|
1033
1400
|
*
|
|
1034
1401
|
* @param {ListRequestOptions} options - The options to apply to the list operation.
|
|
1035
1402
|
* @param {string} [bucketName] - The name of the bucket to list objects from. If not provided, the default bucket name will be used.
|
|
1403
|
+
* @param {ObjectStorageOptions} [objectStorageOptions] - The options for the object storage service.
|
|
1036
1404
|
* @return {Promise<ListResponse>} A promise that resolves to the list of all objects.
|
|
1037
1405
|
*/
|
|
1038
|
-
static async listAll(options, bucketName) {
|
|
1039
|
-
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName).then((instance) => instance.listAll(options));
|
|
1406
|
+
static async listAll(options, bucketName, objectStorageOptions) {
|
|
1407
|
+
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName, objectStorageOptions).then((instance) => instance.listAll(options));
|
|
1040
1408
|
}
|
|
1041
1409
|
/**
|
|
1042
1410
|
* Retrieves an object from the object storage service.
|
|
1043
1411
|
*
|
|
1044
1412
|
* @param {string} key - The key of the object to retrieve.
|
|
1045
1413
|
* @param {string} [bucketName] - The name of the bucket where the object is stored. If not provided, the default bucket name will be used.
|
|
1414
|
+
* @param {IGetObjectOptions} [options] - The options to apply to the get operation.
|
|
1415
|
+
* @param {ObjectStorageOptions} [objectStorageOptions] - The options for the object storage service.
|
|
1046
1416
|
* @return {Promise<GetObjectResponse>} A promise that resolves to the retrieved object.
|
|
1047
1417
|
*/
|
|
1048
|
-
static async getObject(key, bucketName, options) {
|
|
1049
|
-
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName).then((instance) => instance.getObject(key, options));
|
|
1418
|
+
static async getObject(key, bucketName, options, objectStorageOptions) {
|
|
1419
|
+
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName, objectStorageOptions).then((instance) => instance.getObject(key, options));
|
|
1050
1420
|
}
|
|
1051
1421
|
/**
|
|
1052
1422
|
* Retrieves an object info (without file content) from the object storage service.
|
|
1053
1423
|
* @param key - The key of the object to retrieve.
|
|
1424
|
+
* @param bucketName - The name of the bucket where the object is stored. If not provided, the default bucket name will be used.
|
|
1425
|
+
* @param objectStorageOptions - The options for the object storage service.
|
|
1054
1426
|
* @returns A promise that resolves to the info of the file.
|
|
1055
1427
|
*/
|
|
1056
|
-
static async getHeadObject(key, bucketName) {
|
|
1057
|
-
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName).then((instance) => instance.getHeadObject(key));
|
|
1428
|
+
static async getHeadObject(key, bucketName, objectStorageOptions) {
|
|
1429
|
+
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName, objectStorageOptions).then((instance) => instance.getHeadObject(key));
|
|
1058
1430
|
}
|
|
1059
1431
|
/**
|
|
1060
1432
|
* Retrieves a signed URL for the specified object in the object storage service.
|
|
@@ -1062,10 +1434,11 @@ var _ObjectStorageService = class _ObjectStorageService {
|
|
|
1062
1434
|
* @param {string} key - The key of the object for which to generate the signed URL.
|
|
1063
1435
|
* @param {number} expiresInMinutes - The number of minutes until the signed URL expires.
|
|
1064
1436
|
* @param {string} [bucketName] - The name of the bucket where the object is stored. If not provided, the default bucket name will be used.
|
|
1437
|
+
* @param {ObjectStorageOptions} [objectStorageOptions] - The options for the object storage service.
|
|
1065
1438
|
* @return {Promise<string>} A promise that resolves to the generated signed URL.
|
|
1066
1439
|
*/
|
|
1067
|
-
static async getDownloadUrl(key, expiresInMinutes, bucketName) {
|
|
1068
|
-
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName).then((instance) => instance.getDownloadUrl(key, expiresInMinutes));
|
|
1440
|
+
static async getDownloadUrl(key, expiresInMinutes, bucketName, objectStorageOptions) {
|
|
1441
|
+
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName, objectStorageOptions).then((instance) => instance.getDownloadUrl(key, expiresInMinutes));
|
|
1069
1442
|
}
|
|
1070
1443
|
/**
|
|
1071
1444
|
* Retrieves an upload URL for the specified object in the object storage service.
|
|
@@ -1073,10 +1446,11 @@ var _ObjectStorageService = class _ObjectStorageService {
|
|
|
1073
1446
|
* @param {string} key - The key of the object for which to generate the upload URL.
|
|
1074
1447
|
* @param {number} expiresInMinutes - The number of minutes until the upload URL expires.
|
|
1075
1448
|
* @param {string} [bucketName] - The name of the bucket where the object will be stored. If not provided, the default bucket name will be used.
|
|
1449
|
+
* @param {ObjectStorageOptions} [objectStorageOptions] - The options for the object storage service.
|
|
1076
1450
|
* @return {Promise<string>} A promise that resolves to the generated upload URL.
|
|
1077
1451
|
*/
|
|
1078
|
-
static async getUploadUrl(key, expiresInMinutes, bucketName) {
|
|
1079
|
-
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName).then((instance) => instance.getUploadUrl(key, expiresInMinutes));
|
|
1452
|
+
static async getUploadUrl(key, expiresInMinutes, bucketName, objectStorageOptions) {
|
|
1453
|
+
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName, objectStorageOptions).then((instance) => instance.getUploadUrl(key, expiresInMinutes));
|
|
1080
1454
|
}
|
|
1081
1455
|
/**
|
|
1082
1456
|
* Uploads a file to the object storage service.
|
|
@@ -1085,30 +1459,33 @@ var _ObjectStorageService = class _ObjectStorageService {
|
|
|
1085
1459
|
* @param {FileContent} body - The content of the file to upload.
|
|
1086
1460
|
* @param {Object} [metadata] - Optional metadata to associate with the object.
|
|
1087
1461
|
* @param {string} [bucketName] - The name of the bucket where the object will be stored. If not provided, the default bucket name will be used.
|
|
1462
|
+
* @param {ObjectStorageOptions} [objectStorageOptions] - The options for the object storage service.
|
|
1088
1463
|
* @return {Promise<UploadResponse>} A promise that resolves to the response of the upload operation.
|
|
1089
1464
|
*/
|
|
1090
|
-
static async upload(key, body, metadata, bucketName) {
|
|
1091
|
-
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName).then((instance) => instance.upload(key, body, metadata));
|
|
1465
|
+
static async upload(key, body, metadata, bucketName, objectStorageOptions) {
|
|
1466
|
+
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName, objectStorageOptions).then((instance) => instance.upload(key, body, metadata));
|
|
1092
1467
|
}
|
|
1093
1468
|
/**
|
|
1094
1469
|
* Creates an upload write stream for the specified key in the object storage service.
|
|
1095
1470
|
*
|
|
1096
1471
|
* @param {string} key - The key of the object to create the upload write stream for.
|
|
1097
1472
|
* @param {string} [bucketName] - The name of the bucket where the object will be stored. If not provided, the default bucket name will be used.
|
|
1473
|
+
* @param {ObjectStorageOptions} [objectStorageOptions] - The options for the object storage service.
|
|
1098
1474
|
* @return {Promise<CreateUploadWriteStreamResponse>} A promise that resolves to the response of the upload operation.
|
|
1099
1475
|
*/
|
|
1100
|
-
static async createUploadWriteStream(key, bucketName) {
|
|
1101
|
-
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName).then((instance) => instance.createUploadWriteStream(key));
|
|
1476
|
+
static async createUploadWriteStream(key, bucketName, objectStorageOptions) {
|
|
1477
|
+
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName, objectStorageOptions).then((instance) => instance.createUploadWriteStream(key));
|
|
1102
1478
|
}
|
|
1103
1479
|
/**
|
|
1104
1480
|
* Deletes an object or multiple objects from the object storage service.
|
|
1105
1481
|
*
|
|
1106
1482
|
* @param {string | string[]} key - The key or array of keys of the objects to delete.
|
|
1107
1483
|
* @param {string} [bucketName] - The name of the bucket where the objects are stored. If not provided, the default bucket name will be used.
|
|
1484
|
+
* @param {ObjectStorageOptions} [objectStorageOptions] - The options for the object storage service.
|
|
1108
1485
|
* @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.
|
|
1109
1486
|
*/
|
|
1110
|
-
static async delete(key, bucketName) {
|
|
1111
|
-
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName).then(async (instance) => {
|
|
1487
|
+
static async delete(key, bucketName, objectStorageOptions) {
|
|
1488
|
+
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName, objectStorageOptions).then(async (instance) => {
|
|
1112
1489
|
if (Array.isArray(key)) {
|
|
1113
1490
|
const deleteBlobPromises = key.map(async (blobName) => {
|
|
1114
1491
|
var _a;
|
|
@@ -1136,20 +1513,22 @@ var _ObjectStorageService = class _ObjectStorageService {
|
|
|
1136
1513
|
* Retrieves the head bucket from the object storage service.
|
|
1137
1514
|
*
|
|
1138
1515
|
* @param {string} [bucketName] - The name of the bucket. If not provided, the default bucket name will be used.
|
|
1516
|
+
* @param {ObjectStorageOptions} [objectStorageOptions] - The options for the object storage service.
|
|
1139
1517
|
* @return {Promise<HeadBucketResponse>} A promise that resolves to the head bucket response.
|
|
1140
1518
|
*/
|
|
1141
|
-
static async getHeadBucket(bucketName) {
|
|
1142
|
-
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName).then((instance) => instance.getHeadBucket());
|
|
1519
|
+
static async getHeadBucket(bucketName, objectStorageOptions) {
|
|
1520
|
+
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName, objectStorageOptions).then((instance) => instance.getHeadBucket());
|
|
1143
1521
|
}
|
|
1144
1522
|
/**
|
|
1145
1523
|
* Generates a unique upload ID for a multipart upload.
|
|
1146
1524
|
*
|
|
1147
1525
|
* @param {string} key - The key of the object to upload.
|
|
1148
1526
|
* @param {string} [bucketName] - The name of the bucket. If not provided, the default bucket name will be used.
|
|
1527
|
+
* @param {ObjectStorageOptions} [objectStorageOptions] - The options for the object storage service.
|
|
1149
1528
|
* @return {Promise<string>} A promise that resolves to the generated upload ID.
|
|
1150
1529
|
*/
|
|
1151
|
-
static async generateUploadIdMultipart(key, bucketName) {
|
|
1152
|
-
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName).then((instance) => instance.generateUploadIdMultipart(key));
|
|
1530
|
+
static async generateUploadIdMultipart(key, bucketName, objectStorageOptions) {
|
|
1531
|
+
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName, objectStorageOptions).then((instance) => instance.generateUploadIdMultipart(key));
|
|
1153
1532
|
}
|
|
1154
1533
|
/**
|
|
1155
1534
|
* Retrieves a list of multipart uploads for a specified key in the object storage service.
|
|
@@ -1157,19 +1536,21 @@ var _ObjectStorageService = class _ObjectStorageService {
|
|
|
1157
1536
|
* @param {string} key - The key of the object to retrieve uploads for.
|
|
1158
1537
|
* @param {string} [bucketName] - The name of the bucket. If not provided, the default bucket name will be used.
|
|
1159
1538
|
* @param {string} [uploadId] - The upload ID to filter the results by.
|
|
1539
|
+
* @param {ObjectStorageOptions} [objectStorageOptions] - The options for the object storage service.
|
|
1160
1540
|
* @return {Promise<ListPartsMultipartUploadResponse>} A promise that resolves to the list of multipart uploads for the specified key.
|
|
1161
1541
|
*/
|
|
1162
|
-
static async listMultipartUploadsForKey(key, bucketName, uploadId) {
|
|
1163
|
-
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName).then((instance) => instance.listMultipartUploadsForKey(key, uploadId));
|
|
1542
|
+
static async listMultipartUploadsForKey(key, bucketName, uploadId, objectStorageOptions) {
|
|
1543
|
+
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName, objectStorageOptions).then((instance) => instance.listMultipartUploadsForKey(key, uploadId));
|
|
1164
1544
|
}
|
|
1165
1545
|
/**
|
|
1166
1546
|
* Retrieves a list of all multipart uploads for a specified bucket in the object storage service.
|
|
1167
1547
|
*
|
|
1168
1548
|
* @param {string} [bucketName] - The name of the bucket. If not provided, the default bucket name will be used.
|
|
1549
|
+
* @param {ObjectStorageOptions} [objectStorageOptions] - The options for the object storage service.
|
|
1169
1550
|
* @return {Promise<ListMultipartUploadsResponse>} A promise that resolves to the list of multipart uploads for the specified bucket.
|
|
1170
1551
|
*/
|
|
1171
|
-
static async listMultipartUploadsForBucket(bucketName) {
|
|
1172
|
-
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName).then((instance) => instance.listMultipartUploadsForBucket());
|
|
1552
|
+
static async listMultipartUploadsForBucket(bucketName, objectStorageOptions) {
|
|
1553
|
+
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName, objectStorageOptions).then((instance) => instance.listMultipartUploadsForBucket());
|
|
1173
1554
|
}
|
|
1174
1555
|
/**
|
|
1175
1556
|
* Uploads a multipart file to the specified bucket in the object storage service.
|
|
@@ -1179,10 +1560,11 @@ var _ObjectStorageService = class _ObjectStorageService {
|
|
|
1179
1560
|
* @param {number} partNumber - The number of the part being uploaded.
|
|
1180
1561
|
* @param {string} [uploadId] - The ID of the multipart upload.
|
|
1181
1562
|
* @param {string} [bucketName] - The name of the bucket to upload the file to. If not provided, the default bucket name will be used.
|
|
1563
|
+
* @param {ObjectStorageOptions} [objectStorageOptions] - The options for the object storage service.
|
|
1182
1564
|
* @return {Promise<string>} A Promise that resolves to the base64 encoded block ID of the uploaded part.
|
|
1183
1565
|
*/
|
|
1184
|
-
static async uploadMultipart(key, file, partNumber, uploadId, bucketName) {
|
|
1185
|
-
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName).then((instance) => instance.uploadMultipart(key, file, partNumber, uploadId));
|
|
1566
|
+
static async uploadMultipart(key, file, partNumber, uploadId, bucketName, objectStorageOptions) {
|
|
1567
|
+
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName, objectStorageOptions).then((instance) => instance.uploadMultipart(key, file, partNumber, uploadId));
|
|
1186
1568
|
}
|
|
1187
1569
|
/**
|
|
1188
1570
|
* Completes a multipart upload for the specified object in the object storage service.
|
|
@@ -1190,10 +1572,11 @@ var _ObjectStorageService = class _ObjectStorageService {
|
|
|
1190
1572
|
* @param {string} key - The key of the object to complete the multipart upload for.
|
|
1191
1573
|
* @param {string} uploadId - The ID of the multipart upload to complete.
|
|
1192
1574
|
* @param {string} [bucketName] - The name of the bucket to complete the multipart upload in. If not provided, the default bucket name will be used.
|
|
1575
|
+
* @param {ObjectStorageOptions} [objectStorageOptions] - The options for the object storage service.
|
|
1193
1576
|
* @return {Promise<void>} A Promise that resolves when the multipart upload is completed.
|
|
1194
1577
|
*/
|
|
1195
|
-
static async completeMultipartUpload(key, uploadId, bucketName) {
|
|
1196
|
-
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName).then((instance) => instance.completeMultipartUpload(key, uploadId));
|
|
1578
|
+
static async completeMultipartUpload(key, uploadId, bucketName, objectStorageOptions) {
|
|
1579
|
+
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName, objectStorageOptions).then((instance) => instance.completeMultipartUpload(key, uploadId));
|
|
1197
1580
|
}
|
|
1198
1581
|
/**
|
|
1199
1582
|
* Aborts a multipart upload for the specified object in the object storage service.
|
|
@@ -1201,10 +1584,11 @@ var _ObjectStorageService = class _ObjectStorageService {
|
|
|
1201
1584
|
* @param {string} key - The key of the object to abort the multipart upload for.
|
|
1202
1585
|
* @param {string} uploadId - The ID of the multipart upload to abort.
|
|
1203
1586
|
* @param {string} [bucketName] - The name of the bucket to abort the multipart upload in. If not provided, the default bucket name will be used.
|
|
1587
|
+
* @param {ObjectStorageOptions} [objectStorageOptions] - The options for the object storage service.
|
|
1204
1588
|
* @return {Promise<void>} A Promise that resolves when the multipart upload is aborted.
|
|
1205
1589
|
*/
|
|
1206
|
-
static async abortMultipartUpload(key, uploadId, bucketName) {
|
|
1207
|
-
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName).then((instance) => instance.abortMultipartUpload(key, uploadId));
|
|
1590
|
+
static async abortMultipartUpload(key, uploadId, bucketName, objectStorageOptions) {
|
|
1591
|
+
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName, objectStorageOptions).then((instance) => instance.abortMultipartUpload(key, uploadId));
|
|
1208
1592
|
}
|
|
1209
1593
|
/**
|
|
1210
1594
|
* Retrieves a presigned URL for a specific part of a multipart upload.
|