@payloadcms/storage-s3 4.0.0-internal.d28e9fb → 4.0.0-internal.d3909a9

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.
Files changed (45) hide show
  1. package/LICENSE.md +1 -1
  2. package/README.md +2 -2
  3. package/dist/adapter.d.ts +3 -3
  4. package/dist/adapter.d.ts.map +1 -1
  5. package/dist/adapter.js +46 -18
  6. package/dist/adapter.js.map +1 -1
  7. package/dist/copyFile.d.ts +13 -0
  8. package/dist/copyFile.d.ts.map +1 -0
  9. package/dist/copyFile.js +145 -0
  10. package/dist/copyFile.js.map +1 -0
  11. package/dist/deleteFile.d.ts +2 -5
  12. package/dist/deleteFile.d.ts.map +1 -1
  13. package/dist/deleteFile.js +2 -9
  14. package/dist/deleteFile.js.map +1 -1
  15. package/dist/generateURL.js +4 -4
  16. package/dist/generateURL.js.map +1 -1
  17. package/dist/generateUploadInstructions.d.ts +13 -0
  18. package/dist/generateUploadInstructions.d.ts.map +1 -0
  19. package/dist/generateUploadInstructions.js +70 -0
  20. package/dist/generateUploadInstructions.js.map +1 -0
  21. package/dist/getFile.d.ts +5 -4
  22. package/dist/getFile.d.ts.map +1 -1
  23. package/dist/getFile.js +22 -22
  24. package/dist/getFile.js.map +1 -1
  25. package/dist/index.d.ts +14 -23
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +64 -82
  28. package/dist/index.js.map +1 -1
  29. package/dist/uploadFile.d.ts +2 -5
  30. package/dist/uploadFile.d.ts.map +1 -1
  31. package/dist/uploadFile.js +3 -10
  32. package/dist/uploadFile.js.map +1 -1
  33. package/package.json +20 -22
  34. package/dist/client/S3ClientUploadHandler.d.ts +0 -9
  35. package/dist/client/S3ClientUploadHandler.d.ts.map +0 -1
  36. package/dist/client/S3ClientUploadHandler.js +0 -47
  37. package/dist/client/S3ClientUploadHandler.js.map +0 -1
  38. package/dist/exports/client.d.ts +0 -2
  39. package/dist/exports/client.d.ts.map +0 -1
  40. package/dist/exports/client.js +0 -3
  41. package/dist/exports/client.js.map +0 -1
  42. package/dist/generateSignedURL.d.ts +0 -15
  43. package/dist/generateSignedURL.d.ts.map +0 -1
  44. package/dist/generateSignedURL.js +0 -64
  45. package/dist/generateSignedURL.js.map +0 -1
package/dist/getFile.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { GetObjectCommand } from '@aws-sdk/client-s3';
2
2
  import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
3
- import { getFilePrefix as getDocPrefix, getFileKey } from '@payloadcms/plugin-cloud-storage/utilities';
4
- import { getRangeRequestInfo } from 'payload/internal';
3
+ import { buildStoragePathData, getFilePrefix as getDocPrefix } from '@payloadcms/plugin-cloud-storage/utilities';
4
+ import { getRangeRequestInfo, isXmlMimeType, uploadContentSecurityPolicy } from 'payload/internal';
5
5
  const isNodeReadableStream = (body)=>{
6
6
  return typeof body === 'object' && body !== null && 'pipe' in body && typeof body.pipe === 'function' && 'destroy' in body && typeof body.destroy === 'function';
7
7
  };
@@ -14,7 +14,8 @@ const abortRequestAndDestroyStream = ({ abortController, object })=>{
14
14
  object.Body.destroy();
15
15
  }
16
16
  };
