@dimah-s3/server 1.5.11 → 1.7.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.
@@ -9,11 +9,13 @@ export declare const download: import("better-call").StrictEndpoint<"/presign/do
9
9
  key: string;
10
10
  fileName?: unknown;
11
11
  disposition?: "attachment" | "inline" | undefined;
12
+ expiresIn?: unknown;
12
13
  }, {
13
14
  route: string;
14
15
  key: string;
15
16
  fileName?: unknown;
16
17
  disposition?: "attachment" | "inline" | undefined;
18
+ expiresIn?: unknown;
17
19
  }>;
18
20
  }, DownloadPresignResponse>;
19
21
  //# sourceMappingURL=download.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"download.d.ts","sourceRoot":"","sources":["../../../src/api/routes/download.ts"],"names":[],"mappings":"AAEA,OAAO,EAIL,KAAK,uBAAuB,EAC7B,MAAM,gBAAgB,CAAC;AAkHxB,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;2BAMpB,CAAC"}
1
+ {"version":3,"file":"download.d.ts","sourceRoot":"","sources":["../../../src/api/routes/download.ts"],"names":[],"mappings":"AAEA,OAAO,EAIL,KAAK,uBAAuB,EAC7B,MAAM,gBAAgB,CAAC;AAgIxB,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;2BAMpB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../../src/api/routes/file.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,qBAAqB,EAEtB,MAAM,gBAAgB,CAAC;AA8ExB,eAAO,MAAM,IAAI;;;;;;;;;;;;;;;;YAMhB,CAAC;AAEF,OAAO,EAAE,qBAAqB,EAAE,CAAC"}
1
+ {"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../../src/api/routes/file.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,qBAAqB,EAEtB,MAAM,gBAAgB,CAAC;AAwFxB,eAAO,MAAM,IAAI;;;;;;;;;;;;;;;;YAMhB,CAAC;AAEF,OAAO,EAAE,qBAAqB,EAAE,CAAC"}
@@ -42,11 +42,13 @@ export declare const coreEndpoints: {
42
42
  key: string;
43
43
  fileName?: unknown;
44
44
  disposition?: "attachment" | "inline" | undefined;
45
+ expiresIn?: unknown;
45
46
  }, {
46
47
  route: string;
47
48
  key: string;
48
49
  fileName?: unknown;
49
50
  disposition?: "attachment" | "inline" | undefined;
51
+ expiresIn?: unknown;
50
52
  }>;
51
53
  }, import("@dimah-s3/core").DownloadPresignResponse>;
