@payloadcms/storage-vercel-blob 3.13.0 → 3.14.1-canary.881311e
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,
|
|
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,aA2DF,CAAA"}
|
package/dist/staticHandler.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getFilePrefix } from '@payloadcms/plugin-cloud-storage/utilities';
|
|
2
|
-
import { head } from '@vercel/blob';
|
|
2
|
+
import { BlobNotFoundError, head } from '@vercel/blob';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
export const getStaticHandler = ({ baseUrl, cacheControlMaxAge = 0, token }, collection)=>{
|
|
5
5
|
return async (req, { params: { filename } })=>{
|
|
@@ -15,12 +15,6 @@ export const getStaticHandler = ({ baseUrl, cacheControlMaxAge = 0, token }, col
|
|
|
15
15
|
const blobMetadata = await head(fileUrl, {
|
|
16
16
|
token
|
|
17
17
|
});
|
|
18
|
-
if (!blobMetadata) {
|
|
19
|
-
return new Response(null, {
|
|
20
|
-
status: 404,
|
|
21
|
-
statusText: 'Not Found'
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
18
|
const uploadedAtString = blobMetadata.uploadedAt.toISOString();
|
|
25
19
|
const ETag = `"${fileKey}-${uploadedAtString}"`;
|
|
26
20
|
const { contentDisposition, contentType, size } = blobMetadata;
|
|
@@ -59,6 +53,12 @@ export const getStaticHandler = ({ baseUrl, cacheControlMaxAge = 0, token }, col
|
|
|
59
53
|
status: 200
|
|
60
54
|
});
|
|
61
55
|
} catch (err) {
|
|
56
|
+
if (err instanceof BlobNotFoundError) {
|
|
57
|
+
return new Response(null, {
|
|
58
|
+
status: 404,
|
|
59
|
+
statusText: 'Not Found'
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
62
|
req.payload.logger.error({
|
|
63
63
|
err,
|
|
64
64
|
msg: 'Unexpected error in staticHandler'
|
|
@@ -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 { 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: { filename } }) => {\n try {\n const prefix = await getFilePrefix({ collection, filename, req })\n const fileKey = path.posix.join(prefix, encodeURIComponent(filename))\n\n const fileUrl = `${baseUrl}/${fileKey}`\n const etagFromHeaders = req.headers.get('etag') || req.headers.get('if-none-match')\n\n const blobMetadata = await head(fileUrl, { token })\n
|
|
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: { filename } }) => {\n try {\n const prefix = await getFilePrefix({ collection, filename, req })\n const fileKey = path.posix.join(prefix, encodeURIComponent(filename))\n\n const fileUrl = `${baseUrl}/${fileKey}`\n const etagFromHeaders = req.headers.get('etag') || req.headers.get('if-none-match')\n\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 cache: 'no-store',\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","filename","prefix","fileKey","posix","join","encodeURIComponent","fileUrl","etagFromHeaders","headers","get","blobMetadata","uploadedAtString","uploadedAt","toISOString","ETag","contentDisposition","contentType","size","Response","Headers","String","status","response","fetch","cache","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,QAAQ,EAAE,EAAE;QACzC,IAAI;YACF,MAAMC,SAAS,MAAMZ,cAAc;gBAAEQ;gBAAYG;gBAAUF;YAAI;YAC/D,MAAMI,UAAUV,KAAKW,KAAK,CAACC,IAAI,CAACH,QAAQI,mBAAmBL;YAE3D,MAAMM,UAAU,GAAGZ,QAAQ,CAAC,EAAEQ,SAAS;YACvC,MAAMK,kBAAkBT,IAAIU,OAAO,CAACC,GAAG,CAAC,WAAWX,IAAIU,OAAO,CAACC,GAAG,CAAC;YAEnE,MAAMC,eAAe,MAAMnB,KAAKe,SAAS;gBAAEV;YAAM;YACjD,MAAMe,mBAAmBD,aAAaE,UAAU,CAACC,WAAW;YAC5D,MAAMC,OAAO,CAAC,CAAC,EAAEZ,QAAQ,CAAC,EAAES,iBAAiB,CAAC,CAAC;YAE/C,MAAM,EAAEI,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
"version": "3.14.1-canary.881311e",
|
|
4
4
|
"description": "Payload storage adapter for Vercel Blob Storage",
|
|
5
5
|
"homepage": "https://payloadcms.com",
|
|
6
6
|
"repository": {
|
|
@@ -32,13 +32,13 @@
|
|
|
32
32
|
],
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@vercel/blob": "^0.22.3",
|
|
35
|
-
"@payloadcms/plugin-cloud-storage": "3.
|
|
35
|
+
"@payloadcms/plugin-cloud-storage": "3.14.1-canary.881311e"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"payload": "3.
|
|
38
|
+
"payload": "3.14.1-canary.881311e"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
|
-
"payload": "3.
|
|
41
|
+
"payload": "3.14.1-canary.881311e"
|
|
42
42
|
},
|
|
43
43
|
"engines": {
|
|
44
44
|
"node": "^18.20.2 || >=20.9.0"
|