@payloadcms/storage-uploadthing 3.8.1-canary.84084b6 → 3.9.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.
@@ -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;AAE3E,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAI/C,KAAK,IAAI,GAAG;IACV,KAAK,EAAE,KAAK,CAAA;CACb,CAAA;AAED,eAAO,MAAM,UAAU,cAAe,IAAI,KAAG,aAuE5C,CAAA"}
1
+ {"version":3,"file":"staticHandler.d.ts","sourceRoot":"","sources":["../src/staticHandler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAA;AAE3E,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAI/C,KAAK,IAAI,GAAG;IACV,KAAK,EAAE,KAAK,CAAA;CACb,CAAA;AAED,eAAO,MAAM,UAAU,cAAe,IAAI,KAAG,aAuF5C,CAAA"}
@@ -60,10 +60,23 @@ export const getHandler = ({ utApi })=>{
60
60
  });
61
61
  }
62
62
  const blob = await response.blob();
63
+ const etagFromHeaders = req.headers.get('etag') || req.headers.get('if-none-match');
64
+ const objectEtag = response.headers.get('etag');
65
+ if (etagFromHeaders && etagFromHeaders === objectEtag) {
66
+ return new Response(null, {
67
+ headers: new Headers({
68
+ 'Content-Length': String(blob.size),
69
+ 'Content-Type': blob.type,
70
+ ETag: objectEtag
71
+ }),
72
+ status: 304
73
+ });
74
+ }
63
75
  return new Response(blob, {
64
76
  headers: new Headers({
65
77
  'Content-Length': String(blob.size),
66
- 'Content-Type': blob.type
78
+ 'Content-Type': blob.type,
79
+ ETag: objectEtag
67
80
  }),
68
81
  status: 200
69
82
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/staticHandler.ts"],"sourcesContent":["import type { StaticHandler } from '@payloadcms/plugin-cloud-storage/types'\nimport type { Where } from 'payload'\nimport type { UTApi } from 'uploadthing/server'\n\nimport { getKeyFromFilename } from './utilities.js'\n\ntype Args = {\n utApi: UTApi\n}\n\nexport const getHandler = ({ utApi }: Args): StaticHandler => {\n return async (req, { doc, params: { collection, filename } }) => {\n try {\n const collectionConfig = req.payload.collections[collection]?.config\n let retrievedDoc = doc\n\n if (!retrievedDoc) {\n const or: Where[] = [\n {\n filename: {\n equals: filename,\n },\n },\n ]\n\n if (collectionConfig.upload.imageSizes) {\n collectionConfig.upload.imageSizes.forEach(({ name }) => {\n or.push({\n [`sizes.${name}.filename`]: {\n equals: filename,\n },\n })\n })\n }\n\n const result = await req.payload.db.findOne({\n collection,\n req,\n where: { or },\n })\n\n if (result) {\n retrievedDoc = result\n }\n }\n\n if (!retrievedDoc) {\n return new Response(null, { status: 404, statusText: 'Not Found' })\n }\n\n const key = getKeyFromFilename(retrievedDoc, filename)\n if (!key) {\n return new Response(null, { status: 404, statusText: 'Not Found' })\n }\n\n const { url: signedURL } = await utApi.getSignedURL(key)\n\n if (!signedURL) {\n return new Response(null, { status: 404, statusText: 'Not Found' })\n }\n\n const response = await fetch(signedURL)\n\n if (!response.ok) {\n return new Response(null, { status: 404, statusText: 'Not Found' })\n }\n\n const blob = await response.blob()\n\n return new Response(blob, {\n headers: new Headers({\n 'Content-Length': String(blob.size),\n 'Content-Type': blob.type,\n }),\n status: 200,\n })\n } catch (err) {\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":["getKeyFromFilename","getHandler","utApi","req","doc","params","collection","filename","collectionConfig","payload","collections","config","retrievedDoc","or","equals","upload","imageSizes","forEach","name","push","result","db","findOne","where","Response","status","statusText","key","url","signedURL","getSignedURL","response","fetch","ok","blob","headers","Headers","String","size","type","err","logger","error","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Y;YACnE;YAEA,MAAMK,WAAW,MAAMC,MAAMH;YAE7B,IAAI,CAACE,SAASE,EAAE,EAAE;gBAChB,OAAO,IAAIT,SAAS,MAAM;oBAAEC,QAAQ;oBAAKC,YAAY;gBAAY;YACnE;YAEA,MAAMQ,OAAO,MAAMH,SAASG,IAAI;YAEhC,OAAO,IAAIV,SAASU,MAAM;gBACxBC,SAAS,IAAIC,QAAQ;oBACnB,kBAAkBC,OAAOH,KAAKI,IAAI;oBAClC,gBAAgBJ,KAAKK,IAAI;gBAC3B;gBACAd,QAAQ;YACV;QACF,EAAE,OAAOe,KAAK;YACZrC,IAAIM,OAAO,CAACgC,MAAM,CAACC,KAAK,CAAC;gBAAEF;gBAAKG,KAAK;YAAoC;YACzE,OAAO,IAAInB,SAAS,yBAAyB;gBAAEC,QAAQ;YAAI;QAC7D;IACF;AACF,EAAC"}
1
+ {"version":3,"sources":["../src/staticHandler.ts"],"sourcesContent":["import type { StaticHandler } from '@payloadcms/plugin-cloud-storage/types'\nimport type { Where } from 'payload'\nimport type { UTApi } from 'uploadthing/server'\n\nimport { getKeyFromFilename } from './utilities.js'\n\ntype Args = {\n utApi: UTApi\n}\n\nexport const getHandler = ({ utApi }: Args): StaticHandler => {\n return async (req, { doc, params: { collection, filename } }) => {\n try {\n const collectionConfig = req.payload.collections[collection]?.config\n let retrievedDoc = doc\n\n if (!retrievedDoc) {\n const or: Where[] = [\n {\n filename: {\n equals: filename,\n },\n },\n ]\n\n if (collectionConfig.upload.imageSizes) {\n collectionConfig.upload.imageSizes.forEach(({ name }) => {\n or.push({\n [`sizes.${name}.filename`]: {\n equals: filename,\n },\n })\n })\n }\n\n const result = await req.payload.db.findOne({\n collection,\n req,\n where: { or },\n })\n\n if (result) {\n retrievedDoc = result\n }\n }\n\n if (!retrievedDoc) {\n return new Response(null, { status: 404, statusText: 'Not Found' })\n }\n\n const key = getKeyFromFilename(retrievedDoc, filename)\n\n if (!key) {\n return new Response(null, { status: 404, statusText: 'Not Found' })\n }\n\n const { url: signedURL } = await utApi.getSignedURL(key)\n\n if (!signedURL) {\n return new Response(null, { status: 404, statusText: 'Not Found' })\n }\n\n const response = await fetch(signedURL)\n\n if (!response.ok) {\n return new Response(null, { status: 404, statusText: 'Not Found' })\n }\n\n const blob = await response.blob()\n\n const etagFromHeaders = req.headers.get('etag') || req.headers.get('if-none-match')\n const objectEtag = response.headers.get('etag') as string\n\n if (etagFromHeaders && etagFromHeaders === objectEtag) {\n return new Response(null, {\n headers: new Headers({\n 'Content-Length': String(blob.size),\n 'Content-Type': blob.type,\n ETag: objectEtag,\n }),\n status: 304,\n })\n }\n\n return new Response(blob, {\n headers: new Headers({\n 'Content-Length': String(blob.size),\n 'Content-Type': blob.type,\n ETag: objectEtag,\n }),\n status: 200,\n })\n } catch (err) {\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":["getKeyFromFilename","getHandler","utApi","req","doc","params","collection","filename","collectionConfig","payload","collections","config","retrievedDoc","or","equals","upload","imageSizes","forEach","name","push","result","db","findOne","where","Response","status","statusText","key","url","signedURL","getSignedURL","response","fetch","ok","blob","etagFromHeaders","headers","get","objectEtag","Headers","String","size","type","ETag","err","logger","error","msg"],"mappings":"AAIA,SAASA,kBAAkB,QAAQ,iBAAgB;AAMnD,OAAO,MAAMC,aAAa,CAAC,EAAEC,KAAK,EAAQ;IACxC,OAAO,OAAOC,KAAK,EAAEC,GAAG,EAAEC,QAAQ,EAAEC,UAAU,EAAEC,QAAQ,EAAE,EAAE;QAC1D,IAAI;YACF,MAAMC,mBAAmBL,IAAIM,OAAO,CAACC,WAAW,CAACJ,WAAW,EAAEK;YAC9D,IAAIC,eAAeR;YAEnB,IAAI,CAACQ,cAAc;gBACjB,MAAMC,KAAc;oBAClB;wBACEN,UAAU;4BACRO,QAAQP;wBACV;oBACF;iBACD;gBAED,IAAIC,iBAAiBO,MAAM,CAACC,UAAU,EAAE;oBACtCR,iBA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kBC,OAAON,KAAKO,IAAI;wBAClC,gBAAgBP,KAAKQ,IAAI;wBACzBC,MAAML;oBACR;oBACAb,QAAQ;gBACV;YACF;YAEA,OAAO,IAAID,SAASU,MAAM;gBACxBE,SAAS,IAAIG,QAAQ;oBACnB,kBAAkBC,OAAON,KAAKO,IAAI;oBAClC,gBAAgBP,KAAKQ,IAAI;oBACzBC,MAAML;gBACR;gBACAb,QAAQ;YACV;QACF,EAAE,OAAOmB,KAAK;YACZzC,IAAIM,OAAO,CAACoC,MAAM,CAACC,KAAK,CAAC;gBAAEF;gBAAKG,KAAK;YAAoC;YACzE,OAAO,IAAIvB,SAAS,yBAAyB;gBAAEC,QAAQ;YAAI;QAC7D;IACF;AACF,EAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/storage-uploadthing",
3
- "version": "3.8.1-canary.84084b6",
3
+ "version": "3.9.0",
4
4
  "description": "Payload storage adapter for uploadthing",
5
5
  "homepage": "https://payloadcms.com",
6
6
  "repository": {
@@ -32,13 +32,13 @@
32
32
  ],
33
33
  "dependencies": {
34
34
  "uploadthing": "7.3.0",
35
- "@payloadcms/plugin-cloud-storage": "3.8.1-canary.84084b6"
35
+ "@payloadcms/plugin-cloud-storage": "3.9.0"
36
36
  },
37
37
  "devDependencies": {
38
- "payload": "3.8.1-canary.84084b6"
38
+ "payload": "3.9.0"
39
39
  },
40
40
  "peerDependencies": {
41
- "payload": "3.8.1-canary.84084b6"
41
+ "payload": "3.9.0"
42
42
  },
43
43
  "engines": {
44
44
  "node": "^18.20.2 || >=20.9.0"