@hdriel/aws-utils 1.3.2 → 1.3.4
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 +15 -5
- package/dist/index.js +15 -5
- package/package.json +4 -2
package/dist/index.cjs
CHANGED
|
@@ -286,6 +286,7 @@ var import_client_s37 = require("@aws-sdk/client-s3");
|
|
|
286
286
|
|
|
287
287
|
// src/aws/s3/s3-stream.ts
|
|
288
288
|
var import_pathe2 = require("pathe");
|
|
289
|
+
var import_mime_types = __toESM(require("mime-types"), 1);
|
|
289
290
|
var import_stream = require("stream");
|
|
290
291
|
var import_util = require("util");
|
|
291
292
|
var import_buffer2 = require("buffer");
|
|
@@ -1666,14 +1667,20 @@ var S3Stream = class _S3Stream extends S3File {
|
|
|
1666
1667
|
const fileName = filename || normalizedKey.split("/").pop() || `${Date.now()}.${ext}`;
|
|
1667
1668
|
const inlineTypes = ["text/", "image/", "application/pdf", "video/", "audio/"];
|
|
1668
1669
|
const canDisplayInline = SUPPORTED_IFRAME_EXTENSIONS.includes(ext) || inlineTypes.some((type) => contentType.startsWith(type));
|
|
1669
|
-
|
|
1670
|
+
const shouldIncludeCharSet = contentType.startsWith("text/") || contentType === "application/json" || contentType === "application/xml" || contentType === "application/javascript" || contentType === "application/xhtml+xml";
|
|
1671
|
+
if (shouldIncludeCharSet) {
|
|
1672
|
+
res.setHeader("Content-Type", `${contentType}; charset=utf-8`);
|
|
1673
|
+
stream.setEncoding("utf8");
|
|
1674
|
+
} else {
|
|
1675
|
+
res.setHeader("Content-Type", contentType);
|
|
1676
|
+
}
|
|
1670
1677
|
if (fileInfo.ContentLength) {
|
|
1671
1678
|
res.setHeader("Content-Length", String(fileInfo.ContentLength));
|
|
1672
1679
|
}
|
|
1673
|
-
if (forDownloading ||
|
|
1674
|
-
res.setHeader("Content-Disposition", `attachment; filename="${encodeURIComponent(fileName)}"`);
|
|
1675
|
-
} else {
|
|
1680
|
+
if (forDownloading === false || forDownloading === void 0 && canDisplayInline) {
|
|
1676
1681
|
res.setHeader("Content-Disposition", `inline; filename="${encodeURIComponent(fileName)}"`);
|
|
1682
|
+
} else {
|
|
1683
|
+
res.setHeader("Content-Disposition", `attachment; filename="${encodeURIComponent(fileName)}"`);
|
|
1677
1684
|
}
|
|
1678
1685
|
const cachingAge = !_cachingAge || typeof _cachingAge === "number" ? _cachingAge : getTotalSeconds(_cachingAge);
|
|
1679
1686
|
if (cachingAge) {
|
|
@@ -1901,7 +1908,10 @@ var S3Stream = class _S3Stream extends S3File {
|
|
|
1901
1908
|
acl,
|
|
1902
1909
|
s3: this.s3Client,
|
|
1903
1910
|
bucket: this.bucket,
|
|
1904
|
-
contentType:
|
|
1911
|
+
contentType: function(_req, file, cb) {
|
|
1912
|
+
const contentType = file.mimetype || import_mime_types.default.lookup(file.originalname) || "application/octet-stream";
|
|
1913
|
+
cb(null, contentType);
|
|
1914
|
+
},
|
|
1905
1915
|
metadata: (req, file, cb) => __async(this, null, function* () {
|
|
1906
1916
|
const originalName = decodeURIComponent(file.originalname);
|
|
1907
1917
|
const baseMetadata = __spreadProps(__spreadValues({}, file), {
|
package/dist/index.js
CHANGED
|
@@ -246,6 +246,7 @@ import { ListObjectsV2Command as ListObjectsV2Command4 } from "@aws-sdk/client-s
|
|
|
246
246
|
|
|
247
247
|
// src/aws/s3/s3-stream.ts
|
|
248
248
|
import { basename as basename2, extname } from "pathe";
|
|
249
|
+
import mime from "mime-types";
|
|
249
250
|
import { pipeline } from "stream";
|
|
250
251
|
import { promisify } from "util";
|
|
251
252
|
import { Buffer as Buffer3 } from "buffer";
|
|
@@ -1654,14 +1655,20 @@ var S3Stream = class _S3Stream extends S3File {
|
|
|
1654
1655
|
const fileName = filename || normalizedKey.split("/").pop() || `${Date.now()}.${ext}`;
|
|
1655
1656
|
const inlineTypes = ["text/", "image/", "application/pdf", "video/", "audio/"];
|
|
1656
1657
|
const canDisplayInline = SUPPORTED_IFRAME_EXTENSIONS.includes(ext) || inlineTypes.some((type) => contentType.startsWith(type));
|
|
1657
|
-
|
|
1658
|
+
const shouldIncludeCharSet = contentType.startsWith("text/") || contentType === "application/json" || contentType === "application/xml" || contentType === "application/javascript" || contentType === "application/xhtml+xml";
|
|
1659
|
+
if (shouldIncludeCharSet) {
|
|
1660
|
+
res.setHeader("Content-Type", `${contentType}; charset=utf-8`);
|
|
1661
|
+
stream.setEncoding("utf8");
|
|
1662
|
+
} else {
|
|
1663
|
+
res.setHeader("Content-Type", contentType);
|
|
1664
|
+
}
|
|
1658
1665
|
if (fileInfo.ContentLength) {
|
|
1659
1666
|
res.setHeader("Content-Length", String(fileInfo.ContentLength));
|
|
1660
1667
|
}
|
|
1661
|
-
if (forDownloading ||
|
|
1662
|
-
res.setHeader("Content-Disposition", `attachment; filename="${encodeURIComponent(fileName)}"`);
|
|
1663
|
-
} else {
|
|
1668
|
+
if (forDownloading === false || forDownloading === void 0 && canDisplayInline) {
|
|
1664
1669
|
res.setHeader("Content-Disposition", `inline; filename="${encodeURIComponent(fileName)}"`);
|
|
1670
|
+
} else {
|
|
1671
|
+
res.setHeader("Content-Disposition", `attachment; filename="${encodeURIComponent(fileName)}"`);
|
|
1665
1672
|
}
|
|
1666
1673
|
const cachingAge = !_cachingAge || typeof _cachingAge === "number" ? _cachingAge : getTotalSeconds(_cachingAge);
|
|
1667
1674
|
if (cachingAge) {
|
|
@@ -1889,7 +1896,10 @@ var S3Stream = class _S3Stream extends S3File {
|
|
|
1889
1896
|
acl,
|
|
1890
1897
|
s3: this.s3Client,
|
|
1891
1898
|
bucket: this.bucket,
|
|
1892
|
-
contentType:
|
|
1899
|
+
contentType: function(_req, file, cb) {
|
|
1900
|
+
const contentType = file.mimetype || mime.lookup(file.originalname) || "application/octet-stream";
|
|
1901
|
+
cb(null, contentType);
|
|
1902
|
+
},
|
|
1893
1903
|
metadata: (req, file, cb) => __async(this, null, function* () {
|
|
1894
1904
|
const originalName = decodeURIComponent(file.originalname);
|
|
1895
1905
|
const baseMetadata = __spreadProps(__spreadValues({}, file), {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hdriel/aws-utils",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.4",
|
|
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",
|
|
@@ -49,6 +49,7 @@
|
|
|
49
49
|
"aws-crt": "1.27.3",
|
|
50
50
|
"aws-lambda": "1.0.7",
|
|
51
51
|
"bytes": "3.1.2",
|
|
52
|
+
"mime-types": "^3.0.1",
|
|
52
53
|
"ms": "2.1.3",
|
|
53
54
|
"multer": "2.0.2",
|
|
54
55
|
"multer-s3": "3.0.1",
|
|
@@ -62,6 +63,7 @@
|
|
|
62
63
|
"@types/aws-lambda": "8.10.153",
|
|
63
64
|
"@types/bytes": "3.1.5",
|
|
64
65
|
"@types/express": "5.0.3",
|
|
66
|
+
"@types/mime-types": "^3.0.1",
|
|
65
67
|
"@types/ms": "2.1.0",
|
|
66
68
|
"@types/multer": "2.0.0",
|
|
67
69
|
"@types/multer-s3": "3.0.3",
|
|
@@ -69,8 +71,8 @@
|
|
|
69
71
|
"express": "^5.1.0",
|
|
70
72
|
"prettier": "^3.6.2",
|
|
71
73
|
"ts-node": "^10.9.2",
|
|
72
|
-
"tsup": "^8.5.0",
|
|
73
74
|
"tslint": "^6.1.3",
|
|
75
|
+
"tsup": "^8.5.0",
|
|
74
76
|
"typescript": "^5.9.2"
|
|
75
77
|
}
|
|
76
78
|
}
|