@dimah-s3/server 1.5.11 → 1.6.0
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/api/index.js +26 -12
- package/dist/api/index.js.map +1 -1
- package/dist/api/routes/catalog.d.ts.map +1 -1
- package/dist/api/routes/download.d.ts +2 -0
- package/dist/api/routes/download.d.ts.map +1 -1
- package/dist/api/routes/index.d.ts +2 -0
- package/dist/api/routes/index.d.ts.map +1 -1
- package/dist/helpers/expires.d.ts +15 -0
- package/dist/helpers/expires.d.ts.map +1 -1
- package/dist/helpers/index.d.ts +1 -1
- package/dist/helpers/index.d.ts.map +1 -1
- package/dist/index.js +26 -12
- package/dist/index.js.map +1 -1
- package/dist/plugins.js +26 -12
- package/dist/plugins.js.map +1 -1
- package/dist/types/config.d.ts +3 -1
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/hook-contexts.d.ts +12 -1
- package/dist/types/hook-contexts.d.ts.map +1 -1
- package/package.json +11 -11
package/dist/plugins.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { S3_API_ROUTES, isAPIError, APIError, S3_ERROR_CODES, confirmBodySchema, deleteQuerySchema, deleteBatchBodySchema, downloadQuerySchema, fileQuerySchema, multipartAbortBodySchema, multipartCompleteBodySchema, multipartInitBodySchema, multipartListPartsQuerySchema, multipartSignPartBodySchema, uploadBodySchema,
|
|
1
|
+
import { S3_API_ROUTES, isAPIError, APIError, S3_ERROR_CODES, confirmBodySchema, deleteQuerySchema, deleteBatchBodySchema, downloadQuerySchema, fileQuerySchema, multipartAbortBodySchema, multipartCompleteBodySchema, multipartInitBodySchema, multipartListPartsQuerySchema, multipartSignPartBodySchema, uploadBodySchema, buildContentDisposition, S3_MAX_EXPIRES_IN, S3_MAX_POST_OBJECT_BYTES, resolveStoredFileName, S3_DEFAULT_EXPIRES_IN, matchesFileTypes, ROUTE_NAME_PATTERN, normalizeObjectKey, sanitizeFileName } from '@dimah-s3/core';
|
|
2
2
|
import { DeleteObjectCommand, GetObjectCommand, CreateMultipartUploadCommand, UploadPartCommand, PutObjectCommand, ListPartsCommand, AbortMultipartUploadCommand, CompleteMultipartUploadCommand, HeadObjectCommand } from '@aws-sdk/client-s3';
|
|
3
3
|
import { createMiddleware, createEndpoint } from 'better-call';
|
|
4
4
|
import * as z from 'zod';
|
|
@@ -102,6 +102,15 @@ function normalizeExpiresIn(value, maxExpiresIn = S3_MAX_EXPIRES_IN) {
|
|
|
102
102
|
const max = Number.isFinite(maxExpiresIn) && maxExpiresIn > 0 ? Math.floor(maxExpiresIn) : S3_MAX_EXPIRES_IN;
|
|
103
103
|
return Math.min(expires, max);
|
|
104
104
|
}
|
|
105
|
+
function clampDownloadExpiresIn(options) {
|
|
106
|
+
const max = options.maxExpiresIn;
|
|
107
|
+
if (options.resolvedExpiresIn != null) {
|
|
108
|
+
return normalizeExpiresIn(options.resolvedExpiresIn, max);
|
|
109
|
+
}
|
|
110
|
+
const cap = normalizeExpiresIn(options.routeExpiresIn, max);
|
|
111
|
+
if (options.requested == null) return cap;
|
|
112
|
+
return Math.min(normalizeExpiresIn(options.requested, max), cap);
|
|
113
|
+
}
|
|
105
114
|
|
|
106
115
|
// src/helpers/logger.ts
|
|
107
116
|
var defaultLogger = {
|
|
@@ -792,21 +801,25 @@ async function handleDownload(config, input, request) {
|
|
|
792
801
|
const resolved = await route.download.resolve?.({
|
|
793
802
|
...stored,
|
|
794
803
|
fileName: input.fileName,
|
|
795
|
-
disposition: input.disposition ?? route.download.disposition
|
|
804
|
+
disposition: input.disposition ?? route.download.disposition,
|
|
805
|
+
expiresIn: input.expiresIn
|
|
796
806
|
});
|
|
797
807
|
const fileName = resolved?.fileName ?? input.fileName;
|
|
798
808
|
const disposition = resolved?.disposition ?? input.disposition ?? route.download.disposition ?? "attachment";
|
|
799
|
-
const
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
809
|
+
const mode = route.download.mode ?? "presign";
|
|
810
|
+
const expiresIn = mode === "proxy" ? 0 : clampDownloadExpiresIn({
|
|
811
|
+
requested: input.expiresIn,
|
|
812
|
+
routeExpiresIn: route.download.expiresIn,
|
|
813
|
+
resolvedExpiresIn: resolved?.expiresIn,
|
|
814
|
+
maxExpiresIn: config.maxExpiresIn
|
|
815
|
+
});
|
|
803
816
|
await runHook(route.download.guard, {
|
|
804
817
|
...stored,
|
|
805
818
|
fileName,
|
|
806
|
-
disposition
|
|
819
|
+
disposition,
|
|
820
|
+
expiresIn
|
|
807
821
|
});
|
|
808
822
|
await headObjectOrNotFound(route.client, bucket, key);
|
|
809
|
-
const mode = route.download.mode ?? "presign";
|
|
810
823
|
const contentDisposition = fileName ? buildContentDisposition(fileName, disposition) : disposition;
|
|
811
824
|
const url = mode === "proxy" ? fileUrl(request, config.basePath ?? "/api/s3", {
|
|
812
825
|
route: input.route,
|
|
@@ -828,7 +841,7 @@ async function handleDownload(config, input, request) {
|
|
|
828
841
|
...stored,
|
|
829
842
|
fileName,
|
|
830
843
|
url,
|
|
831
|
-
expiresIn
|
|
844
|
+
expiresIn
|
|
832
845
|
},
|
|
833
846
|
config
|
|
834
847
|
);
|
|
@@ -836,7 +849,7 @@ async function handleDownload(config, input, request) {
|
|
|
836
849
|
bucket,
|
|
837
850
|
key,
|
|
838
851
|
url,
|
|
839
|
-
expiresIn
|
|
852
|
+
expiresIn,
|
|
840
853
|
mode,
|
|
841
854
|
disposition
|
|
842
855
|
};
|
|
@@ -859,10 +872,11 @@ function catalogUpload(upload2) {
|
|
|
859
872
|
...upload2.replace ? { replace: upload2.replace } : {}
|
|
860
873
|
};
|
|
861
874
|
}
|
|
862
|
-
function catalogDownload(download2) {
|
|
875
|
+
function catalogDownload(download2, maxExpiresIn) {
|
|
863
876
|
if (!isEnabled(download2)) return { enabled: false };
|
|
864
877
|
return {
|
|
865
878
|
enabled: true,
|
|
879
|
+
expiresIn: normalizeExpiresIn(download2.expiresIn, maxExpiresIn),
|
|
866
880
|
...download2.disposition ? { disposition: download2.disposition } : {},
|
|
867
881
|
...download2.mode ? { mode: download2.mode } : {}
|
|
868
882
|
};
|
|
@@ -872,7 +886,7 @@ function buildRouteCatalog(config) {
|
|
|
872
886
|
for (const [name, route] of Object.entries(config.routes)) {
|
|
873
887
|
routes[name] = {
|
|
874
888
|
upload: catalogUpload(route.upload),
|
|
875
|
-
download: catalogDownload(route.download),
|
|
889
|
+
download: catalogDownload(route.download, config.maxExpiresIn),
|
|
876
890
|
delete: isEnabled(route.delete) ? { enabled: true } : { enabled: false }
|
|
877
891
|
};
|
|
878
892
|
}
|