@payloadcms/storage-uploadthing 3.47.0-internal.b17506e → 3.47.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,
|
|
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,aA8G5C,CAAA"}
|
package/dist/staticHandler.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { getKeyFromFilename } from './utilities.js';
|
|
2
2
|
export const getHandler = ({ utApi })=>{
|
|
3
|
-
return async (req, { doc, params: { clientUploadContext, collection, filename } })=>{
|
|
3
|
+
return async (req, { doc, headers: incomingHeaders, params: { clientUploadContext, collection, filename } })=>{
|
|
4
4
|
try {
|
|
5
5
|
let key;
|
|
6
|
+
const collectionConfig = req.payload.collections[collection]?.config;
|
|
6
7
|
if (clientUploadContext && typeof clientUploadContext === 'object' && 'key' in clientUploadContext && typeof clientUploadContext.key === 'string') {
|
|
7
8
|
key = clientUploadContext.key;
|
|
8
9
|
} else {
|
|
9
|
-
const collectionConfig = req.payload.collections[collection]?.config;
|
|
10
10
|
let retrievedDoc = doc;
|
|
11
11
|
if (!retrievedDoc) {
|
|
12
12
|
const or = [
|
|
@@ -67,22 +67,25 @@ export const getHandler = ({ utApi })=>{
|
|
|
67
67
|
const blob = await response.blob();
|
|
68
68
|
const etagFromHeaders = req.headers.get('etag') || req.headers.get('if-none-match');
|
|
69
69
|
const objectEtag = response.headers.get('etag');
|
|
70
|
+
let headers = new Headers(incomingHeaders);
|
|
71
|
+
headers.append('Content-Length', String(blob.size));
|
|
72
|
+
headers.append('Content-Type', blob.type);
|
|
73
|
+
if (objectEtag) {
|
|
74
|
+
headers.append('ETag', objectEtag);
|
|
75
|
+
}
|
|
76
|
+
if (collectionConfig?.upload && typeof collectionConfig.upload === 'object' && typeof collectionConfig.upload.modifyResponseHeaders === 'function') {
|
|
77
|
+
headers = collectionConfig.upload.modifyResponseHeaders({
|
|
78
|
+
headers
|
|
79
|
+
}) || headers;
|
|
80
|
+
}
|
|
70
81
|
if (etagFromHeaders && etagFromHeaders === objectEtag) {
|
|
71
82
|
return new Response(null, {
|
|
72
|
-
headers
|
|
73
|
-
'Content-Length': String(blob.size),
|
|
74
|
-
'Content-Type': blob.type,
|
|
75
|
-
ETag: objectEtag
|
|
76
|
-
}),
|
|
83
|
+
headers,
|
|
77
84
|
status: 304
|
|
78
85
|
});
|
|
79
86
|
}
|
|
80
87
|
return new Response(blob, {
|
|
81
|
-
headers
|
|
82
|
-
'Content-Length': String(blob.size),
|
|
83
|
-
'Content-Type': blob.type,
|
|
84
|
-
ETag: objectEtag
|
|
85
|
-
}),
|
|
88
|
+
headers,
|
|
86
89
|
status: 200
|
|
87
90
|
});
|
|
88
91
|
} catch (err) {
|
|
@@ -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
|
|
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 (\n req,\n { doc, headers: incomingHeaders, params: { clientUploadContext, collection, filename } },\n ) => {\n try {\n let key: string\n const collectionConfig = req.payload.collections[collection]?.config\n\n if (\n clientUploadContext &&\n typeof clientUploadContext === 'object' &&\n 'key' in clientUploadContext &&\n typeof clientUploadContext.key === 'string'\n ) {\n key = clientUploadContext.key\n } else {\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 key = getKeyFromFilename(retrievedDoc, filename)!\n }\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')\n\n let headers = new Headers(incomingHeaders)\n\n headers.append('Content-Length', String(blob.size))\n headers.append('Content-Type', blob.type)\n\n if (objectEtag) {\n headers.append('ETag', objectEtag)\n }\n\n if (\n collectionConfig?.upload &&\n typeof collectionConfig.upload === 'object' &&\n typeof collectionConfig.upload.modifyResponseHeaders === 'function'\n ) {\n headers = collectionConfig.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 return new Response(blob, {\n headers,\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","headers","incomingHeaders","params","clientUploadContext","collection","filename","key","collectionConfig","payload","collections","config","retrievedDoc","or","equals","upload","imageSizes","forEach","name","push","result","db","findOne","where","Response","status","statusText","url","signedURL","getSignedURL","response","fetch","ok","blob","etagFromHeaders","get","objectEtag","Headers","append","String","size","type","modifyResponseHeaders","err","logger","error","msg"],"mappings":"AAIA,SAASA,kBAAkB,QAAQ,iBAAgB;AAMnD,OAAO,MAAMC,aAAa,CAAC,EAAEC,KAAK,EAAQ;IACxC,OAAO,OACLC,KACA,EAAEC,GAAG,EAAEC,SAASC,eAAe,EAAEC,QAAQ,EAAEC,mBAAmB,EAAEC,UAAU,EAAEC,QAAQ,EAAE,EAAE;QAExF,IAAI;YACF,IAAIC;YACJ,MAAMC,mBAAmBT,IAAIU,OAAO,CAACC,WAAW,CAACL,WAAW,EAAEM;YAE9D,IACEP,uBACA,OAAOA,wBAAwB,YAC/B,SAASA,uBACT,OAAOA,oBAAoBG,GAAG,KAAK,UACnC;gBACAA,MAAMH,oBAAoBG,GAAG;YAC/B,OAAO;gBACL,IAAIK,eAAeZ;gBAEnB,IAAI,CAACY,cAAc;oBACjB,MAAMC,KAAc;wBAClB;4BACEP,UAAU;gCACRQ,QAAQR;4BACV;wBACF;qBACD;oBAED,IAAIE,kBAAkBO,OAAOC,YAA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KO,IAAI;YACjDvC,QAAQqC,MAAM,CAAC,gBAAgBL,KAAKQ,IAAI;YAExC,IAAIL,YAAY;gBACdnC,QAAQqC,MAAM,CAAC,QAAQF;YACzB;YAEA,IACE5B,kBAAkBO,UAClB,OAAOP,iBAAiBO,MAAM,KAAK,YACnC,OAAOP,iBAAiBO,MAAM,CAAC2B,qBAAqB,KAAK,YACzD;gBACAzC,UAAUO,iBAAiBO,MAAM,CAAC2B,qBAAqB,CAAC;oBAAEzC;gBAAQ,MAAMA;YAC1E;YAEA,IAAIiC,mBAAmBA,oBAAoBE,YAAY;gBACrD,OAAO,IAAIZ,SAAS,MAAM;oBACxBvB;oBACAwB,QAAQ;gBACV;YACF;YAEA,OAAO,IAAID,SAASS,MAAM;gBACxBhC;gBACAwB,QAAQ;YACV;QACF,EAAE,OAAOkB,KAAK;YACZ5C,IAAIU,OAAO,CAACmC,MAAM,CAACC,KAAK,CAAC;gBAAEF;gBAAKG,KAAK;YAAoC;YACzE,OAAO,IAAItB,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.47.0
|
|
3
|
+
"version": "3.47.0",
|
|
4
4
|
"description": "Payload storage adapter for uploadthing",
|
|
5
5
|
"homepage": "https://payloadcms.com",
|
|
6
6
|
"repository": {
|
|
@@ -38,13 +38,13 @@
|
|
|
38
38
|
],
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"uploadthing": "7.3.0",
|
|
41
|
-
"@payloadcms/plugin-cloud-storage": "3.47.0
|
|
41
|
+
"@payloadcms/plugin-cloud-storage": "3.47.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"payload": "3.47.0
|
|
44
|
+
"payload": "3.47.0"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
|
-
"payload": "3.47.0
|
|
47
|
+
"payload": "3.47.0"
|
|
48
48
|
},
|
|
49
49
|
"engines": {
|
|
50
50
|
"node": "^18.20.2 || >=20.9.0"
|