@dimah-s3/server 1.4.0 → 1.4.2

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/plugins.js CHANGED
@@ -512,33 +512,29 @@ function listedPartsByteSize(parts, excludePartNumber) {
512
512
  }
513
513
  async function finalizeConfirmedObject(client, bucket, key, input) {
514
514
  const { config, route, stored, head, uploadId, acl } = input;
515
- const contentLength = requireContentLength(head);
516
- const fileName = resolveStoredFileName(head.ContentDisposition, key);
517
515
  const rawMetadata = head.Metadata ?? {};
516
+ const fileName = resolveStoredFileName(head.ContentDisposition, key);
517
+ let context;
518
518
  try {
519
+ const contentLength = requireContentLength(head);
519
520
  assertVerifiedConstraints(route.upload, {
520
521
  fileName,
521
522
  contentType: head.ContentType,
522
523
  contentLength
523
524
  });
524
- } catch (err) {
525
- await deleteObjectBestEffort(client, bucket, key);
526
- throw err;
527
- }
528
- const metadata = stripPreviousKeyMeta(rawMetadata);
529
- const context = {
530
- ...stored,
531
- contentType: head.ContentType,
532
- contentLength,
533
- eTag: head.ETag?.replace(/"/g, ""),
534
- metadata,
535
- acl,
536
- fileName,
537
- versionId: head.VersionId,
538
- lastModified: head.LastModified?.toISOString(),
539
- uploadId
540
- };
541
- try {
525
+ const metadata = stripPreviousKeyMeta(rawMetadata);
526
+ context = {
527
+ ...stored,
528
+ contentType: head.ContentType,
529
+ contentLength,
530
+ eTag: head.ETag?.replace(/"/g, ""),
531
+ metadata,
532
+ acl,
533
+ fileName,
534
+ versionId: head.VersionId,
535
+ lastModified: head.LastModified?.toISOString(),
536
+ uploadId
537
+ };
542
538
  await runLifecycleHook(route.upload.onConfirmed, context, config);
543
539
  } catch (err) {
544
540
  await deleteObjectBestEffort(client, bucket, key);
@@ -1024,23 +1020,39 @@ async function handleMultipartInit(config, input, request) {
1024
1020
  if (!UploadId) {
1025
1021
  throw errors.internalError();
1026
1022
  }
1027
- await runLifecycleHook(
1028
- route.upload.multipart.onInit,
1029
- {
1030
- ...stored,
1031
- uploadId: UploadId,
1032
- file: {
1033
- name: fileName,
1034
- size: fileSize,
1035
- type: input.contentType
1023
+ try {
1024
+ await runLifecycleHook(
1025
+ route.upload.multipart.onInit,
1026
+ {
1027
+ ...stored,
1028
+ uploadId: UploadId,
1029
+ file: {
1030
+ name: fileName,
1031
+ size: fileSize,
1032
+ type: input.contentType
1033
+ },
1034
+ metadata,
1035
+ clientMetadata: input.metadata,
1036
+ acl,
1037
+ replace: route.upload.replace
1036
1038
  },
1037
- metadata,
1038
- clientMetadata: input.metadata,
1039
- acl,
1040
- replace: route.upload.replace
1041
- },
1042
- config
1043
- );
1039
+ config
1040
+ );
1041
+ } catch (err) {
1042
+ await abortMultipartBestEffort(route.client, bucket, key, UploadId);
1043
+ try {
1044
+ await runLifecycleHook(
1045
+ route.upload.multipart.onAbort,
1046
+ {
1047
+ ...stored,
1048
+ uploadId: UploadId
1049
+ },
1050
+ config
1051
+ );
1052
+ } catch {
1053
+ }
1054
+ throw err;
1055
+ }
1044
1056
  return { bucket, key, uploadId: UploadId };
1045
1057
  }
1046
1058
  var multipartInit = createS3Endpoint(