52
54
  catalog: import("better-call").StrictEndpoint<"/routes", {
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/api/routes/index.ts"],"names":[],"mappings":"AAaA,2DAA2D;AAC3D,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAazB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,OAAO,aAAa,CAAC;AAEjD,eAAO,MAAM,mBAAmB,EAE3B,CAAC,MAAM,aAAa,CAAC,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/api/routes/index.ts"],"names":[],"mappings":"AAaA,2DAA2D;AAC3D,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAazB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,OAAO,aAAa,CAAC;AAEjD,eAAO,MAAM,mBAAmB,EAE3B,CAAC,MAAM,aAAa,CAAC,EAAE,CAAC"}
@@ -3,4 +3,19 @@
3
3
  * to {@link maxExpiresIn} (SigV4 max by default).
4
4
  */
5
5
  export declare function normalizeExpiresIn(value: unknown, maxExpiresIn?: number): number;
6
+ /**
7
+ * Signed download TTL.
8
+ * `download.resolve` wins, then the shorter of the client request and the
9
+ * route cap. Both are clamped to `maxExpiresIn`.
10
+ */
11
+ export declare function clampDownloadExpiresIn(options: {
12
+ /** Client `expiresIn`, when the query sent one. */
13
+ requested?: number;
14
+ /** Route `download.expiresIn`. Omitted uses the protocol default. */
15
+ routeExpiresIn?: number;
16
+ /** `download.resolve` return. Replaces the cap and the client request. */
17
+ resolvedExpiresIn?: number;
18
+ /** Instance ceiling. Defaults to the SigV4 maximum. */
19
+ maxExpiresIn?: number;
20
+ }): number;
6
21
  //# sourceMappingURL=expires.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"expires.d.ts","sourceRoot":"","sources":["../../src/helpers/expires.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,OAAO,EACd,YAAY,GAAE,MAA0B,GACvC,MAAM,CASR"}
1
+ {"version":3,"file":"expires.d.ts","sourceRoot":"","sources":["../../src/helpers/expires.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,OAAO,EACd,YAAY,GAAE,MAA0B,GACvC,MAAM,CASR;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE;IAC9C,mDAAmD;IACnD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,qEAAqE;IACrE,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,0EAA0E;IAC1E,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,uDAAuD;IACvD,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,GAAG,MAAM,CAQT"}
@@ -1,4 +1,6 @@
1
1
  import { type HeadObjectCommandOutput, type S3Client } from "@aws-sdk/client-s3";
2
+ /** HeadObject as a yes/no. Errors other than not-found still throw. */
3
+ export declare function objectExists(client: S3Client, bucket: string, key: string): Promise<boolean>;
2
4
  /** HeadObject, mapping AWS not-found to `OBJECT_NOT_FOUND`. */
3
5
  export declare function headObjectOrNotFound(client: S3Client, bucket: string, key: string): Promise<HeadObjectCommandOutput>;
4
6
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"head-object.d.ts","sourceRoot":"","sources":["../../src/helpers/head-object.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,uBAAuB,EAC5B,KAAK,QAAQ,EACd,MAAM,oBAAoB,CAAC;AAI5B,+DAA+D;AAC/D,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,QAAQ,EAChB,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,uBAAuB,CAAC,CAIlC;AAED;;;GAGG;AACH,wBAAsB,gCAAgC,CACpD,MAAM,EAAE,QAAQ,EAChB,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,uBAAuB,CAAC,CAgBlC;AAED,yEAAyE;AACzE,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,uBAAuB,GAAG,MAAM,CAK1E"}
1
+ {"version":3,"file":"head-object.d.ts","sourceRoot":"","sources":["../../src/helpers/head-object.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,uBAAuB,EAC5B,KAAK,QAAQ,EACd,MAAM,oBAAoB,CAAC;AAI5B,uEAAuE;AACvE,wBAAsB,YAAY,CAChC,MAAM,EAAE,QAAQ,EAChB,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,OAAO,CAAC,CAQlB;AAED,+DAA+D;AAC/D,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,QAAQ,EAChB,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,uBAAuB,CAAC,CAIlC;AAED;;;GAGG;AACH,wBAAsB,gCAAgC,CACpD,MAAM,EAAE,QAAQ,EAChB,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,uBAAuB,CAAC,CAgBlC;AAED,yEAAyE;AACzE,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,uBAAuB,GAAG,MAAM,CAK1E"}
@@ -1,6 +1,6 @@
1
1
  export { abortMultipartBestEffort, deleteObjectBestEffort, } from "./best-effort";
2
2
  export { isAwsNotFound, sendOrObjectNotFound } from "./is-aws-not-found";
3
- export { normalizeExpiresIn } from "./expires";
3
+ export { clampDownloadExpiresIn, normalizeExpiresIn } from "./expires";
4
4
  export { runHook, runLifecycleHook, runObjectHook } from "./hooks";
5
5
  export { isEnabled, isFeatureOn, normalizeFeature, normalizeRoute, normalizeRoutes, } from "./features";
6
6
  export { requestFromHeaders } from "./request";
@@ -9,8 +9,9 @@ export type { ResolvedObject } from "./resolve-target";
9
9
  export { assertFeatureEnabled, getResolvedRoute, openRoute, openStoredTarget, openUploadTarget, storedObjectContext, } from "./resolve-route";
10
10
  export type { OpenedTarget, OpenedUploadTarget, OpenUploadInput, } from "./resolve-route";
11
11
  export { assertDeclaredConstraints, assertVerifiedConstraints, assertWithinMaxFileSize, } from "./constraints";
12
- export { headObjectAfterMultipartComplete, headObjectOrNotFound, requireContentLength, } from "./head-object";
12
+ export { headObjectAfterMultipartComplete, headObjectOrNotFound, objectExists, requireContentLength, } from "./head-object";
13
13
  export { listAllParts, listedPartsByteSize } from "./list-parts";
14
+ export { applyInlineTypes } from "./inline-types";
14
15
  export { resolveLogger, defaultLogger } from "./logger";
15
16
  export { finalizeConfirmedObject } from "./finalize-confirmed";
16
17
  export { DIMAH_PREVIOUS_KEY_META, previousKeyFromMetadata, stripPreviousKeyMeta, } from "./previous-key";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,sBAAsB,GACvB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACnE,OAAO,EACL,SAAS,EACT,WAAW,EACX,gBAAgB,EAChB,cAAc,EACd,eAAe,GAChB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EACL,oBAAoB,EACpB,gBAAgB,EAChB,SAAS,EACT,gBAAgB,EAChB,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,iBAAiB,CAAC;AACzB,YAAY,EACV,YAAY,EACZ,kBAAkB,EAClB,eAAe,GAChB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,yBAAyB,EACzB,yBAAyB,EACzB,uBAAuB,GACxB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,gCAAgC,EAChC,oBAAoB,EACpB,oBAAoB,GACrB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACxD,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EACL,uBAAuB,EACvB,uBAAuB,EACvB,oBAAoB,GACrB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,sBAAsB,GACvB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AACzE,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AACvE,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACnE,OAAO,EACL,SAAS,EACT,WAAW,EACX,gBAAgB,EAChB,cAAc,EACd,eAAe,GAChB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EACL,oBAAoB,EACpB,gBAAgB,EAChB,SAAS,EACT,gBAAgB,EAChB,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,iBAAiB,CAAC;AACzB,YAAY,EACV,YAAY,EACZ,kBAAkB,EAClB,eAAe,GAChB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,yBAAyB,EACzB,yBAAyB,EACzB,uBAAuB,GACxB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,gCAAgC,EAChC,oBAAoB,EACpB,YAAY,EACZ,oBAAoB,GACrB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACxD,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EACL,uBAAuB,EACvB,uBAAuB,EACvB,oBAAoB,GACrB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,aAAa,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { type ContentDispositionType, type ResolveInlineDispositionResult } from "@dimah-s3/core";
2
+ /**
3
+ * Route `download.inlineTypes` after HeadObject. Without a list, the
4
+ * disposition is signed as is.
5
+ */
6
+ export declare function applyInlineTypes(inlineTypes: readonly string[] | undefined, input: {
7
+ key: string;
8
+ fileName?: string;
9
+ disposition: ContentDispositionType;
10
+ contentType?: string;
11
+ }): ResolveInlineDispositionResult;
12
+ //# sourceMappingURL=inline-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inline-types.d.ts","sourceRoot":"","sources":["../../src/helpers/inline-types.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,sBAAsB,EAC3B,KAAK,8BAA8B,EACpC,MAAM,gBAAgB,CAAC;AAExB;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,WAAW,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,EAC1C,KAAK,EAAE;IACL,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,sBAAsB,CAAC;IACpC,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,GACA,8BAA8B,CAQhC"}
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
- import { S3_API_ROUTES, isAPIError, APIError, S3_ERROR_CODES, confirmBodySchema, deleteQuerySchema, deleteBatchBodySchema, downloadQuerySchema, fileQuerySchema, multipartAbortBodySchema, multipartCompleteBodySchema, multipartInitBodySchema, multipartListPartsQuerySchema, multipartSignPartBodySchema, uploadBodySchema, resolveStoredFileName, S3_MAX_EXPIRES_IN, buildContentDisposition, S3_MAX_POST_OBJECT_BYTES, normalizeS3ApiBasePath, S3_API_BASE_PATH, matchesFileTypes, S3_DEFAULT_EXPIRES_IN, normalizeObjectKey, sanitizeFileName, ROUTE_NAME_PATTERN } from '@dimah-s3/core';
1
+ import { S3_API_ROUTES, isAPIError, APIError, S3_ERROR_CODES, confirmBodySchema, deleteQuerySchema, deleteBatchBodySchema, downloadQuerySchema, fileQuerySchema, multipartAbortBodySchema, multipartCompleteBodySchema, multipartInitBodySchema, multipartListPartsQuerySchema, multipartSignPartBodySchema, uploadBodySchema, resolveStoredFileName, buildContentDisposition, S3_MAX_EXPIRES_IN, S3_MAX_POST_OBJECT_BYTES, normalizeS3ApiBasePath, S3_API_BASE_PATH, matchesFileTypes, resolveInlineDisposition, fileNameFromKey, S3_DEFAULT_EXPIRES_IN, normalizeObjectKey, sanitizeFileName, ROUTE_NAME_PATTERN } from '@dimah-s3/core';
2
2
  export { APIError, S3_ERROR_CODES, isAPIError, isS3ErrorCode } from '@dimah-s3/core';
3
- import { PutObjectCommand, DeleteObjectCommand, GetObjectCommand, CreateMultipartUploadCommand, UploadPartCommand, ListPartsCommand, AbortMultipartUploadCommand, CompleteMultipartUploadCommand, HeadObjectCommand } from '@aws-sdk/client-s3';
3
+ import { PutObjectCommand, DeleteObjectCommand, GetObjectCommand, CreateMultipartUploadCommand, UploadPartCommand, HeadObjectCommand, ListPartsCommand, AbortMultipartUploadCommand, CompleteMultipartUploadCommand } from '@aws-sdk/client-s3';
4
4
  import { createMiddleware, createEndpoint, createRouter, toResponse } from 'better-call';
5
5
  import * as z from 'zod';
6
6
  import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
@@ -140,6 +140,15 @@ function normalizeExpiresIn(value, maxExpiresIn = S3_MAX_EXPIRES_IN) {
140
140
  const max = Number.isFinite(maxExpiresIn) && maxExpiresIn > 0 ? Math.floor(maxExpiresIn) : S3_MAX_EXPIRES_IN;
141
141
  return Math.min(expires, max);
142
142
  }
143
+ function clampDownloadExpiresIn(options) {
144
+ const max = options.maxExpiresIn;
145
+ if (options.resolvedExpiresIn != null) {
146
+ return normalizeExpiresIn(options.resolvedExpiresIn, max);
147
+ }
148
+ const cap = normalizeExpiresIn(options.routeExpiresIn, max);
149
+ if (options.requested == null) return cap;
150
+ return Math.min(normalizeExpiresIn(options.requested, max), cap);
151
+ }
143
152
 
144
153
  // src/helpers/logger.ts
145
154
  var defaultLogger = {
@@ -561,6 +570,15 @@ async function openStoredTarget(config, input, request, feature) {
561
570
  stored: storedObjectContext(request, route2, target.key)
562
571
  };
563
572
  }
573
+ async function objectExists(client, bucket, key) {
574
+ try {
575
+ await client.send(new HeadObjectCommand({ Bucket: bucket, Key: key }));
576
+ return true;
577
+ } catch (err) {
578
+ if (isAwsNotFound(err)) return false;
579
+ throw err;
580
+ }
581
+ }
564
582
  async function headObjectOrNotFound(client, bucket, key) {
565
583
  return sendOrObjectNotFound(
566
584
  () => client.send(new HeadObjectCommand({ Bucket: bucket, Key: key }))
@@ -614,6 +632,15 @@ function listedPartsByteSize(parts, excludePartNumber) {
614
632
  }
615
633
  return total;
616
634
  }
635
+ function applyInlineTypes(inlineTypes, input) {
636
+ if (!inlineTypes) return { disposition: input.disposition };
637
+ return resolveInlineDisposition({
638
+ contentType: input.contentType,
639
+ fileName: input.fileName ?? fileNameFromKey(input.key),
640
+ allow: inlineTypes,
641
+ requested: input.disposition
642
+ });
643
+ }
617
644
  async function finalizeConfirmedObject(client, bucket, key, input) {
618
645
  const { config, route: route2, stored, head, uploadId, acl } = input;
619
646
  const rawMetadata = head.Metadata ?? {};
@@ -817,7 +844,7 @@ var confirm = createS3Endpoint(
817
844
  return handleConfirm(ctx.context.config, ctx.body, ctx.context.request);
818
845
  }
819
846
  );
820
- async function handleDelete(config, input, request) {
847
+ async function deleteStoredObject(config, input, request) {
821
848
  const { route: route2, key, bucket, stored } = await openStoredTarget(
822
849
  config,
823
850
  input,
@@ -825,34 +852,30 @@ async function handleDelete(config, input, request) {
825
852
  "delete"
826
853
  );
827
854
  await runHook(route2.delete.guard, stored);
828
- await headObjectOrNotFound(route2.client, bucket, key);
829
- await route2.client.send(
830
- new DeleteObjectCommand({ Bucket: bucket, Key: key })
855
+ const existed = await objectExists(route2.client, bucket, key);
856
+ if (existed) {
857
+ await route2.client.send(
858
+ new DeleteObjectCommand({ Bucket: bucket, Key: key })
859
+ );
860
+ }
861
+ await runLifecycleHook(
862
+ route2.delete.onDeleted,
863
+ { ...stored, existed },
864
+ config
831
865
  );
832
- await runLifecycleHook(route2.delete.onDeleted, stored, config);
833
- return { success: true, bucket, key };
866
+ return { success: true, bucket, key, existed };
834
867
  }
835
868
  var deleteObject = createS3Endpoint(
836
869
  S3_API_ROUTES.delete,
837
870
  { method: "DELETE", query: deleteQuerySchema },
838
871
  async (ctx) => {
839
- return handleDelete(ctx.context.config, ctx.query, ctx.context.request);
872
+ return deleteStoredObject(
873
+ ctx.context.config,
874
+ ctx.query,
875
+ ctx.context.request
876
+ );
840
877
  }
841
878
  );
842
- async function deleteOne(config, routeName, key, request) {
843
- const { route: route2, bucket, stored } = await openStoredTarget(
844
- config,
845
- { route: routeName, key },
846
- request,
847
- "delete"
848
- );
849
- await runHook(route2.delete.guard, stored);
850
- await headObjectOrNotFound(route2.client, bucket, stored.key);
851
- await route2.client.send(
852
- new DeleteObjectCommand({ Bucket: bucket, Key: stored.key })
853
- );
854
- await runLifecycleHook(route2.delete.onDeleted, stored, config);
855
- }
856
879
  var deleteBatch = createS3Endpoint(
857
880
  S3_API_ROUTES.deleteBatch,
858
881
  { method: "POST", body: deleteBatchBodySchema },
@@ -862,8 +885,12 @@ var deleteBatch = createS3Endpoint(
862
885
  const results = [];
863
886
  for (const key of ctx.body.keys) {
864
887
  try {
865
- await deleteOne(config, ctx.body.route, key, request);
866
- results.push({ key, success: true });
888
+ const { existed } = await deleteStoredObject(
889
+ config,
890
+ { route: ctx.body.route, key },
891
+ request
892
+ );
893
+ results.push({ key, success: true, existed });
867
894
  } catch (err) {
868
895
  results.push({
869
896
  key,
@@ -896,33 +923,44 @@ async function handleDownload(config, input, request) {
896
923
  const resolved = await route2.download.resolve?.({
897
924
  ...stored,
898
925
  fileName: input.fileName,
899
- disposition: input.disposition ?? route2.download.disposition
926
+ disposition: input.disposition ?? route2.download.disposition,
927
+ expiresIn: input.expiresIn
900
928
  });
901
929
  const fileName = resolved?.fileName ?? input.fileName;
902
930
  const disposition = resolved?.disposition ?? input.disposition ?? route2.download.disposition ?? "attachment";
903
- const expiresIn = normalizeExpiresIn(
904
- resolved?.expiresIn ?? route2.download.expiresIn,
905
- config.maxExpiresIn
906
- );
931
+ const mode = route2.download.mode ?? "presign";
932
+ const expiresIn = mode === "proxy" ? 0 : clampDownloadExpiresIn({
933
+ requested: input.expiresIn,
934
+ routeExpiresIn: route2.download.expiresIn,
935
+ resolvedExpiresIn: resolved?.expiresIn,
936
+ maxExpiresIn: config.maxExpiresIn
937
+ });
907
938
  await runHook(route2.download.guard, {
908
939
  ...stored,
909
940
  fileName,
910
- disposition
941
+ disposition,
942
+ expiresIn
911
943
  });
912
- await headObjectOrNotFound(route2.client, bucket, key);
913
- const mode = route2.download.mode ?? "presign";
914
- const contentDisposition = fileName ? buildContentDisposition(fileName, disposition) : disposition;
944
+ const head = await headObjectOrNotFound(route2.client, bucket, key);
945
+ const signed = applyInlineTypes(route2.download.inlineTypes, {
946
+ key,
947
+ fileName,
948
+ disposition,
949
+ contentType: head.ContentType
950
+ });
951
+ const contentDisposition = fileName ? buildContentDisposition(fileName, signed.disposition) : signed.disposition;
915
952
  const url = mode === "proxy" ? fileUrl(request, config.basePath ?? "/api/s3", {
916
953
  route: input.route,
917
954
  key,
918
955
  fileName,
919
- disposition
956
+ disposition: signed.disposition
920
957
  }) : await getSignedUrl(
921
958
  route2.client,
922
959
  new GetObjectCommand({
923
960
  Bucket: bucket,
924
961
  Key: key,
925
- ResponseContentDisposition: contentDisposition
962
+ ResponseContentDisposition: contentDisposition,
963
+ ResponseContentType: signed.contentType
926
964
  }),
927
965
  { expiresIn }
928
966
  );
@@ -932,7 +970,7 @@ async function handleDownload(config, input, request) {
932
970
  ...stored,
933
971
  fileName,
934
972
  url,
935
- expiresIn: mode === "proxy" ? 0 : expiresIn
973
+ expiresIn
936
974
  },
937
975
  config
938
976
  );
@@ -940,9 +978,9 @@ async function handleDownload(config, input, request) {
940
978
  bucket,
941
979
  key,
942
980
  url,
943
- expiresIn: mode === "proxy" ? 0 : expiresIn,
981
+ expiresIn,
944
982
  mode,
945
- disposition
983
+ disposition: signed.disposition
946
984
  };
947
985
  }
948
986
  var download = createS3Endpoint(
@@ -963,11 +1001,13 @@ function catalogUpload(upload2) {
963
1001
  ...upload2.replace ? { replace: upload2.replace } : {}
964
1002
  };
965
1003
  }
966
- function catalogDownload(download2) {
1004
+ function catalogDownload(download2, maxExpiresIn) {
967
1005
  if (!isEnabled(download2)) return { enabled: false };
968
1006
  return {
969
1007
  enabled: true,
1008
+ expiresIn: normalizeExpiresIn(download2.expiresIn, maxExpiresIn),
970
1009
  ...download2.disposition ? { disposition: download2.disposition } : {},
1010
+ ...download2.inlineTypes ? { inlineTypes: [...download2.inlineTypes] } : {},
971
1011
  ...download2.mode ? { mode: download2.mode } : {}
972
1012
  };
973
1013
  }
@@ -976,7 +1016,7 @@ function buildRouteCatalog(config) {
976
1016
  for (const [name, route2] of Object.entries(config.routes)) {
977
1017
  routes[name] = {
978
1018
  upload: catalogUpload(route2.upload),
979
- download: catalogDownload(route2.download),
1019
+ download: catalogDownload(route2.download, config.maxExpiresIn),
980
1020
  delete: isEnabled(route2.delete) ? { enabled: true } : { enabled: false }
981
1021
  };
982
1022
  }
@@ -1008,13 +1048,20 @@ async function handleFile(config, input, request) {
1008
1048
  fileName,
1009
1049
  disposition
1010
1050
  });
1011
- await headObjectOrNotFound(route2.client, bucket, key);
1051
+ const head = await headObjectOrNotFound(route2.client, bucket, key);
1052
+ const signed = applyInlineTypes(route2.download.inlineTypes, {
1053
+ key,
1054
+ fileName,
1055
+ disposition,
1056
+ contentType: head.ContentType
1057
+ });
1058
+ const contentDisposition = fileName ? buildContentDisposition(fileName, signed.disposition) : signed.disposition;
1012
1059
  const result = await sendOrObjectNotFound(
1013
1060
  () => route2.client.send(
1014
1061
  new GetObjectCommand({
1015
1062
  Bucket: bucket,
1016
1063
  Key: key,
1017
- ResponseContentDisposition: fileName ? buildContentDisposition(fileName, disposition) : disposition
1064
+ ResponseContentDisposition: contentDisposition
1018
1065
  })
1019
1066
  )
1020
1067
  );
@@ -1022,11 +1069,12 @@ async function handleFile(config, input, request) {
1022
1069
  if (!body) throw errors.objectNotFound();
1023
1070
  const stream = "transformToWebStream" in body && typeof body.transformToWebStream === "function" ? body.transformToWebStream() : body;
1024
1071
  const headers = new Headers();
1025
- headers.set("Content-Type", result.ContentType ?? "application/octet-stream");
1026
1072
  headers.set(
1027
- "Content-Disposition",
1028
- fileName ? buildContentDisposition(fileName, disposition) : disposition
1073
+ "Content-Type",
1074
+ signed.contentType ?? result.ContentType ?? "application/octet-stream"
1029
1075
  );
1076
+ headers.set("Content-Disposition", contentDisposition);
1077
+ headers.set("X-Content-Type-Options", "nosniff");
1030
1078
  if (typeof result.ContentLength === "number") {
1031
1079
  headers.set("Content-Length", String(result.ContentLength));
1032
1080
  }