17
- export async function getFile({ bucket, client, clientUploadContext, collection, collectionPrefix = '', filename, incomingHeaders, prefixQueryParam, req, signedDownloads, useCompositePrefixes = false }) {
17
+ export async function getFile({ bucket, client, collection, collectionPrefix = '', doc, filename, incomingHeaders, operation = 'read', req, signedDownloads, uploadReference, useCompositePrefixes = false }) {
18
+ const isTransformSource = operation === 'transform';
18
19
  let object = undefined;
19
20
  let streamed = false;
20
21
  const abortController = new AbortController();
@@ -28,19 +29,21 @@ export async function getFile({ bucket, client, clientUploadContext, collection,
28
29
  }
29
30
  try {
30
31
  const docPrefix = await getDocPrefix({
31
- clientUploadContext,
32
32
  collection,
33
+ collectionPrefix,
34
+ doc,
33
35
  filename,
34
- prefixQueryParam,
35
- req
36
+ req,
37
+ uploadReference,
38
+ useCompositePrefixes
36
39
  });
37
- const { fileKey: key } = getFileKey({
40
+ const { storageFilePath } = buildStoragePathData({
38
41
  collectionPrefix,
39
42
  docPrefix,
40
43
  filename,
41
44
  useCompositePrefixes
42
45
  });
43
- if (signedDownloads && !clientUploadContext) {
46
+ if (signedDownloads && !uploadReference && !isTransformSource) {
44
47
  let useSignedURL = true;
45
48
  if (typeof signedDownloads === 'object' && typeof signedDownloads.shouldUseSignedURL === 'function') {
46
49
  useSignedURL = await signedDownloads.shouldUseSignedURL({
@@ -52,7 +55,7 @@ export async function getFile({ bucket, client, clientUploadContext, collection,
52
55
  if (useSignedURL) {
53
56
  const command = new GetObjectCommand({
54
57
  Bucket: bucket,
55
- Key: key
58
+ Key: storageFilePath
56
59
  });
57
60
  const signedUrl = await getSignedUrl(client, command, typeof signedDownloads === 'object' ? signedDownloads : {
58
61
  expiresIn: 7200
@@ -60,10 +63,9 @@ export async function getFile({ bucket, client, clientUploadContext, collection,
60
63
  return Response.redirect(signedUrl, 302);
61
64
  }
62
65
  }
63
- // Get file size first for range validation and to set Content-Length header before streaming
64
66
  const headObject = await client.headObject({
65
67
  Bucket: bucket,
66
- Key: key
68
+ Key: storageFilePath
67
69
  });
68
70
  const fileSize = headObject.ContentLength;
69
71
  if (!fileSize) {
@@ -71,8 +73,7 @@ export async function getFile({ bucket, client, clientUploadContext, collection,
71
73
  status: 500
72
74
  });
73
75
  }
74
- // Handle range request
75
- const rangeHeader = req.headers.get('range');
76
+ const rangeHeader = isTransformSource ? null : req.headers.get('range');
76
77
  const rangeResult = getRangeRequestInfo({
77
78
  fileSize,
78
79
  rangeHeader
@@ -85,7 +86,6 @@ export async function getFile({ bucket, client, clientUploadContext, collection,
85
86
  }
86
87
  const rangeForS3 = rangeResult.type === 'partial' ? `bytes=${rangeResult.rangeStart}-${rangeResult.rangeEnd}` : undefined;
87
88
  let headers = new Headers(incomingHeaders);
88
- // Add range-related headers from the result
89
89
  for (const [headerKey, value] of Object.entries(rangeResult.headers)){
90
90
  headers.append(headerKey, value);
91
91
  }
@@ -93,18 +93,18 @@ export async function getFile({ bucket, client, clientUploadContext, collection,
93
93
  if (headObject.ETag) {
94
94
  headers.append('ETag', headObject.ETag);
95
95
  }
96
- // Add Content-Security-Policy header for SVG files to prevent executable code
97
- if (headObject.ContentType === 'image/svg+xml') {
98
- headers.append('Content-Security-Policy', "script-src 'none'");
96
+ // Apply a restrictive policy to XML-family responses served through Payload.
97
+ if (isXmlMimeType(headObject.ContentType)) {
98
+ headers.append('Content-Security-Policy', uploadContentSecurityPolicy);
99
99
  }
100
100
  const etagFromHeaders = req.headers.get('etag') || req.headers.get('if-none-match');
101
101
  const objectEtag = headObject.ETag;
102
- if (collection.upload && typeof collection.upload === 'object' && typeof collection.upload.modifyResponseHeaders === 'function') {
102
+ if (!isTransformSource && collection.upload && typeof collection.upload === 'object' && typeof collection.upload.modifyResponseHeaders === 'function') {
103
103
  headers = collection.upload.modifyResponseHeaders({
104
104
  headers
105
105
  }) || headers;
106
106
  }
107
- if (etagFromHeaders && etagFromHeaders === objectEtag) {
107
+ if (!isTransformSource && etagFromHeaders && etagFromHeaders === objectEtag) {
108
108
  return new Response(null, {
109
109
  headers,
110
110
  status: 304
@@ -112,7 +112,7 @@ export async function getFile({ bucket, client, clientUploadContext, collection,
112
112
  }
113
113
  object = await client.getObject({
114
114
  Bucket: bucket,
115
- Key: key,
115
+ Key: storageFilePath,
116
116
  Range: rangeForS3
117
117
  }, {
118
118
  abortSignal: abortController.signal
@@ -125,7 +125,7 @@ export async function getFile({ bucket, client, clientUploadContext, collection,
125
125
  }
126
126
  if (!isNodeReadableStream(object.Body)) {
127
127
  req.payload.logger.error({
128
- key,
128
+ key: storageFilePath,
129
129
  msg: 'S3 object body is not a readable stream'
130
130
  });
131
131
  return new Response('Internal Server Error', {
@@ -136,7 +136,7 @@ export async function getFile({ bucket, client, clientUploadContext, collection,
136
136
  stream.on('error', (err)=>{
137
137
  req.payload.logger.error({
138
138
  err,
139
- key,
139
+ key: storageFilePath,
140
140
  msg: 'Error while streaming S3 object (aborting)'
141
141
  });
142
142
  abortRequestAndDestroyStream({
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/getFile.ts"],"sourcesContent":["import type * as AWS from '@aws-sdk/client-s3'\nimport type { CollectionConfig, PayloadRequest } from 'payload'\nimport type { Readable } from 'stream'\n\nimport { GetObjectCommand } from '@aws-sdk/client-s3'\nimport { getSignedUrl } from '@aws-sdk/s3-request-presigner'\nimport {\n getFilePrefix as getDocPrefix,\n getFileKey,\n} from '@payloadcms/plugin-cloud-storage/utilities'\nimport { getRangeRequestInfo } from 'payload/internal'\n\nexport type SignedDownloadsConfig =\n | {\n /** @default 7200 */\n expiresIn?: number\n shouldUseSignedURL?(args: {\n collection: CollectionConfig\n filename: string\n req: PayloadRequest\n }): boolean | Promise<boolean>\n }\n | boolean\n\ninterface GetFileArgs {\n bucket: string\n client: AWS.S3\n clientUploadContext?: unknown\n collection: CollectionConfig\n collectionPrefix?: string\n filename: string\n incomingHeaders?: Headers\n prefixQueryParam?: string\n req: PayloadRequest\n signedDownloads: SignedDownloadsConfig\n useCompositePrefixes?: boolean\n}\n\nconst isNodeReadableStream = (body: AWS.GetObjectOutput['Body']): body is Readable => {\n return (\n typeof body === 'object' &&\n body !== null &&\n 'pipe' in body &&\n typeof body.pipe === 'function' &&\n 'destroy' in body &&\n typeof body.destroy === 'function'\n )\n}\n\nconst abortRequestAndDestroyStream = ({\n abortController,\n object,\n}: {\n abortController: AbortController\n object?: AWS.GetObjectOutput\n}) => {\n try {\n abortController.abort()\n } catch {\n /* noop */\n }\n if (object?.Body && isNodeReadableStream(object.Body)) {\n object.Body.destroy()\n }\n}\n\nexport async function getFile({\n bucket,\n client,\n clientUploadContext,\n collection,\n collectionPrefix = '',\n filename,\n incomingHeaders,\n prefixQueryParam,\n req,\n signedDownloads,\n useCompositePrefixes = false,\n}: GetFileArgs): Promise<Response> {\n let object: AWS.GetObjectOutput | undefined = undefined\n let streamed = false\n\n const abortController = new AbortController()\n if (req.signal) {\n req.signal.addEventListener('abort', () => {\n abortRequestAndDestroyStream({ abortController, object })\n })\n }\n\n try {\n const docPrefix = await getDocPrefix({\n clientUploadContext,\n collection,\n filename,\n prefixQueryParam,\n req,\n })\n\n const { fileKey: key } = getFileKey({\n collectionPrefix,\n docPrefix,\n filename,\n useCompositePrefixes,\n })\n\n if (signedDownloads && !clientUploadContext) {\n let useSignedURL = true\n if (\n typeof signedDownloads === 'object' &&\n typeof signedDownloads.shouldUseSignedURL === 'function'\n ) {\n useSignedURL = await signedDownloads.shouldUseSignedURL({ collection, filename, req })\n }\n\n if (useSignedURL) {\n const command = new GetObjectCommand({ Bucket: bucket, Key: key })\n const signedUrl = await getSignedUrl(\n client,\n command,\n typeof signedDownloads === 'object' ? signedDownloads : { expiresIn: 7200 },\n )\n return Response.redirect(signedUrl, 302)\n }\n }\n\n // Get file size first for range validation and to set Content-Length header before streaming\n const headObject = await client.headObject({\n Bucket: bucket,\n Key: key,\n })\n const fileSize = headObject.ContentLength\n\n if (!fileSize) {\n return new Response('Internal Server Error', { status: 500 })\n }\n\n // Handle range request\n const rangeHeader = req.headers.get('range')\n const rangeResult = getRangeRequestInfo({ fileSize, rangeHeader })\n\n if (rangeResult.type === 'invalid') {\n return new Response(null, {\n headers: new Headers(rangeResult.headers),\n status: rangeResult.status,\n })\n }\n\n const rangeForS3 =\n rangeResult.type === 'partial'\n ? `bytes=${rangeResult.rangeStart}-${rangeResult.rangeEnd}`\n : undefined\n\n let headers = new Headers(incomingHeaders)\n\n // Add range-related headers from the result\n for (const [headerKey, value] of Object.entries(rangeResult.headers)) {\n headers.append(headerKey, value)\n }\n\n headers.append('Content-Type', String(headObject.ContentType))\n if (headObject.ETag) {\n headers.append('ETag', headObject.ETag)\n }\n\n // Add Content-Security-Policy header for SVG files to prevent executable code\n if (headObject.ContentType === 'image/svg+xml') {\n headers.append('Content-Security-Policy', \"script-src 'none'\")\n }\n\n const etagFromHeaders = req.headers.get('etag') || req.headers.get('if-none-match')\n const objectEtag = headObject.ETag\n\n if (\n collection.upload &&\n typeof collection.upload === 'object' &&\n typeof collection.upload.modifyResponseHeaders === 'function'\n ) {\n headers = collection.upload.modifyResponseHeaders({ headers }) || headers\n }\n\n if (etagFromHeaders && etagFromHeaders === objectEtag) {\n return new Response(null, {\n headers,\n status: 304,\n })\n }\n\n object = await client.getObject(\n {\n Bucket: bucket,\n Key: key,\n Range: rangeForS3,\n },\n { abortSignal: abortController.signal },\n )\n\n if (!object.Body) {\n return new Response(null, { status: 404, statusText: 'Not Found' })\n }\n\n if (!isNodeReadableStream(object.Body)) {\n req.payload.logger.error({\n key,\n msg: 'S3 object body is not a readable stream',\n })\n return new Response('Internal Server Error', { status: 500 })\n }\n\n const stream = object.Body\n stream.on('error', (err: Error) => {\n req.payload.logger.error({\n err,\n key,\n msg: 'Error while streaming S3 object (aborting)',\n })\n abortRequestAndDestroyStream({ abortController, object })\n })\n\n streamed = true\n return new Response(stream, { headers, status: rangeResult.status })\n } catch (err) {\n if (\n err &&\n typeof err === 'object' &&\n (('name' in err && (err.name === 'NoSuchKey' || err.name === 'NotFound')) ||\n ('httpStatusCode' in err && err.httpStatusCode === 404))\n ) {\n return new Response(null, { status: 404, statusText: 'Not Found' })\n }\n req.payload.logger.error(err)\n return new Response('Internal Server Error', { status: 500 })\n } finally {\n if (!streamed) {\n abortRequestAndDestroyStream({ abortController, object })\n }\n }\n}\n"],"names":["GetObjectCommand","getSignedUrl","getFilePrefix","getDocPrefix","getFileKey","getRangeRequestInfo","isNodeReadableStream","body","pipe","destroy","abortRequestAndDestroyStream","abortController","object","abort","Body","getFile","bucket","client","clientUploadContext","collection","collectionPrefix","filename","incomingHeaders","prefixQueryParam","req","signedDownloads","useCompositePrefixes","undefined","streamed","AbortController","signal","addEventListener","docPrefix","fileKey","key","useSignedURL","shouldUseSignedURL","command","Bucket","Key","signedUrl","expiresIn","Response","redirect","headObject","fileSize","ContentLength","status","rangeHeader","headers","get","rangeResult","type","Headers","rangeForS3","rangeStart","rangeEnd","headerKey","value","Object","entries","append","String","ContentType","ETag","etagFromHeaders","objectEtag","upload","modifyResponseHeaders","getObject","Range","abortSignal","statusText","payload","logger","error","msg","stream","on","err","name","httpStatusCode"],"mappings":"AAIA,SAASA,gBAAgB,QAAQ,qBAAoB;AACrD,SAASC,YAAY,QAAQ,gCAA+B;AAC5D,SACEC,iBAAiBC,YAAY,EAC7BC,UAAU,QACL,6CAA4C;AACnD,SAASC,mBAAmB,QAAQ,mBAAkB;AA4BtD,MAAMC,uBAAuB,CAACC;IAC5B,OACE,OAAOA,SAAS,YAChBA,SAAS,QACT,UAAUA,QACV,OAAOA,KAAKC,IAAI,KAAK,cACrB,aAAaD,QACb,OAAOA,KAAKE,OAAO,KAAK;AAE5B;AAEA,MAAMC,+BAA+B,CAAC,EACpCC,eAAe,EACfC,MAAM,EAIP;IACC,IAAI;QACFD,gBAAgBE,KAAK;IACvB,EAAE,OAAM;IACN,QAAQ,GACV;IACA,IAAID,QAAQE,QAAQR,qBAAqBM,OAAOE,IAAI,GAAG;QACrDF,OAAOE,IAAI,CAACL,OAAO;IACrB;AACF;AAEA,OAAO,eAAeM,QAAQ,EAC5BC,MAAM,EACNC,MAAM,EACNC,mBAAmB,EACnBC,UAAU,EACVC,mBAAmB,EAAE,EACrBC,QAAQ,EACRC,eAAe,EACfC,gBAAgB,EAChBC,GAAG,EACHC,eAAe,EACfC,uBAAuB,KAAK,EAChB;IACZ,IAAId,SAA0Ce;IAC9C,IAAIC,WAAW;IAEf,MAAMjB,kBAAkB,IAAIkB;IAC5B,IAAIL,IAAIM,MAAM,EAAE;QACdN,IAAIM,MAAM,CAACC,gBAAgB,CAAC,SAAS;YACnCrB,6BAA6B;gBAAEC;gBAAiBC;YAAO;QACzD;IACF;IAEA,IAAI;QACF,MAAMoB,YAAY,MAAM7B,aAAa;YACnCe;YACAC;YACAE;YACAE;YACAC;QACF;QAEA,MAAM,EAAES,SAASC,GAAG,EAAE,GAAG9B,WAAW;YAClCgB;YACAY;YACAX;YACAK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AAC,SAAS,CAACC;YAClBvD,IAAIiD,OAAO,CAACC,MAAM,CAACC,KAAK,CAAC;gBACvBI;gBACA7C;gBACA0C,KAAK;YACP;YACAlE,6BAA6B;gBAAEC;gBAAiBC;YAAO;QACzD;QAEAgB,WAAW;QACX,OAAO,IAAIc,SAASmC,QAAQ;YAAE5B;YAASF,QAAQI,YAAYJ,MAAM;QAAC;IACpE,EAAE,OAAOgC,KAAK;QACZ,IACEA,OACA,OAAOA,QAAQ,YACd,CAAA,AAAC,UAAUA,OAAQA,CAAAA,IAAIC,IAAI,KAAK,eAAeD,IAAIC,IAAI,KAAK,UAAS,KACnE,oBAAoBD,OAAOA,IAAIE,cAAc,KAAK,GAAG,GACxD;YACA,OAAO,IAAIvC,SAAS,MAAM;gBAAEK,QAAQ;gBAAKyB,YAAY;YAAY;QACnE;QACAhD,IAAIiD,OAAO,CAACC,MAAM,CAACC,KAAK,CAACI;QACzB,OAAO,IAAIrC,SAAS,yBAAyB;YAAEK,QAAQ;QAAI;IAC7D,SAAU;QACR,IAAI,CAACnB,UAAU;YACblB,6BAA6B;gBAAEC;gBAAiBC;YAAO;QACzD;IACF;AACF"}
1
+ {"version":3,"sources":["../src/getFile.ts"],"sourcesContent":["import type * as AWS from '@aws-sdk/client-s3'\nimport type { CollectionConfig, FileHandlerOperation, PayloadRequest, TypeWithID } from 'payload'\nimport type { Readable } from 'stream'\n\nimport { GetObjectCommand } from '@aws-sdk/client-s3'\nimport { getSignedUrl } from '@aws-sdk/s3-request-presigner'\nimport {\n buildStoragePathData,\n getFilePrefix as getDocPrefix,\n} from '@payloadcms/plugin-cloud-storage/utilities'\nimport { getRangeRequestInfo, isXmlMimeType, uploadContentSecurityPolicy } from 'payload/internal'\n\nexport type SignedDownloadsConfig =\n | {\n /** @default 7200 */\n expiresIn?: number\n shouldUseSignedURL?(args: {\n collection: CollectionConfig\n filename: string\n req: PayloadRequest\n }): boolean | Promise<boolean>\n }\n | boolean\n\ninterface GetFileArgs {\n bucket: string\n client: AWS.S3\n collection: CollectionConfig\n collectionPrefix?: string\n doc?: TypeWithID\n filename: string\n incomingHeaders?: Headers\n operation?: FileHandlerOperation\n req: PayloadRequest\n signedDownloads: SignedDownloadsConfig\n uploadReference?: unknown\n useCompositePrefixes?: boolean\n}\n\nconst isNodeReadableStream = (body: AWS.GetObjectOutput['Body']): body is Readable => {\n return (\n typeof body === 'object' &&\n body !== null &&\n 'pipe' in body &&\n typeof body.pipe === 'function' &&\n 'destroy' in body &&\n typeof body.destroy === 'function'\n )\n}\n\nconst abortRequestAndDestroyStream = ({\n abortController,\n object,\n}: {\n abortController: AbortController\n object?: AWS.GetObjectOutput\n}) => {\n try {\n abortController.abort()\n } catch {\n /* noop */\n }\n if (object?.Body && isNodeReadableStream(object.Body)) {\n object.Body.destroy()\n }\n}\n\nexport async function getFile({\n bucket,\n client,\n collection,\n collectionPrefix = '',\n doc,\n filename,\n incomingHeaders,\n operation = 'read',\n req,\n signedDownloads,\n uploadReference,\n useCompositePrefixes = false,\n}: GetFileArgs): Promise<Response> {\n const isTransformSource = operation === 'transform'\n let object: AWS.GetObjectOutput | undefined = undefined\n let streamed = false\n\n const abortController = new AbortController()\n if (req.signal) {\n req.signal.addEventListener('abort', () => {\n abortRequestAndDestroyStream({ abortController, object })\n })\n }\n\n try {\n const docPrefix = await getDocPrefix({\n collection,\n collectionPrefix,\n doc,\n filename,\n req,\n uploadReference,\n useCompositePrefixes,\n })\n\n const { storageFilePath } = buildStoragePathData({\n collectionPrefix,\n docPrefix,\n filename,\n useCompositePrefixes,\n })\n\n if (signedDownloads && !uploadReference && !isTransformSource) {\n let useSignedURL = true\n if (\n typeof signedDownloads === 'object' &&\n typeof signedDownloads.shouldUseSignedURL === 'function'\n ) {\n useSignedURL = await signedDownloads.shouldUseSignedURL({ collection, filename, req })\n }\n\n if (useSignedURL) {\n const command = new GetObjectCommand({ Bucket: bucket, Key: storageFilePath })\n const signedUrl = await getSignedUrl(\n client,\n command,\n typeof signedDownloads === 'object' ? signedDownloads : { expiresIn: 7200 },\n )\n return Response.redirect(signedUrl, 302)\n }\n }\n\n const headObject = await client.headObject({\n Bucket: bucket,\n Key: storageFilePath,\n })\n const fileSize = headObject.ContentLength\n\n if (!fileSize) {\n return new Response('Internal Server Error', { status: 500 })\n }\n\n const rangeHeader = isTransformSource ? null : req.headers.get('range')\n const rangeResult = getRangeRequestInfo({ fileSize, rangeHeader })\n\n if (rangeResult.type === 'invalid') {\n return new Response(null, {\n headers: new Headers(rangeResult.headers),\n status: rangeResult.status,\n })\n }\n\n const rangeForS3 =\n rangeResult.type === 'partial'\n ? `bytes=${rangeResult.rangeStart}-${rangeResult.rangeEnd}`\n : undefined\n\n let headers = new Headers(incomingHeaders)\n\n for (const [headerKey, value] of Object.entries(rangeResult.headers)) {\n headers.append(headerKey, value)\n }\n\n headers.append('Content-Type', String(headObject.ContentType))\n if (headObject.ETag) {\n headers.append('ETag', headObject.ETag)\n }\n\n // Apply a restrictive policy to XML-family responses served through Payload.\n if (isXmlMimeType(headObject.ContentType)) {\n headers.append('Content-Security-Policy', uploadContentSecurityPolicy)\n }\n\n const etagFromHeaders = req.headers.get('etag') || req.headers.get('if-none-match')\n const objectEtag = headObject.ETag\n\n if (\n !isTransformSource &&\n collection.upload &&\n typeof collection.upload === 'object' &&\n typeof collection.upload.modifyResponseHeaders === 'function'\n ) {\n headers = collection.upload.modifyResponseHeaders({ headers }) || headers\n }\n\n if (!isTransformSource && etagFromHeaders && etagFromHeaders === objectEtag) {\n return new Response(null, {\n headers,\n status: 304,\n })\n }\n\n object = await client.getObject(\n {\n Bucket: bucket,\n Key: storageFilePath,\n Range: rangeForS3,\n },\n { abortSignal: abortController.signal },\n )\n\n if (!object.Body) {\n return new Response(null, { status: 404, statusText: 'Not Found' })\n }\n\n if (!isNodeReadableStream(object.Body)) {\n req.payload.logger.error({\n key: storageFilePath,\n msg: 'S3 object body is not a readable stream',\n })\n return new Response('Internal Server Error', { status: 500 })\n }\n\n const stream = object.Body\n stream.on('error', (err: Error) => {\n req.payload.logger.error({\n err,\n key: storageFilePath,\n msg: 'Error while streaming S3 object (aborting)',\n })\n abortRequestAndDestroyStream({ abortController, object })\n })\n\n streamed = true\n return new Response(stream, { headers, status: rangeResult.status })\n } catch (err) {\n if (\n err &&\n typeof err === 'object' &&\n (('name' in err && (err.name === 'NoSuchKey' || err.name === 'NotFound')) ||\n ('httpStatusCode' in err && err.httpStatusCode === 404))\n ) {\n return new Response(null, { status: 404, statusText: 'Not Found' })\n }\n req.payload.logger.error(err)\n return new Response('Internal Server Error', { status: 500 })\n } finally {\n if (!streamed) {\n abortRequestAndDestroyStream({ abortController, object })\n }\n }\n}\n"],"names":["GetObjectCommand","getSignedUrl","buildStoragePathData","getFilePrefix","getDocPrefix","getRangeRequestInfo","isXmlMimeType","uploadContentSecurityPolicy","isNodeReadableStream","body","pipe","destroy","abortRequestAndDestroyStream","abortController","object","abort","Body","getFile","bucket","client","collection","collectionPrefix","doc","filename","incomingHeaders","operation","req","signedDownloads","uploadReference","useCompositePrefixes","isTransformSource","undefined","streamed","AbortController","signal","addEventListener","docPrefix","storageFilePath","useSignedURL","shouldUseSignedURL","command","Bucket","Key","signedUrl","expiresIn","Response","redirect","headObject","fileSize","ContentLength","status","rangeHeader","headers","get","rangeResult","type","Headers","rangeForS3","rangeStart","rangeEnd","headerKey","value","Object","entries","append","String","ContentType","ETag","etagFromHeaders","objectEtag","upload","modifyResponseHeaders","getObject","Range","abortSignal","statusText","payload","logger","error","key","msg","stream","on","err","name","httpStatusCode"],"mappings":"AAIA,SAASA,gBAAgB,QAAQ,qBAAoB;AACrD,SAASC,YAAY,QAAQ,gCAA+B;AAC5D,SACEC,oBAAoB,EACpBC,iBAAiBC,YAAY,QACxB,6CAA4C;AACnD,SAASC,mBAAmB,EAAEC,aAAa,EAAEC,2BAA2B,QAAQ,mBAAkB;AA6BlG,MAAMC,uBAAuB,CAACC;IAC5B,OACE,OAAOA,SAAS,YAChBA,SAAS,QACT,UAAUA,QAC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OAAOA,QAAQ,YACd,CAAA,AAAC,UAAUA,OAAQA,CAAAA,IAAIC,IAAI,KAAK,eAAeD,IAAIC,IAAI,KAAK,UAAS,KACnE,oBAAoBD,OAAOA,IAAIE,cAAc,KAAK,GAAG,GACxD;YACA,OAAO,IAAIxC,SAAS,MAAM;gBAAEK,QAAQ;gBAAKyB,YAAY;YAAY;QACnE;QACAjD,IAAIkD,OAAO,CAACC,MAAM,CAACC,KAAK,CAACK;QACzB,OAAO,IAAItC,SAAS,yBAAyB;YAAEK,QAAQ;QAAI;IAC7D,SAAU;QACR,IAAI,CAAClB,UAAU;YACbpB,6BAA6B;gBAAEC;gBAAiBC;YAAO;QACzD;IACF;AACF"}
package/dist/index.d.ts CHANGED
@@ -1,22 +1,12 @@
1
+ import type { S3ClientConfig } from '@aws-sdk/client-s3';
1
2
  import type { ClientUploadsConfig, CollectionOptions } from '@payloadcms/plugin-cloud-storage/types';
2
- import type { Plugin, UploadCollectionSlug } from 'payload';
3
- import * as AWS from '@aws-sdk/client-s3';
3
+ import type { StorageAdapter, UploadCollectionSlug } from 'payload';
4
4
  import type { SignedDownloadsConfig } from './getFile.js';
5
5
  export type S3StorageOptions = {
6
6
  /**
7
7
  * Access control list for uploaded files.
8
8
  */
9
9
  acl?: 'private' | 'public-read';
10
- /**
11
- * When enabled, fields (like the prefix field) will always be inserted into
12
- * the collection schema regardless of whether the plugin is enabled. This
13
- * ensures a consistent schema across all environments.
14
- *
15
- * This will be enabled by default in Payload v4.
16
- *
17
- * @default false
18
- */
19
- alwaysInsertFields?: boolean;
20
10
  /**
21
11
  * Bucket name to upload files to.
22
12
  *
@@ -31,7 +21,7 @@ export type S3StorageOptions = {
31
21
  */
32
22
  clientCacheKey?: string;
33
23
  /**
34
- * Do uploads directly on the client to bypass limits on Vercel. You must allow CORS PUT method for the bucket to your website.
24
+ * Upload directly to S3 instead of through Payload. You must allow CORS PUT requests from your website.
35
25
  */
36
26
  clientUploads?: ClientUploadsConfig;
37
27
  /**
@@ -45,7 +35,7 @@ export type S3StorageOptions = {
45
35
  *
46
36
  * [AWS.S3ClientConfig Docs](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-s3/interfaces/s3clientconfig.html)
47
37
  */
48
- config: AWS.S3ClientConfig;
38
+ config: S3ClientConfig;
49
39
  /**
50
40
  * Whether or not to disable local storage
51
41
  *
@@ -64,20 +54,21 @@ export type S3StorageOptions = {
64
54
  signedDownloads?: SignedDownloadsConfig;
65
55
  /**
66
56
  * When true, the collection-level prefix and document-level prefix are combined
67
- * (compositional). When false (default), document prefix overrides collection
68
- * prefix entirely.
57
+ * (compositional). When false (default), a document prefix already within the
58
+ * collection prefix is used as-is for new uploads; otherwise it is nested beneath it.
59
+ * Existing files retain their stored prefixes for reads, URLs, and cleanup.
69
60
  *
70
- * Example:
71
- * - collection prefix: `collection-prefix/`
72
- * - document prefix: `document-prefix/`
73
- * - resulting prefix with useCompositePrefixes=true: `collection-prefix/document-prefix/`
74
- * - resulting prefix with useCompositePrefixes=false: `document-prefix/`
61
+ * Example with a document prefix already contained by the collection prefix:
62
+ * - collection prefix: `uploads/`
63
+ * - document prefix: `uploads/documents/`
64
+ * - resulting prefix with useCompositePrefixes=true: `uploads/uploads/documents/`
65
+ * - resulting prefix with useCompositePrefixes=false: `uploads/documents/`
75
66
  *
76
67
  * @default false
77
68
  */
78
69
  useCompositePrefixes?: boolean;
79
70
  };
80
- type S3StoragePlugin = (storageS3Args: S3StorageOptions) => Plugin;
81
- export declare const s3Storage: S3StoragePlugin;
71
+ type S3StorageFactory = (storageS3Args: S3StorageOptions) => StorageAdapter;
72
+ export declare const s3Storage: S3StorageFactory;
82
73
  export {};
83
74
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EAEnB,iBAAiB,EAClB,MAAM,wCAAwC,CAAA;AAE/C,OAA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,EAClB,MAAM,wCAAwC,CAAA;AAE/C,OAAO,KAAK,EAAU,cAAc,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAK3E,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAA;AAIzD,MAAM,MAAM,gBAAgB,GAAG;IAC7B;;OAEG;IACH,GAAG,CAAC,EAAE,SAAS,GAAG,aAAa,CAAA;IAE/B;;;;OAIG;IAEH,MAAM,EAAE,MAAM,CAAA;IAEd;;;;;OAKG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;IAEvB;;OAEG;IACH,aAAa,CAAC,EAAE,mBAAmB,CAAA;IACnC;;OAEG;IACH,WAAW,EAAE,OAAO,CAClB,MAAM,CACJ,oBAAoB,EAClB,CAAC;QACC,eAAe,CAAC,EAAE,qBAAqB,CAAA;KACxC,GAAG,IAAI,CAAC,iBAAiB,EAAE,SAAS,CAAC,CAAC,GACvC,IAAI,CACP,CACF,CAAA;IACD;;;;OAIG;IACH,MAAM,EAAE,cAAc,CAAA;IAEtB;;;;OAIG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAA;IAE7B;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB;;OAEG;IACH,eAAe,CAAC,EAAE,qBAAqB,CAAA;IACvC;;;;;;;;;;;;;OAaG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B,CAAA;AAED,KAAK,gBAAgB,GAAG,CAAC,aAAa,EAAE,gBAAgB,KAAK,cAAc,CAAA;AAe3E,eAAO,MAAM,SAAS,EAAE,gBA8GtB,CAAA"}
package/dist/index.js CHANGED
@@ -1,8 +1,6 @@
1
- import * as AWS from '@aws-sdk/client-s3';
1
+ import { S3 } from '@aws-sdk/client-s3';
2
2
  import { cloudStoragePlugin } from '@payloadcms/plugin-cloud-storage';
3
- import { initClientUploads } from '@payloadcms/plugin-cloud-storage/utilities';
4
3
  import { createS3Adapter } from './adapter.js';
5
- import { getGenerateSignedURLHandler } from './generateSignedURL.js';
6
4
  const s3Clients = new Map();
7
5
  const defaultRequestHandlerOpts = {
8
6
  httpAgent: {
@@ -14,38 +12,25 @@ const defaultRequestHandlerOpts = {
14
12
  maxSockets: 100
15
13
  }
16
14
  };
17
- export const s3Storage = (s3StorageOptions)=>(incomingConfig)=>{
18
- const cacheKey = s3StorageOptions.clientCacheKey || `s3:${s3StorageOptions.bucket}`;
19
- const getStorageClient = ()=>{
20
- if (s3Clients.has(cacheKey)) {
15
+ export const s3Storage = (s3StorageOptions)=>({
16
+ name: 's3',
17
+ collections: Object.keys(s3StorageOptions.collections),
18
+ init: (incomingConfig)=>{
19
+ const cacheKey = s3StorageOptions.clientCacheKey || `s3:${s3StorageOptions.bucket}`;
20
+ const isPluginDisabled = s3StorageOptions.enabled === false;
21
+ const getStorageClient = ()=>{
22
+ if (s3Clients.has(cacheKey)) {
23
+ return s3Clients.get(cacheKey);
24
+ }
25
+ s3Clients.set(cacheKey, new S3({
26
+ requestHandler: defaultRequestHandlerOpts,
27
+ ...s3StorageOptions.config ?? {}
28
+ }));
21
29
  return s3Clients.get(cacheKey);
22
- }
23
- s3Clients.set(cacheKey, new AWS.S3({
24
- requestHandler: defaultRequestHandlerOpts,
25
- ...s3StorageOptions.config ?? {}
26
- }));
27
- return s3Clients.get(cacheKey);
28
- };
29
- const isPluginDisabled = s3StorageOptions.enabled === false;
30
- initClientUploads({
31
- clientHandler: '@payloadcms/storage-s3/client#S3ClientUploadHandler',
32
- collections: s3StorageOptions.collections,
33
- config: incomingConfig,
34
- enabled: !isPluginDisabled && Boolean(s3StorageOptions.clientUploads),
35
- serverHandler: getGenerateSignedURLHandler({
36
- access: typeof s3StorageOptions.clientUploads === 'object' ? s3StorageOptions.clientUploads.access : undefined,
37
- acl: s3StorageOptions.acl,
38
- bucket: s3StorageOptions.bucket,
39
- collections: s3StorageOptions.collections,
40
- getStorageClient,
41
- useCompositePrefixes: s3StorageOptions.useCompositePrefixes
42
- }),
43
- serverHandlerPath: '/storage-s3-generate-signed-url'
44
- });
45
- if (isPluginDisabled) {
46
- // If alwaysInsertFields is true, still call cloudStoragePlugin to insert fields
47
- if (s3StorageOptions.alwaysInsertFields) {
48
- // Build collections with adapter: null since plugin is disabled
30
+ };
31
+ if (isPluginDisabled) {
32
+ // Still call cloudStoragePlugin with adapter: null so fields (like prefix) are
33
+ // inserted into the schema, keeping it consistent across environments.
49
34
  const collectionsWithoutAdapter = Object.entries(s3StorageOptions.collections).reduce((acc, [slug, collOptions])=>({
50
35
  ...acc,
51
36
  [slug]: {
@@ -54,60 +39,57 @@ export const s3Storage = (s3StorageOptions)=>(incomingConfig)=>{
54
39
  }
55
40
  }), {});
56
41
  return cloudStoragePlugin({
57
- alwaysInsertFields: true,
58
42
  collections: collectionsWithoutAdapter,
59
43
  enabled: false,
60
44
  useCompositePrefixes: s3StorageOptions.useCompositePrefixes
61
45
  })(incomingConfig);
62
46
  }
63
- return incomingConfig;
64
- }
65
- // Determine signedDownloads for this collection
66
- const resolveSignedDownloads = (slug)=>{
67
- const collectionStorageConfig = s3StorageOptions.collections[slug];
68
- let signedDownloads = typeof collectionStorageConfig === 'object' ? collectionStorageConfig.signedDownloads ?? false : null;
69
- if (signedDownloads === null) {
70
- signedDownloads = s3StorageOptions.signedDownloads ?? false;
71
- }
72
- return signedDownloads;
73
- };
74
- // Add adapter to each collection option object
75
- const collectionsWithAdapter = Object.entries(s3StorageOptions.collections).reduce((acc, [slug, collOptions])=>({
76
- ...acc,
77
- [slug]: {
78
- ...collOptions === true ? {} : collOptions,
79
- adapter: createS3Adapter({
80
- acl: s3StorageOptions.acl,
81
- bucket: s3StorageOptions.bucket,
82
- clientUploads: s3StorageOptions.clientUploads,
83
- config: s3StorageOptions.config,
84
- getStorageClient,
85
- signedDownloads: resolveSignedDownloads(slug),
86
- useCompositePrefixes: s3StorageOptions.useCompositePrefixes
87
- })
47
+ // Determine signedDownloads for this collection
48
+ const resolveSignedDownloads = (slug)=>{
49
+ const collectionStorageConfig = s3StorageOptions.collections[slug];
50
+ let signedDownloads = typeof collectionStorageConfig === 'object' ? collectionStorageConfig.signedDownloads ?? false : null;
51
+ if (signedDownloads === null) {
52
+ signedDownloads = s3StorageOptions.signedDownloads ?? false;
88
53
  }
89
- }), {});
90
- // Set disableLocalStorage: true for collections specified in the plugin options
91
- const config = {
92
- ...incomingConfig,
93
- collections: (incomingConfig.collections || []).map((collection)=>{
94
- if (!collectionsWithAdapter[collection.slug]) {
95
- return collection;
96
- }
97
- return {
98
- ...collection,
99
- upload: {
100
- ...typeof collection.upload === 'object' ? collection.upload : {},
101
- disableLocalStorage: true
54
+ return signedDownloads;
55
+ };
56
+ // Add adapter to each collection option object
57
+ const collectionsWithAdapter = Object.entries(s3StorageOptions.collections).reduce((acc, [slug, collOptions])=>({
58
+ ...acc,
59
+ [slug]: {
60
+ ...collOptions === true ? {} : collOptions,
61
+ adapter: createS3Adapter({
62
+ acl: s3StorageOptions.acl,
63
+ bucket: s3StorageOptions.bucket,
64
+ clientUploads: s3StorageOptions.clientUploads,
65
+ config: s3StorageOptions.config,
66
+ getStorageClient,
67
+ signedDownloads: resolveSignedDownloads(slug),
68
+ useCompositePrefixes: s3StorageOptions.useCompositePrefixes
69
+ })
70
+ }
71
+ }), {});
72
+ // Set disableLocalStorage: true for collections specified in the plugin options
73
+ const config = {
74
+ ...incomingConfig,
75
+ collections: (incomingConfig.collections || []).map((collection)=>{
76
+ if (!collectionsWithAdapter[collection.slug]) {
77
+ return collection;
102
78
  }
103
- };
104
- })
105
- };
106
- return cloudStoragePlugin({
107
- alwaysInsertFields: s3StorageOptions.alwaysInsertFields,
108
- collections: collectionsWithAdapter,
109
- useCompositePrefixes: s3StorageOptions.useCompositePrefixes
110
- })(config);
111
- };
79
+ return {
80
+ ...collection,
81
+ upload: {
82
+ ...typeof collection.upload === 'object' ? collection.upload : {},
83
+ disableLocalStorage: true
84
+ }
85
+ };
86
+ })
87
+ };
88
+ return cloudStoragePlugin({
89
+ collections: collectionsWithAdapter,
90
+ useCompositePrefixes: s3StorageOptions.useCompositePrefixes
91
+ })(config);
92
+ }
93
+ });
112
94
 
113
95
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type {\n ClientUploadsConfig,\n PluginOptions as CloudStoragePluginOptions,\n CollectionOptions,\n} from '@payloadcms/plugin-cloud-storage/types'\nimport type { NodeHttpHandlerOptions } from '@smithy/node-http-handler'\nimport type { Config, Plugin, UploadCollectionSlug } from 'payload'\n\nimport * as AWS from '@aws-sdk/client-s3'\nimport { cloudStoragePlugin } from '@payloadcms/plugin-cloud-storage'\nimport { initClientUploads } from '@payloadcms/plugin-cloud-storage/utilities'\n\nimport type { SignedDownloadsConfig } from './getFile.js'\n\nimport { createS3Adapter } from './adapter.js'\nimport { getGenerateSignedURLHandler } from './generateSignedURL.js'\n\nexport type S3StorageOptions = {\n /**\n * Access control list for uploaded files.\n */\n acl?: 'private' | 'public-read'\n\n /**\n * When enabled, fields (like the prefix field) will always be inserted into\n * the collection schema regardless of whether the plugin is enabled. This\n * ensures a consistent schema across all environments.\n *\n * This will be enabled by default in Payload v4.\n *\n * @default false\n */\n alwaysInsertFields?: boolean\n\n /**\n * Bucket name to upload files to.\n *\n * Must follow [AWS S3 bucket naming conventions](https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucketnamingrules.html).\n */\n\n bucket: string\n\n /**\n * Optional cache key to identify the S3 storage client instance.\n * If not provided, a default key will be used.\n *\n * @default `s3:containerName`\n */\n clientCacheKey?: string\n\n /**\n * Do uploads directly on the client to bypass limits on Vercel. You must allow CORS PUT method for the bucket to your website.\n */\n clientUploads?: ClientUploadsConfig\n /**\n * Collection options to apply the S3 adapter to.\n */\n collections: Partial<\n Record<\n UploadCollectionSlug,\n | ({\n signedDownloads?: SignedDownloadsConfig\n } & Omit<CollectionOptions, 'adapter'>)\n | true\n >\n >\n /**\n * AWS S3 client configuration. Highly dependent on your AWS setup.\n *\n * [AWS.S3ClientConfig Docs](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-s3/interfaces/s3clientconfig.html)\n */\n config: AWS.S3ClientConfig\n\n /**\n * Whether or not to disable local storage\n *\n * @default true\n */\n disableLocalStorage?: boolean\n\n /**\n * Whether or not to enable the plugin\n *\n * Default: true\n */\n enabled?: boolean\n /**\n * Use pre-signed URLs for files downloading. Can be overriden per-collection.\n */\n signedDownloads?: SignedDownloadsConfig\n /**\n * When true, the collection-level prefix and document-level prefix are combined\n * (compositional). When false (default), document prefix overrides collection\n * prefix entirely.\n *\n * Example:\n * - collection prefix: `collection-prefix/`\n * - document prefix: `document-prefix/`\n * - resulting prefix with useCompositePrefixes=true: `collection-prefix/document-prefix/`\n * - resulting prefix with useCompositePrefixes=false: `document-prefix/`\n *\n * @default false\n */\n useCompositePrefixes?: boolean\n}\n\ntype S3StoragePlugin = (storageS3Args: S3StorageOptions) => Plugin\n\nconst s3Clients = new Map<string, AWS.S3>()\n\nconst defaultRequestHandlerOpts: NodeHttpHandlerOptions = {\n httpAgent: {\n keepAlive: true,\n maxSockets: 100,\n },\n httpsAgent: {\n keepAlive: true,\n maxSockets: 100,\n },\n}\n\nexport const s3Storage: S3StoragePlugin =\n (s3StorageOptions: S3StorageOptions) =>\n (incomingConfig: Config): Config => {\n const cacheKey = s3StorageOptions.clientCacheKey || `s3:${s3StorageOptions.bucket}`\n\n const getStorageClient: () => AWS.S3 = () => {\n if (s3Clients.has(cacheKey)) {\n return s3Clients.get(cacheKey)!\n }\n\n s3Clients.set(\n cacheKey,\n new AWS.S3({\n requestHandler: defaultRequestHandlerOpts,\n ...(s3StorageOptions.config ?? {}),\n }),\n )\n\n return s3Clients.get(cacheKey)!\n }\n\n const isPluginDisabled = s3StorageOptions.enabled === false\n\n initClientUploads({\n clientHandler: '@payloadcms/storage-s3/client#S3ClientUploadHandler',\n collections: s3StorageOptions.collections,\n config: incomingConfig,\n enabled: !isPluginDisabled && Boolean(s3StorageOptions.clientUploads),\n serverHandler: getGenerateSignedURLHandler({\n access:\n typeof s3StorageOptions.clientUploads === 'object'\n ? s3StorageOptions.clientUploads.access\n : undefined,\n acl: s3StorageOptions.acl,\n bucket: s3StorageOptions.bucket,\n collections: s3StorageOptions.collections,\n getStorageClient,\n useCompositePrefixes: s3StorageOptions.useCompositePrefixes,\n }),\n serverHandlerPath: '/storage-s3-generate-signed-url',\n })\n\n if (isPluginDisabled) {\n // If alwaysInsertFields is true, still call cloudStoragePlugin to insert fields\n if (s3StorageOptions.alwaysInsertFields) {\n // Build collections with adapter: null since plugin is disabled\n const collectionsWithoutAdapter: CloudStoragePluginOptions['collections'] = Object.entries(\n s3StorageOptions.collections,\n ).reduce(\n (acc, [slug, collOptions]) => ({\n ...acc,\n [slug]: {\n ...(collOptions === true ? {} : collOptions),\n adapter: null,\n },\n }),\n {} as Record<string, CollectionOptions>,\n )\n\n return cloudStoragePlugin({\n alwaysInsertFields: true,\n collections: collectionsWithoutAdapter,\n enabled: false,\n useCompositePrefixes: s3StorageOptions.useCompositePrefixes,\n })(incomingConfig)\n }\n\n return incomingConfig\n }\n\n // Determine signedDownloads for this collection\n const resolveSignedDownloads = (slug: string): SignedDownloadsConfig => {\n const collectionStorageConfig = s3StorageOptions.collections[slug]\n\n let signedDownloads: null | SignedDownloadsConfig =\n typeof collectionStorageConfig === 'object'\n ? (collectionStorageConfig.signedDownloads ?? false)\n : null\n\n if (signedDownloads === null) {\n signedDownloads = s3StorageOptions.signedDownloads ?? false\n }\n\n return signedDownloads\n }\n\n // Add adapter to each collection option object\n const collectionsWithAdapter: CloudStoragePluginOptions['collections'] = Object.entries(\n s3StorageOptions.collections,\n ).reduce(\n (acc, [slug, collOptions]) => ({\n ...acc,\n [slug]: {\n ...(collOptions === true ? {} : collOptions),\n adapter: createS3Adapter({\n acl: s3StorageOptions.acl,\n bucket: s3StorageOptions.bucket,\n clientUploads: s3StorageOptions.clientUploads,\n config: s3StorageOptions.config,\n getStorageClient,\n signedDownloads: resolveSignedDownloads(slug),\n useCompositePrefixes: s3StorageOptions.useCompositePrefixes,\n }),\n },\n }),\n {} as Record<string, CollectionOptions>,\n )\n\n // Set disableLocalStorage: true for collections specified in the plugin options\n const config = {\n ...incomingConfig,\n collections: (incomingConfig.collections || []).map((collection) => {\n if (!collectionsWithAdapter[collection.slug]) {\n return collection\n }\n\n return {\n ...collection,\n upload: {\n ...(typeof collection.upload === 'object' ? collection.upload : {}),\n disableLocalStorage: true,\n },\n }\n }),\n }\n\n return cloudStoragePlugin({\n alwaysInsertFields: s3StorageOptions.alwaysInsertFields,\n collections: collectionsWithAdapter,\n useCompositePrefixes: s3StorageOptions.useCompositePrefixes,\n })(config)\n }\n"],"names":["AWS","cloudStoragePlugin","initClientUploads","createS3Adapter","getGenerateSignedURLHandler","s3Clients","Map","defaultRequestHandlerOpts","httpAgent","keepAlive","maxSockets","httpsAgent","s3Storage","s3StorageOptions","incomingConfig","cacheKey","clientCacheKey","bucket","getStorageClient","has","get","set","S3","requestHandler","config","isPluginDisabled","enabled","clientHandler","collections","Boolean","clientUploads","serverHandler","access","undefined","acl","useCompositePrefixes","serverHandlerPath","alwaysInsertFields","collectionsWithoutAdapter","Object","entries","reduce","acc","slug","collOptions","adapter","resolveSignedDownloads","collectionStorageConfig","signedDownloads","collectionsWithAdapter","map","collection","upload","disableLocalStorage"],"mappings":"AAQA,YAAYA,SAAS,qBAAoB;AACzC,SAASC,kBAAkB,QAAQ,mCAAkC;AACrE,SAASC,iBAAiB,QAAQ,6CAA4C;AAI9E,SAASC,eAAe,QAAQ,eAAc;AAC9C,SAASC,2BAA2B,QAAQ,yBAAwB;AA6FpE,MAAMC,YAAY,IAAIC;AAEtB,MAAMC,4BAAoD;IACxDC,WAAW;QACTC,WAAW;QACXC,YAAY;IACd;IACAC,YAAY;QACVF,WAAW;QACXC,YAAY;IACd;AACF;AAEA,OAAO,MAAME,YACX,CAACC,mBACD,CAACC;QACC,MAAMC,WAAWF,iBAAiB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AmB;YACxBoC,oBAAoBxB,iBAAiBwB,kBAAkB;YACvDT,aAAaqB;YACbd,sBAAsBtB,iBAAiBsB,oBAAoB;QAC7D,GAAGX;IACL,EAAC"}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { S3ClientConfig } from '@aws-sdk/client-s3'\nimport type {\n ClientUploadsConfig,\n PluginOptions as CloudStoragePluginOptions,\n CollectionOptions,\n} from '@payloadcms/plugin-cloud-storage/types'\nimport type { NodeHttpHandlerOptions } from '@smithy/node-http-handler'\nimport type { Config, StorageAdapter, UploadCollectionSlug } from 'payload'\n\nimport { S3 } from '@aws-sdk/client-s3'\nimport { cloudStoragePlugin } from '@payloadcms/plugin-cloud-storage'\n\nimport type { SignedDownloadsConfig } from './getFile.js'\n\nimport { createS3Adapter } from './adapter.js'\n\nexport type S3StorageOptions = {\n /**\n * Access control list for uploaded files.\n */\n acl?: 'private' | 'public-read'\n\n /**\n * Bucket name to upload files to.\n *\n * Must follow [AWS S3 bucket naming conventions](https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucketnamingrules.html).\n */\n\n bucket: string\n\n /**\n * Optional cache key to identify the S3 storage client instance.\n * If not provided, a default key will be used.\n *\n * @default `s3:containerName`\n */\n clientCacheKey?: string\n\n /**\n * Upload directly to S3 instead of through Payload. You must allow CORS PUT requests from your website.\n */\n clientUploads?: ClientUploadsConfig\n /**\n * Collection options to apply the S3 adapter to.\n */\n collections: Partial<\n Record<\n UploadCollectionSlug,\n | ({\n signedDownloads?: SignedDownloadsConfig\n } & Omit<CollectionOptions, 'adapter'>)\n | true\n >\n >\n /**\n * AWS S3 client configuration. Highly dependent on your AWS setup.\n *\n * [AWS.S3ClientConfig Docs](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-s3/interfaces/s3clientconfig.html)\n */\n config: S3ClientConfig\n\n /**\n * Whether or not to disable local storage\n *\n * @default true\n */\n disableLocalStorage?: boolean\n\n /**\n * Whether or not to enable the plugin\n *\n * Default: true\n */\n enabled?: boolean\n /**\n * Use pre-signed URLs for files downloading. Can be overriden per-collection.\n */\n signedDownloads?: SignedDownloadsConfig\n /**\n * When true, the collection-level prefix and document-level prefix are combined\n * (compositional). When false (default), a document prefix already within the\n * collection prefix is used as-is for new uploads; otherwise it is nested beneath it.\n * Existing files retain their stored prefixes for reads, URLs, and cleanup.\n *\n * Example with a document prefix already contained by the collection prefix:\n * - collection prefix: `uploads/`\n * - document prefix: `uploads/documents/`\n * - resulting prefix with useCompositePrefixes=true: `uploads/uploads/documents/`\n * - resulting prefix with useCompositePrefixes=false: `uploads/documents/`\n *\n * @default false\n */\n useCompositePrefixes?: boolean\n}\n\ntype S3StorageFactory = (storageS3Args: S3StorageOptions) => StorageAdapter\n\nconst s3Clients = new Map<string, S3>()\n\nconst defaultRequestHandlerOpts: NodeHttpHandlerOptions = {\n httpAgent: {\n keepAlive: true,\n maxSockets: 100,\n },\n httpsAgent: {\n keepAlive: true,\n maxSockets: 100,\n },\n}\n\nexport const s3Storage: S3StorageFactory = (\n s3StorageOptions: S3StorageOptions,\n): StorageAdapter => ({\n name: 's3',\n collections: Object.keys(s3StorageOptions.collections),\n init: (incomingConfig: Config): Config => {\n const cacheKey = s3StorageOptions.clientCacheKey || `s3:${s3StorageOptions.bucket}`\n\n const isPluginDisabled = s3StorageOptions.enabled === false\n\n const getStorageClient: () => S3 = () => {\n if (s3Clients.has(cacheKey)) {\n return s3Clients.get(cacheKey)!\n }\n\n s3Clients.set(\n cacheKey,\n new S3({\n requestHandler: defaultRequestHandlerOpts,\n ...(s3StorageOptions.config ?? {}),\n }),\n )\n\n return s3Clients.get(cacheKey)!\n }\n\n if (isPluginDisabled) {\n // Still call cloudStoragePlugin with adapter: null so fields (like prefix) are\n // inserted into the schema, keeping it consistent across environments.\n const collectionsWithoutAdapter: CloudStoragePluginOptions['collections'] = Object.entries(\n s3StorageOptions.collections,\n ).reduce(\n (acc, [slug, collOptions]) => ({\n ...acc,\n [slug]: {\n ...(collOptions === true ? {} : collOptions),\n adapter: null,\n },\n }),\n {} as Record<string, CollectionOptions>,\n )\n\n return cloudStoragePlugin({\n collections: collectionsWithoutAdapter,\n enabled: false,\n useCompositePrefixes: s3StorageOptions.useCompositePrefixes,\n })(incomingConfig)\n }\n\n // Determine signedDownloads for this collection\n const resolveSignedDownloads = (slug: string): SignedDownloadsConfig => {\n const collectionStorageConfig = s3StorageOptions.collections[slug]\n\n let signedDownloads: null | SignedDownloadsConfig =\n typeof collectionStorageConfig === 'object'\n ? (collectionStorageConfig.signedDownloads ?? false)\n : null\n\n if (signedDownloads === null) {\n signedDownloads = s3StorageOptions.signedDownloads ?? false\n }\n\n return signedDownloads\n }\n\n // Add adapter to each collection option object\n const collectionsWithAdapter: CloudStoragePluginOptions['collections'] = Object.entries(\n s3StorageOptions.collections,\n ).reduce(\n (acc, [slug, collOptions]) => ({\n ...acc,\n [slug]: {\n ...(collOptions === true ? {} : collOptions),\n adapter: createS3Adapter({\n acl: s3StorageOptions.acl,\n bucket: s3StorageOptions.bucket,\n clientUploads: s3StorageOptions.clientUploads,\n config: s3StorageOptions.config,\n getStorageClient,\n signedDownloads: resolveSignedDownloads(slug),\n useCompositePrefixes: s3StorageOptions.useCompositePrefixes,\n }),\n },\n }),\n {} as Record<string, CollectionOptions>,\n )\n\n // Set disableLocalStorage: true for collections specified in the plugin options\n const config = {\n ...incomingConfig,\n collections: (incomingConfig.collections || []).map((collection) => {\n if (!collectionsWithAdapter[collection.slug]) {\n return collection\n }\n\n return {\n ...collection,\n upload: {\n ...(typeof collection.upload === 'object' ? collection.upload : {}),\n disableLocalStorage: true,\n },\n }\n }),\n }\n\n return cloudStoragePlugin({\n collections: collectionsWithAdapter,\n useCompositePrefixes: s3StorageOptions.useCompositePrefixes,\n })(config)\n },\n})\n"],"names":["S3","cloudStoragePlugin","createS3Adapter","s3Clients","Map","defaultRequestHandlerOpts","httpAgent","keepAlive","maxSockets","httpsAgent","s3Storage","s3StorageOptions","name","collections","Object","keys","init","incomingConfig","cacheKey","clientCacheKey","bucket","isPluginDisabled","enabled","getStorageClient","has","get","set","requestHandler","config","collectionsWithoutAdapter","entries","reduce","acc","slug","collOptions","adapter","useCompositePrefixes","resolveSignedDownloads","collectionStorageConfig","signedDownloads","collectionsWithAdapter","acl","clientUploads","map","collection","upload","disableLocalStorage"],"mappings":"AASA,SAASA,EAAE,QAAQ,qBAAoB;AACvC,SAASC,kBAAkB,QAAQ,mCAAkC;AAIrE,SAASC,eAAe,QAAQ,eAAc;AAmF9C,MAAMC,YAAY,IAAIC;AAEtB,MAAMC,4BAAoD;IACxDC,WAAW;QACTC,WAAW;QACXC,YAAY;IACd;IACAC,YAAY;QACVF,WAAW;QACXC,YAAY;IACd;AACF;AAEA,OAAO,MAAME,YAA8B,CACzCC,mBACoB,CAAA;QACpBC,MAAM;QACNC,aAAaC,OAAOC,IAAI,CAACJ,iBAAiBE,WAAW;QACrDG,MAAM,CAACC;YACL,MAAMC,WAAWP,iBAAiBQ,cAAc,IAAI,CAAC,GAAG,EAAER,iBAAiBS,MAAM,EAAE;YAEnF,MAAMC,mBAAmBV,iBAAiBW,OAAO,KAAK;YAEtD,MAAMC,mBAA6B;gBACjC,IAAIpB,UAAUqB,GAAG,CAACN,WAAW;oBAC3B,OAAOf,UAAUsB,GAAG,CAACP;gBACvB;gBAEAf,UAAUuB,GAAG,CACXR,UACA,IAAIlB,GAAG;oBACL2B,gBAAgBtB;oBAChB,GAAIM,iBAAiBiB,MAAM,IAAI,CAAC,CAAC;gBACnC;gBAGF,OAAOzB,UAAUsB,GAAG,CAACP;YACvB;YAEA,IAAIG,kBAAkB;gBACpB,+EAA+E;gBAC/E,uEAAuE;gBACvE,MAAMQ,4BAAsEf,OAAOgB,OAAO,CACxFnB,iBAAiBE,WAAW,EAC5BkB,MAAM,CACN,CAACC,KAAK,CAACC,MAAMC,YAAY,GAAM,CAAA;wBAC7B,GAAGF,GAAG;wBACN,CAACC,KAAK,EAAE;4BACN,GAAIC,gBAAgB,OA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4BACN,GAAI,OAAOD,WAAWC,MAAM,KAAK,WAAWD,WAAWC,MAAM,GAAG,CAAC,CAAC;4BAClEC,qBAAqB;wBACvB;oBACF;gBACF;YACF;YAEA,OAAO7C,mBAAmB;gBACxBY,aAAa2B;gBACbJ,sBAAsBzB,iBAAiByB,oBAAoB;YAC7D,GAAGR;QACL;IACF,CAAA,EAAE"}
@@ -4,13 +4,10 @@ interface UploadArgs {
4
4
  bucket: string;
5
5
  buffer: Buffer;
6
6
  client: AWS.S3;
7
- collectionPrefix?: string;
8
- docPrefix?: string;
9
- filename: string;
10
7
  mimeType: string;
8
+ storageFilePath: string;
11
9
  tempFilePath?: string;
12
- useCompositePrefixes?: boolean;
13
10
  }
14
- export declare function uploadFile({ acl, bucket, buffer, client, collectionPrefix, docPrefix, filename, mimeType, tempFilePath, useCompositePrefixes, }: UploadArgs): Promise<void>;
11
+ export declare function uploadFile({ acl, bucket, buffer, client, mimeType, storageFilePath, tempFilePath, }: UploadArgs): Promise<void>;
15
12
  export {};
16
13
  //# sourceMappingURL=uploadFile.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"uploadFile.d.ts","sourceRoot":"","sources":["../src/uploadFile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,GAAG,MAAM,oBAAoB,CAAA;AAM9C,UAAU,UAAU;IAClB,GAAG,CAAC,EAAE,SAAS,GAAG,aAAa,CAAA;IAC/B,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,GAAG,CAAC,EAAE,CAAA;IACd,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,MAAM,CAAA;IAChB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B;AAID,wBAAsB,UAAU,CAAC,EAC/B,GAAG,EACH,MAAM,EACN,MAAM,EACN,MAAM,EACN,gBAAqB,EACrB,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,YAAY,EACZ,oBAA4B,GAC7B,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAoC5B"}
1
+ {"version":3,"file":"uploadFile.d.ts","sourceRoot":"","sources":["../src/uploadFile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,GAAG,MAAM,oBAAoB,CAAA;AAK9C,UAAU,UAAU;IAClB,GAAG,CAAC,EAAE,SAAS,GAAG,aAAa,CAAA;IAC/B,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,GAAG,CAAC,EAAE,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;IAChB,eAAe,EAAE,MAAM,CAAA;IACvB,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB;AAID,wBAAsB,UAAU,CAAC,EAC/B,GAAG,EACH,MAAM,EACN,MAAM,EACN,MAAM,EACN,QAAQ,EACR,eAAe,EACf,YAAY,GACb,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CA6B5B"}
@@ -1,15 +1,8 @@
1
1
  import { Upload } from '@aws-sdk/lib-storage';
2
- import { getFileKey } from '@payloadcms/plugin-cloud-storage/utilities';
3
2
  import fs from 'fs';
4
3
  const multipartThreshold = 1024 * 1024 * 50 // 50MB
5
4
  ;
6
- export async function uploadFile({ acl, bucket, buffer, client, collectionPrefix = '', docPrefix, filename, mimeType, tempFilePath, useCompositePrefixes = false }) {
7
- const { fileKey } = getFileKey({
8
- collectionPrefix,
9
- docPrefix,
10
- filename,
11
- useCompositePrefixes
12
- });
5
+ export async function uploadFile({ acl, bucket, buffer, client, mimeType, storageFilePath, tempFilePath }) {
13
6
  const fileBufferOrStream = tempFilePath ? fs.createReadStream(tempFilePath) : buffer;
14
7
  if (buffer.length > 0 && buffer.length < multipartThreshold) {
15
8
  await client.putObject({
@@ -17,7 +10,7 @@ export async function uploadFile({ acl, bucket, buffer, client, collectionPrefix
17
10
  Body: fileBufferOrStream,
18
11
  Bucket: bucket,
19
12
  ContentType: mimeType,
20
- Key: fileKey
13
+ Key: storageFilePath
21
14
  });
22
15
  return;
23
16
  }
@@ -28,7 +21,7 @@ export async function uploadFile({ acl, bucket, buffer, client, collectionPrefix
28
21
  Body: fileBufferOrStream,
29
22
  Bucket: bucket,
30
23
  ContentType: mimeType,
31
- Key: fileKey
24
+ Key: storageFilePath
32
25
  },
33
26
  partSize: multipartThreshold,
34
27
  queueSize: 4
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/uploadFile.ts"],"sourcesContent":["import type * as AWS from '@aws-sdk/client-s3'\n\nimport { Upload } from '@aws-sdk/lib-storage'\nimport { getFileKey } from '@payloadcms/plugin-cloud-storage/utilities'\nimport fs from 'fs'\n\ninterface UploadArgs {\n acl?: 'private' | 'public-read'\n bucket: string\n buffer: Buffer\n client: AWS.S3\n collectionPrefix?: string\n docPrefix?: string\n filename: string\n mimeType: string\n tempFilePath?: string\n useCompositePrefixes?: boolean\n}\n\nconst multipartThreshold = 1024 * 1024 * 50 // 50MB\n\nexport async function uploadFile({\n acl,\n bucket,\n buffer,\n client,\n collectionPrefix = '',\n docPrefix,\n filename,\n mimeType,\n tempFilePath,\n useCompositePrefixes = false,\n}: UploadArgs): Promise<void> {\n const { fileKey } = getFileKey({\n collectionPrefix,\n docPrefix,\n filename,\n useCompositePrefixes,\n })\n\n const fileBufferOrStream = tempFilePath ? fs.createReadStream(tempFilePath) : buffer\n\n if (buffer.length > 0 && buffer.length < multipartThreshold) {\n await client.putObject({\n ACL: acl,\n Body: fileBufferOrStream,\n Bucket: bucket,\n ContentType: mimeType,\n Key: fileKey,\n })\n\n return\n }\n\n const parallelUploadS3 = new Upload({\n client,\n params: {\n ACL: acl,\n Body: fileBufferOrStream,\n Bucket: bucket,\n ContentType: mimeType,\n Key: fileKey,\n },\n partSize: multipartThreshold,\n queueSize: 4,\n })\n\n await parallelUploadS3.done()\n}\n"],"names":["Upload","getFileKey","fs","multipartThreshold","uploadFile","acl","bucket","buffer","client","collectionPrefix","docPrefix","filename","mimeType","tempFilePath","useCompositePrefixes","fileKey","fileBufferOrStream","createReadStream","length","putObject","ACL","Body","Bucket","ContentType","Key","parallelUploadS3","params","partSize","queueSize","done"],"mappings":"AAEA,SAASA,MAAM,QAAQ,uBAAsB;AAC7C,SAASC,UAAU,QAAQ,6CAA4C;AACvE,OAAOC,QAAQ,KAAI;AAenB,MAAMC,qBAAqB,OAAO,OAAO,GAAG,OAAO;;AAEnD,OAAO,eAAeC,WAAW,EAC/BC,GAAG,EACHC,MAAM,EACNC,MAAM,EACNC,MAAM,EACNC,mBAAmB,EAAE,EACrBC,SAAS,EACTC,QAAQ,EACRC,QAAQ,EACRC,YAAY,EACZC,uBAAuB,KAAK,EACjB;IACX,MAAM,EAAEC,OAAO,EAAE,GAAGd,WAAW;QAC7BQ;QACAC;QACAC;QACAG;IACF;IAEA,MAAME,qBAAqBH,eAAeX,GAAGe,gBAAgB,CAACJ,gBAAgBN;IAE9E,IAAIA,OAAOW,MAAM,GAAG,KAAKX,OAAOW,MAAM,GAAGf,oBAAoB;QAC3D,MAAMK,OAAOW,SAAS,CAAC;YACrBC,KAAKf;YACLgB,MAAML;YACNM,QAAQhB;YACRiB,aAAaX;YACbY,KAAKT;QACP;QAEA;IACF;IAEA,MAAMU,mBAAmB,IAAIzB,OAAO;QAClCQ;QACAkB,QAAQ;YACNN,KAAKf;YACLgB,MAAML;YACNM,QAAQhB;YACRiB,aAAaX;YACbY,KAAKT;QACP;QACAY,UAAUxB;QACVyB,WAAW;IACb;IAEA,MAAMH,iBAAiBI,IAAI;AAC7B"}
1
+ {"version":3,"sources":["../src/uploadFile.ts"],"sourcesContent":["import type * as AWS from '@aws-sdk/client-s3'\n\nimport { Upload } from '@aws-sdk/lib-storage'\nimport fs from 'fs'\n\ninterface UploadArgs {\n acl?: 'private' | 'public-read'\n bucket: string\n buffer: Buffer\n client: AWS.S3\n mimeType: string\n storageFilePath: string\n tempFilePath?: string\n}\n\nconst multipartThreshold = 1024 * 1024 * 50 // 50MB\n\nexport async function uploadFile({\n acl,\n bucket,\n buffer,\n client,\n mimeType,\n storageFilePath,\n tempFilePath,\n}: UploadArgs): Promise<void> {\n const fileBufferOrStream = tempFilePath ? fs.createReadStream(tempFilePath) : buffer\n\n if (buffer.length > 0 && buffer.length < multipartThreshold) {\n await client.putObject({\n ACL: acl,\n Body: fileBufferOrStream,\n Bucket: bucket,\n ContentType: mimeType,\n Key: storageFilePath,\n })\n\n return\n }\n\n const parallelUploadS3 = new Upload({\n client,\n params: {\n ACL: acl,\n Body: fileBufferOrStream,\n Bucket: bucket,\n ContentType: mimeType,\n Key: storageFilePath,\n },\n partSize: multipartThreshold,\n queueSize: 4,\n })\n\n await parallelUploadS3.done()\n}\n"],"names":["Upload","fs","multipartThreshold","uploadFile","acl","bucket","buffer","client","mimeType","storageFilePath","tempFilePath","fileBufferOrStream","createReadStream","length","putObject","ACL","Body","Bucket","ContentType","Key","parallelUploadS3","params","partSize","queueSize","done"],"mappings":"AAEA,SAASA,MAAM,QAAQ,uBAAsB;AAC7C,OAAOC,QAAQ,KAAI;AAYnB,MAAMC,qBAAqB,OAAO,OAAO,GAAG,OAAO;;AAEnD,OAAO,eAAeC,WAAW,EAC/BC,GAAG,EACHC,MAAM,EACNC,MAAM,EACNC,MAAM,EACNC,QAAQ,EACRC,eAAe,EACfC,YAAY,EACD;IACX,MAAMC,qBAAqBD,eAAeT,GAAGW,gBAAgB,CAACF,gBAAgBJ;IAE9E,IAAIA,OAAOO,MAAM,GAAG,KAAKP,OAAOO,MAAM,GAAGX,oBAAoB;QAC3D,MAAMK,OAAOO,SAAS,CAAC;YACrBC,KAAKX;YACLY,MAAML;YACNM,QAAQZ;YACRa,aAAaV;YACbW,KAAKV;QACP;QAEA;IACF;IAEA,MAAMW,mBAAmB,IAAIpB,OAAO;QAClCO;QACAc,QAAQ;YACNN,KAAKX;YACLY,MAAML;YACNM,QAAQZ;YACRa,aAAaV;YACbW,KAAKV;QACP;QACAa,UAAUpB;QACVqB,WAAW;IACb;IAEA,MAAMH,iBAAiBI,IAAI;AAC7B"}