@payloadcms/storage-vercel-blob 3.47.0-canary.3 → 3.47.0-canary.5

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.
@@ -1 +1 @@
1
- {"version":3,"file":"staticHandler.d.ts","sourceRoot":"","sources":["../src/staticHandler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAA;AAC3E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAM/C,KAAK,iBAAiB,GAAG;IACvB,OAAO,EAAE,MAAM,CAAA;IACf,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAED,eAAO,MAAM,gBAAgB,2CACiB,iBAAiB,cACjD,gBAAgB,KAC3B,aA4DF,CAAA"}
1
+ {"version":3,"file":"staticHandler.d.ts","sourceRoot":"","sources":["../src/staticHandler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAA;AAC3E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAM/C,KAAK,iBAAiB,GAAG;IACvB,OAAO,EAAE,MAAM,CAAA;IACf,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAED,eAAO,MAAM,gBAAgB,2CACiB,iBAAiB,cACjD,gBAAgB,KAC3B,aAgEF,CAAA"}
@@ -2,7 +2,7 @@ import { getFilePrefix } from '@payloadcms/plugin-cloud-storage/utilities';
2
2
  import { BlobNotFoundError, head } from '@vercel/blob';
3
3
  import path from 'path';
4
4
  export const getStaticHandler = ({ baseUrl, cacheControlMaxAge = 0, token }, collection)=>{
5
- return async (req, { params: { clientUploadContext, filename } })=>{
5
+ return async (req, { headers: incomingHeaders, params: { clientUploadContext, filename } })=>{
6
6
  try {
7
7
  const prefix = await getFilePrefix({
8
8
  clientUploadContext,
@@ -16,18 +16,23 @@ export const getStaticHandler = ({ baseUrl, cacheControlMaxAge = 0, token }, col
16
16
  const blobMetadata = await head(fileUrl, {
17
17
  token
18
18
  });
19
- const uploadedAtString = blobMetadata.uploadedAt.toISOString();
19
+ const { contentDisposition, contentType, size, uploadedAt } = blobMetadata;
20
+ const uploadedAtString = uploadedAt.toISOString();
20
21
  const ETag = `"${fileKey}-${uploadedAtString}"`;
21
- const { contentDisposition, contentType, size } = blobMetadata;
22
+ let headers = new Headers(incomingHeaders);
23
+ headers.append('Cache-Control', `public, max-age=${cacheControlMaxAge}`);
24
+ headers.append('Content-Disposition', contentDisposition);
25
+ headers.append('Content-Length', String(size));
26
+ headers.append('Content-Type', contentType);
27
+ headers.append('ETag', ETag);
28
+ if (collection.upload && typeof collection.upload === 'object' && typeof collection.upload.modifyResponseHeaders === 'function') {
29
+ headers = collection.upload.modifyResponseHeaders({
30
+ headers
31
+ }) || headers;
32
+ }
22
33
  if (etagFromHeaders && etagFromHeaders === ETag) {
23
34
  return new Response(null, {
24
- headers: new Headers({
25
- 'Cache-Control': `public, max-age=${cacheControlMaxAge}`,
26
- 'Content-Disposition': contentDisposition,
27
- 'Content-Length': String(size),
28
- 'Content-Type': contentType,
29
- ETag
30
- }),
35
+ headers,
31
36
  status: 304
32
37
  });
33
38
  }
@@ -45,15 +50,9 @@ export const getStaticHandler = ({ baseUrl, cacheControlMaxAge = 0, token }, col
45
50
  });
46
51
  }
47
52
  const bodyBuffer = await blob.arrayBuffer();
53
+ headers.append('Last-Modified', uploadedAtString);
48
54
  return new Response(bodyBuffer, {
49
- headers: new Headers({
50
- 'Cache-Control': `public, max-age=${cacheControlMaxAge}`,
51
- 'Content-Disposition': contentDisposition,
52
- 'Content-Length': String(size),
53
- 'Content-Type': contentType,
54
- ETag,
55
- 'Last-Modified': blobMetadata.uploadedAt.toUTCString()
56
- }),
55
+ headers,
57
56
  status: 200
58
57
  });
59
58
  } catch (err) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/staticHandler.ts"],"sourcesContent":["import type { StaticHandler } from '@payloadcms/plugin-cloud-storage/types'\nimport type { CollectionConfig } from 'payload'\n\nimport { getFilePrefix } from '@payloadcms/plugin-cloud-storage/utilities'\nimport { BlobNotFoundError, head } from '@vercel/blob'\nimport path from 'path'\n\ntype StaticHandlerArgs = {\n baseUrl: string\n cacheControlMaxAge?: number\n token: string\n}\n\nexport const getStaticHandler = (\n { baseUrl, cacheControlMaxAge = 0, token }: StaticHandlerArgs,\n collection: CollectionConfig,\n): StaticHandler => {\n return async (req, { params: { clientUploadContext, filename } }) => {\n try {\n const prefix = await getFilePrefix({ clientUploadContext, collection, filename, req })\n const fileKey = path.posix.join(prefix, encodeURIComponent(filename))\n const fileUrl = `${baseUrl}/${fileKey}`\n const etagFromHeaders = req.headers.get('etag') || req.headers.get('if-none-match')\n const blobMetadata = await head(fileUrl, { token })\n const uploadedAtString = blobMetadata.uploadedAt.toISOString()\n const ETag = `\"${fileKey}-${uploadedAtString}\"`\n\n const { contentDisposition, contentType, size } = blobMetadata\n\n if (etagFromHeaders && etagFromHeaders === ETag) {\n return new Response(null, {\n headers: new Headers({\n 'Cache-Control': `public, max-age=${cacheControlMaxAge}`,\n 'Content-Disposition': contentDisposition,\n 'Content-Length': String(size),\n 'Content-Type': contentType,\n ETag,\n }),\n status: 304,\n })\n }\n\n const response = await fetch(`${fileUrl}?${uploadedAtString}`, {\n headers: {\n 'Cache-Control': 'no-store, no-cache, must-revalidate',\n Pragma: 'no-cache',\n },\n })\n\n const blob = await response.blob()\n\n if (!blob) {\n return new Response(null, { status: 204, statusText: 'No Content' })\n }\n\n const bodyBuffer = await blob.arrayBuffer()\n\n return new Response(bodyBuffer, {\n headers: new Headers({\n 'Cache-Control': `public, max-age=${cacheControlMaxAge}`,\n 'Content-Disposition': contentDisposition,\n 'Content-Length': String(size),\n 'Content-Type': contentType,\n ETag,\n 'Last-Modified': blobMetadata.uploadedAt.toUTCString(),\n }),\n status: 200,\n })\n } catch (err: unknown) {\n if (err instanceof BlobNotFoundError) {\n return new Response(null, { status: 404, statusText: 'Not Found' })\n }\n req.payload.logger.error({ err, msg: 'Unexpected error in staticHandler' })\n return new Response('Internal Server Error', { status: 500 })\n }\n }\n}\n"],"names":["getFilePrefix","BlobNotFoundError","head","path","getStaticHandler","baseUrl","cacheControlMaxAge","token","collection","req","params","clientUploadContext","filename","prefix","fileKey","posix","join","encodeURIComponent","fileUrl","etagFromHeaders","headers","get","blobMetadata","uploadedAtString","uploadedAt","toISOString","ETag","contentDisposition","contentType","size","Response","Headers","String","status","response","fetch","Pragma","blob","statusText","bodyBuffer","arrayBuffer","toUTCString","err","payload","logger","error","msg"],"mappings":"AAGA,SAASA,aAAa,QAAQ,6CAA4C;AAC1E,SAASC,iBAAiB,EAAEC,IAAI,QAAQ,eAAc;AACtD,OAAOC,UAAU,OAAM;AAQvB,OAAO,MAAMC,mBAAmB,CAC9B,EAAEC,OAAO,EAAEC,qBAAqB,CAAC,EAAEC,KAAK,EAAqB,EAC7DC;IAEA,OAAO,OAAOC,KAAK,EAAEC,QAAQ,EAAEC,mBAAmB,EAAEC,QAAQ,EAAE,EAAE;QAC9D,IAAI;YACF,MAAMC,SAAS,MAAMb,cAAc;gBAAEW;gBAAqBH;gBAAYI;gBAAUH;YAAI;YACpF,MAAMK,UAAUX,KAAKY,KAAK,CAACC,IAAI,CAACH,QAAQI,mBAAmBL;YAC3D,MAAMM,UAAU,GAAGb,QAAQ,CAAC,EAAES,SAAS;YACvC,MAAMK,kBAAkBV,IAAIW,OAAO,CAACC,GAAG,CAAC,WAAWZ,IAAIW,OAAO,CAACC,GAAG,CAAC;YACnE,MAAMC,eAAe,MAAMpB,KAAKgB,SAAS;gBAAEX;YAAM;YACjD,MAAMgB,mBAAmBD,aAAaE,UAAU,CAACC,WAAW;YAC5D,MAAMC,OAAO,CAAC,CAAC,EAAEZ,QAAQ,CAAC,EAAES,iBAAiB,CAAC,CAAC;YA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plugin-cloud-storage/types'\nimport type { CollectionConfig } from 'payload'\n\nimport { getFilePrefix } from '@payloadcms/plugin-cloud-storage/utilities'\nimport { BlobNotFoundError, head } from '@vercel/blob'\nimport path from 'path'\n\ntype StaticHandlerArgs = {\n baseUrl: string\n cacheControlMaxAge?: number\n token: string\n}\n\nexport const getStaticHandler = (\n { baseUrl, cacheControlMaxAge = 0, token }: StaticHandlerArgs,\n collection: CollectionConfig,\n): StaticHandler => {\n return async (req, { headers: incomingHeaders, params: { clientUploadContext, filename } }) => {\n try {\n const prefix = await getFilePrefix({ clientUploadContext, collection, filename, req })\n const fileKey = path.posix.join(prefix, encodeURIComponent(filename))\n const fileUrl = `${baseUrl}/${fileKey}`\n const etagFromHeaders = req.headers.get('etag') || req.headers.get('if-none-match')\n const blobMetadata = await head(fileUrl, { token })\n const { contentDisposition, contentType, size, uploadedAt } = blobMetadata\n const uploadedAtString = uploadedAt.toISOString()\n const ETag = `\"${fileKey}-${uploadedAtString}\"`\n\n let headers = new Headers(incomingHeaders)\n\n headers.append('Cache-Control', `public, max-age=${cacheControlMaxAge}`)\n headers.append('Content-Disposition', contentDisposition)\n headers.append('Content-Length', String(size))\n headers.append('Content-Type', contentType)\n headers.append('ETag', 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 === ETag) {\n return new Response(null, {\n headers,\n status: 304,\n })\n }\n\n const response = await fetch(`${fileUrl}?${uploadedAtString}`, {\n headers: {\n 'Cache-Control': 'no-store, no-cache, must-revalidate',\n Pragma: 'no-cache',\n },\n })\n\n const blob = await response.blob()\n\n if (!blob) {\n return new Response(null, { status: 204, statusText: 'No Content' })\n }\n\n const bodyBuffer = await blob.arrayBuffer()\n\n headers.append('Last-Modified', uploadedAtString)\n\n return new Response(bodyBuffer, {\n headers,\n status: 200,\n })\n } catch (err: unknown) {\n if (err instanceof BlobNotFoundError) {\n return new Response(null, { status: 404, statusText: 'Not Found' })\n }\n req.payload.logger.error({ err, msg: 'Unexpected error in staticHandler' })\n return new Response('Internal Server Error', { status: 500 })\n }\n }\n}\n"],"names":["getFilePrefix","BlobNotFoundError","head","path","getStaticHandler","baseUrl","cacheControlMaxAge","token","collection","req","headers","incomingHeaders","params","clientUploadContext","filename","prefix","fileKey","posix","join","encodeURIComponent","fileUrl","etagFromHeaders","get","blobMetadata","contentDisposition","contentType","size","uploadedAt","uploadedAtString","toISOString","ETag","Headers","append","String","upload","modifyResponseHeaders","Response","status","response","fetch","Pragma","blob","statusText","bodyBuffer","arrayBuffer","err","payload","logger","error","msg"],"mappings":"AAGA,SAASA,aAAa,QAAQ,6CAA4C;AAC1E,SAASC,iBAAiB,EAAEC,IAAI,QAAQ,eAAc;AACtD,OAAOC,UAAU,OAAM;AAQvB,OAAO,MAAMC,mBAAmB,CAC9B,EAAEC,OAAO,EAAEC,qBAAqB,CAAC,EAAEC,KAAK,EAAqB,EAC7DC;IAEA,OAAO,OAAOC,KAAK,EAAEC,SAASC,eAAe,EAAEC,QAAQ,EAAEC,mBAAmB,EAAEC,QAAQ,EAAE,EAAE;QACxF,IAAI;YACF,MAAMC,SAAS,MAAMf,cAAc;gBAAEa;gBAAqBL;gBAAYM;gBAAUL;YAAI;YACpF,MAAMO,UAAUb,KAAKc,KAAK,CAACC,IAAI,CAACH,QAAQI,mBAAmBL;YAC3D,MAAMM,UAAU,GAAGf,QAAQ,CAAC,EAAEW,SAAS;YACvC,MAAMK,kBAAkBZ,IAAIC,OAAO,CAACY,GAAG,CAAC,WAAWb,IAAIC,OAAO,CAACY,GAAG,CAAC;YACnE,MAAMC,eAAe,MAAMrB,KAAKkB,SAAS;gBAAEb;YAAM;YACjD,MAAM,EAAEiB,kBAAkB,EAAEC,WAAW,EAAEC,IAAI,EAAEC,UAAU,EAAE,GAAGJ;YAC9D,MAAMK,mBAAmBD,WAAWE,WAAW;YAC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M,CAACC,KAAK,CAAC;gBAAEH;gBAAKI,KAAK;YAAoC;YACzE,OAAO,IAAIb,SAAS,yBAAyB;gBAAEC,QAAQ;YAAI;QAC7D;IACF;AACF,EAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/storage-vercel-blob",
3
- "version": "3.47.0-canary.3",
3
+ "version": "3.47.0-canary.5",
4
4
  "description": "Payload storage adapter for Vercel Blob Storage",
5
5
  "homepage": "https://payloadcms.com",
6
6
  "repository": {
@@ -38,13 +38,13 @@
38
38
  ],
39
39
  "dependencies": {
40
40
  "@vercel/blob": "^0.22.3",
41
- "@payloadcms/plugin-cloud-storage": "3.47.0-canary.3"
41
+ "@payloadcms/plugin-cloud-storage": "3.47.0-canary.5"
42
42
  },
43
43
  "devDependencies": {
44
- "payload": "3.47.0-canary.3"
44
+ "payload": "3.47.0-canary.5"
45
45
  },
46
46
  "peerDependencies": {
47
- "payload": "3.47.0-canary.3"
47
+ "payload": "3.47.0-canary.5"
48
48
  },
49
49
  "engines": {
50
50
  "node": "^18.20.2 || >=20.9.0"