@hdriel/aws-utils 1.2.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +7 -7
- package/dist/index.d.cts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +7 -7
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -279,6 +279,7 @@ var import_archiver = __toESM(require("archiver"), 1);
|
|
|
279
279
|
var import_node_stream2 = require("stream");
|
|
280
280
|
var import_multer_s3 = __toESM(require("multer-s3"), 1);
|
|
281
281
|
var import_multer = __toESM(require("multer"), 1);
|
|
282
|
+
var import_p_limit = __toESM(require("p-limit"), 1);
|
|
282
283
|
var import_client_s35 = require("@aws-sdk/client-s3");
|
|
283
284
|
|
|
284
285
|
// src/utils/consts.ts
|
|
@@ -289,10 +290,6 @@ var ACLs = /* @__PURE__ */ ((ACLs2) => {
|
|
|
289
290
|
return ACLs2;
|
|
290
291
|
})(ACLs || {});
|
|
291
292
|
|
|
292
|
-
// src/utils/concurrency.ts
|
|
293
|
-
var import_p_limit = __toESM(require("p-limit"), 1);
|
|
294
|
-
var s3Limiter = (0, import_p_limit.default)(4);
|
|
295
|
-
|
|
296
293
|
// src/utils/helpers.ts
|
|
297
294
|
var import_bytes = __toESM(require("bytes"), 1);
|
|
298
295
|
var import_ms = __toESM(require("ms"), 1);
|
|
@@ -1110,7 +1107,7 @@ var S3File = class extends S3Directory {
|
|
|
1110
1107
|
return url;
|
|
1111
1108
|
});
|
|
1112
1109
|
}
|
|
1113
|
-
sizeOf(fileKey, unit) {
|
|
1110
|
+
sizeOf(fileKey, unit = "b") {
|
|
1114
1111
|
return __async(this, null, function* () {
|
|
1115
1112
|
var _a2, _b, _c;
|
|
1116
1113
|
const normalizedKey = getNormalizedPath(fileKey);
|
|
@@ -1232,9 +1229,10 @@ var S3File = class extends S3Directory {
|
|
|
1232
1229
|
var pump = (0, import_util.promisify)(import_stream.pipeline);
|
|
1233
1230
|
var S3Stream = class _S3Stream extends S3File {
|
|
1234
1231
|
constructor(_a2) {
|
|
1235
|
-
var _b = _a2, { maxUploadFileSizeRestriction = "10GB" } = _b, props = __objRest(_b, ["maxUploadFileSizeRestriction"]);
|
|
1232
|
+
var _b = _a2, { maxUploadFileSizeRestriction = "10GB", concurrencyVideoLimit = 0 } = _b, props = __objRest(_b, ["maxUploadFileSizeRestriction", "concurrencyVideoLimit"]);
|
|
1236
1233
|
super(props);
|
|
1237
1234
|
__publicField(this, "maxUploadFileSizeRestriction");
|
|
1235
|
+
__publicField(this, "s3Limiter");
|
|
1238
1236
|
__publicField(this, "streamImageFileCtrl", ({
|
|
1239
1237
|
fileKey: _fileKey,
|
|
1240
1238
|
queryField = "file",
|
|
@@ -1321,6 +1319,7 @@ var S3Stream = class _S3Stream extends S3File {
|
|
|
1321
1319
|
});
|
|
1322
1320
|
});
|
|
1323
1321
|
this.maxUploadFileSizeRestriction = maxUploadFileSizeRestriction;
|
|
1322
|
+
this.s3Limiter = concurrencyVideoLimit ? (0, import_p_limit.default)(concurrencyVideoLimit) : null;
|
|
1324
1323
|
}
|
|
1325
1324
|
streamObjectFile(_0) {
|
|
1326
1325
|
return __async(this, arguments, function* (fileKey, {
|
|
@@ -1358,7 +1357,7 @@ var S3Stream = class _S3Stream extends S3File {
|
|
|
1358
1357
|
Bucket: this.bucket,
|
|
1359
1358
|
Key: normalizedKey
|
|
1360
1359
|
}, Range ? { Range } : {}));
|
|
1361
|
-
const data = yield s3Limiter(() => this.execute(cmd, { abortSignal }));
|
|
1360
|
+
const data = this.s3Limiter ? yield this.s3Limiter(() => this.execute(cmd, { abortSignal })) : yield this.execute(cmd, { abortSignal });
|
|
1362
1361
|
const body = data.Body;
|
|
1363
1362
|
if (!body) return null;
|
|
1364
1363
|
return {
|
|
@@ -1785,6 +1784,7 @@ var S3Stream = class _S3Stream extends S3File {
|
|
|
1785
1784
|
}),
|
|
1786
1785
|
key: (req, file, cb) => __async(this, null, function* () {
|
|
1787
1786
|
let filename;
|
|
1787
|
+
file.originalname = decodeURIComponent(file.originalname);
|
|
1788
1788
|
if (typeof _filename === "function") {
|
|
1789
1789
|
filename = yield _filename(req, file);
|
|
1790
1790
|
} else if (_filename) {
|
package/dist/index.d.cts
CHANGED
|
@@ -263,7 +263,7 @@ declare class S3File extends S3Directory {
|
|
|
263
263
|
taggingFile(fileKey: string, tag: Tag | Tag[]): Promise<boolean>;
|
|
264
264
|
fileVersion(fileKey: string): Promise<string>;
|
|
265
265
|
fileUrl(fileKey: string, expiresIn?: number | StringValue): Promise<string>;
|
|
266
|
-
sizeOf(fileKey: string, unit
|
|
266
|
+
sizeOf(fileKey: string, unit?: Unit): Promise<number>;
|
|
267
267
|
fileExists(fileKey: string): Promise<boolean>;
|
|
268
268
|
fileContent(fileKey: string, format?: 'buffer' | 'base64' | 'utf8'): Promise<Buffer | string>;
|
|
269
269
|
uploadFileContent(fileKey: string, fileData: Buffer | Readable | string | Uint8Array | object, { acl, version, prettier, }?: {
|
|
@@ -276,10 +276,12 @@ declare class S3File extends S3Directory {
|
|
|
276
276
|
|
|
277
277
|
type S3StreamProps = S3FileProps & {
|
|
278
278
|
maxUploadFileSizeRestriction?: ByteUnitStringValue;
|
|
279
|
+
concurrencyVideoLimit?: number | null;
|
|
279
280
|
};
|
|
280
281
|
declare class S3Stream extends S3File {
|
|
281
282
|
private readonly maxUploadFileSizeRestriction;
|
|
282
|
-
|
|
283
|
+
private readonly s3Limiter;
|
|
284
|
+
constructor({ maxUploadFileSizeRestriction, concurrencyVideoLimit, ...props }: S3StreamProps);
|
|
283
285
|
protected streamObjectFile(fileKey: string, { Range, checkFileExists, abortSignal, }?: {
|
|
284
286
|
Range?: string;
|
|
285
287
|
checkFileExists?: boolean;
|
package/dist/index.d.ts
CHANGED
|
@@ -263,7 +263,7 @@ declare class S3File extends S3Directory {
|
|
|
263
263
|
taggingFile(fileKey: string, tag: Tag | Tag[]): Promise<boolean>;
|
|
264
264
|
fileVersion(fileKey: string): Promise<string>;
|
|
265
265
|
fileUrl(fileKey: string, expiresIn?: number | StringValue): Promise<string>;
|
|
266
|
-
sizeOf(fileKey: string, unit
|
|
266
|
+
sizeOf(fileKey: string, unit?: Unit): Promise<number>;
|
|
267
267
|
fileExists(fileKey: string): Promise<boolean>;
|
|
268
268
|
fileContent(fileKey: string, format?: 'buffer' | 'base64' | 'utf8'): Promise<Buffer | string>;
|
|
269
269
|
uploadFileContent(fileKey: string, fileData: Buffer | Readable | string | Uint8Array | object, { acl, version, prettier, }?: {
|
|
@@ -276,10 +276,12 @@ declare class S3File extends S3Directory {
|
|
|
276
276
|
|
|
277
277
|
type S3StreamProps = S3FileProps & {
|
|
278
278
|
maxUploadFileSizeRestriction?: ByteUnitStringValue;
|
|
279
|
+
concurrencyVideoLimit?: number | null;
|
|
279
280
|
};
|
|
280
281
|
declare class S3Stream extends S3File {
|
|
281
282
|
private readonly maxUploadFileSizeRestriction;
|
|
282
|
-
|
|
283
|
+
private readonly s3Limiter;
|
|
284
|
+
constructor({ maxUploadFileSizeRestriction, concurrencyVideoLimit, ...props }: S3StreamProps);
|
|
283
285
|
protected streamObjectFile(fileKey: string, { Range, checkFileExists, abortSignal, }?: {
|
|
284
286
|
Range?: string;
|
|
285
287
|
checkFileExists?: boolean;
|
package/dist/index.js
CHANGED
|
@@ -240,6 +240,7 @@ import archiver from "archiver";
|
|
|
240
240
|
import { Readable as Readable2 } from "stream";
|
|
241
241
|
import multerS3 from "multer-s3";
|
|
242
242
|
import multer from "multer";
|
|
243
|
+
import pLimit from "p-limit";
|
|
243
244
|
import { GetObjectCommand as GetObjectCommand2 } from "@aws-sdk/client-s3";
|
|
244
245
|
|
|
245
246
|
// src/utils/consts.ts
|
|
@@ -250,10 +251,6 @@ var ACLs = /* @__PURE__ */ ((ACLs2) => {
|
|
|
250
251
|
return ACLs2;
|
|
251
252
|
})(ACLs || {});
|
|
252
253
|
|
|
253
|
-
// src/utils/concurrency.ts
|
|
254
|
-
import pLimit from "p-limit";
|
|
255
|
-
var s3Limiter = pLimit(4);
|
|
256
|
-
|
|
257
254
|
// src/utils/helpers.ts
|
|
258
255
|
import bytes from "bytes";
|
|
259
256
|
import ms from "ms";
|
|
@@ -1099,7 +1096,7 @@ var S3File = class extends S3Directory {
|
|
|
1099
1096
|
return url;
|
|
1100
1097
|
});
|
|
1101
1098
|
}
|
|
1102
|
-
sizeOf(fileKey, unit) {
|
|
1099
|
+
sizeOf(fileKey, unit = "b") {
|
|
1103
1100
|
return __async(this, null, function* () {
|
|
1104
1101
|
var _a2, _b, _c;
|
|
1105
1102
|
const normalizedKey = getNormalizedPath(fileKey);
|
|
@@ -1221,9 +1218,10 @@ var S3File = class extends S3Directory {
|
|
|
1221
1218
|
var pump = promisify(pipeline);
|
|
1222
1219
|
var S3Stream = class _S3Stream extends S3File {
|
|
1223
1220
|
constructor(_a2) {
|
|
1224
|
-
var _b = _a2, { maxUploadFileSizeRestriction = "10GB" } = _b, props = __objRest(_b, ["maxUploadFileSizeRestriction"]);
|
|
1221
|
+
var _b = _a2, { maxUploadFileSizeRestriction = "10GB", concurrencyVideoLimit = 0 } = _b, props = __objRest(_b, ["maxUploadFileSizeRestriction", "concurrencyVideoLimit"]);
|
|
1225
1222
|
super(props);
|
|
1226
1223
|
__publicField(this, "maxUploadFileSizeRestriction");
|
|
1224
|
+
__publicField(this, "s3Limiter");
|
|
1227
1225
|
__publicField(this, "streamImageFileCtrl", ({
|
|
1228
1226
|
fileKey: _fileKey,
|
|
1229
1227
|
queryField = "file",
|
|
@@ -1310,6 +1308,7 @@ var S3Stream = class _S3Stream extends S3File {
|
|
|
1310
1308
|
});
|
|
1311
1309
|
});
|
|
1312
1310
|
this.maxUploadFileSizeRestriction = maxUploadFileSizeRestriction;
|
|
1311
|
+
this.s3Limiter = concurrencyVideoLimit ? pLimit(concurrencyVideoLimit) : null;
|
|
1313
1312
|
}
|
|
1314
1313
|
streamObjectFile(_0) {
|
|
1315
1314
|
return __async(this, arguments, function* (fileKey, {
|
|
@@ -1347,7 +1346,7 @@ var S3Stream = class _S3Stream extends S3File {
|
|
|
1347
1346
|
Bucket: this.bucket,
|
|
1348
1347
|
Key: normalizedKey
|
|
1349
1348
|
}, Range ? { Range } : {}));
|
|
1350
|
-
const data = yield s3Limiter(() => this.execute(cmd, { abortSignal }));
|
|
1349
|
+
const data = this.s3Limiter ? yield this.s3Limiter(() => this.execute(cmd, { abortSignal })) : yield this.execute(cmd, { abortSignal });
|
|
1351
1350
|
const body = data.Body;
|
|
1352
1351
|
if (!body) return null;
|
|
1353
1352
|
return {
|
|
@@ -1774,6 +1773,7 @@ var S3Stream = class _S3Stream extends S3File {
|
|
|
1774
1773
|
}),
|
|
1775
1774
|
key: (req, file, cb) => __async(this, null, function* () {
|
|
1776
1775
|
let filename;
|
|
1776
|
+
file.originalname = decodeURIComponent(file.originalname);
|
|
1777
1777
|
if (typeof _filename === "function") {
|
|
1778
1778
|
filename = yield _filename(req, file);
|
|
1779
1779
|
} else if (_filename) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hdriel/aws-utils",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "Simplified AWS SDK (v3) utilities for S3 (upload, download, streaming) with TypeScript support",
|
|
5
5
|
"author": "Hadriel Benjo (https://github.com/hdriel)",
|
|
6
6
|
"type": "module",
|