@payloadcms/storage-uploadthing 3.0.0-canary.f1db24e → 3.0.0-canary.f1f97ff
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.
- package/dist/generateURL.js.map +1 -1
- package/dist/handleDelete.js +1 -1
- package/dist/handleDelete.js.map +1 -1
- package/dist/handleUpload.js +1 -1
- package/dist/handleUpload.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/staticHandler.js.map +1 -1
- package/dist/utilities.js.map +1 -1
- package/package.json +9 -9
package/dist/generateURL.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/generateURL.ts"],"sourcesContent":["import type { GenerateURL } from '@payloadcms/plugin-cloud-storage/types'\n\nimport path from 'path'\n\nimport { getKeyFromFilename } from './utilities.js'\n\nexport const generateURL: GenerateURL = ({ data, filename, prefix = '' }) => {\n const key = getKeyFromFilename(data, filename)\n return `https://utfs.io/f/${path.posix.join(prefix, key || '')}`\n}\n"],"names":["path","getKeyFromFilename","generateURL","data","filename","prefix","key","posix","join"],"
|
|
1
|
+
{"version":3,"sources":["../src/generateURL.ts"],"sourcesContent":["import type { GenerateURL } from '@payloadcms/plugin-cloud-storage/types'\n\nimport path from 'path'\n\nimport { getKeyFromFilename } from './utilities.js'\n\nexport const generateURL: GenerateURL = ({ data, filename, prefix = '' }) => {\n const key = getKeyFromFilename(data, filename)\n return `https://utfs.io/f/${path.posix.join(prefix, key || '')}`\n}\n"],"names":["path","getKeyFromFilename","generateURL","data","filename","prefix","key","posix","join"],"mappings":"AAEA,OAAOA,UAAU,OAAM;AAEvB,SAASC,kBAAkB,QAAQ,iBAAgB;AAEnD,OAAO,MAAMC,cAA2B,CAAC,EAAEC,IAAI,EAAEC,QAAQ,EAAEC,SAAS,EAAE,EAAE;IACtE,MAAMC,MAAML,mBAAmBE,MAAMC;IACrC,OAAO,CAAC,kBAAkB,EAAEJ,KAAKO,KAAK,CAACC,IAAI,CAACH,QAAQC,OAAO,IAAI,CAAC;AAClE,EAAC"}
|
package/dist/handleDelete.js
CHANGED
package/dist/handleDelete.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/handleDelete.ts"],"sourcesContent":["import type { HandleDelete } from '@payloadcms/plugin-cloud-storage/types'\nimport type { UTApi } from 'uploadthing/server'\n\nimport { APIError } from 'payload
|
|
1
|
+
{"version":3,"sources":["../src/handleDelete.ts"],"sourcesContent":["import type { HandleDelete } from '@payloadcms/plugin-cloud-storage/types'\nimport type { UTApi } from 'uploadthing/server'\n\nimport { APIError } from 'payload'\n\nimport { getKeyFromFilename } from './utilities.js'\n\ntype Args = {\n utApi: UTApi\n}\n\nexport const getHandleDelete = ({ utApi }: Args): HandleDelete => {\n return async ({ doc, filename, req }) => {\n const key = getKeyFromFilename(doc, filename)\n\n if (!key) {\n req.payload.logger.error({\n msg: `Error deleting file: ${filename} - unable to extract key from doc`,\n })\n throw new APIError(`Error deleting file: ${filename}`)\n }\n\n try {\n if (key) {\n await utApi.deleteFiles(key)\n }\n } catch (err) {\n req.payload.logger.error({\n err,\n msg: `Error deleting file with key: ${filename} - key: ${key}`,\n })\n throw new APIError(`Error deleting file: ${filename}`)\n }\n }\n}\n"],"names":["APIError","getKeyFromFilename","getHandleDelete","utApi","doc","filename","req","key","payload","logger","error","msg","deleteFiles","err"],"mappings":"AAGA,SAASA,QAAQ,QAAQ,UAAS;AAElC,SAASC,kBAAkB,QAAQ,iBAAgB;AAMnD,OAAO,MAAMC,kBAAkB,CAAC,EAAEC,KAAK,EAAQ;IAC7C,OAAO,OAAO,EAAEC,GAAG,EAAEC,QAAQ,EAAEC,GAAG,EAAE;QAClC,MAAMC,MAAMN,mBAAmBG,KAAKC;QAEpC,IAAI,CAACE,KAAK;YACRD,IAAIE,OAAO,CAACC,MAAM,CAACC,KAAK,CAAC;gBACvBC,KAAK,CAAC,qBAAqB,EAAEN,SAAS,iCAAiC,CAAC;YAC1E;YACA,MAAM,IAAIL,SAAS,CAAC,qBAAqB,EAAEK,SAAS,CAAC;QACvD;QAEA,IAAI;YACF,IAAIE,KAAK;gBACP,MAAMJ,MAAMS,WAAW,CAACL;YAC1B;QACF,EAAE,OAAOM,KAAK;YACZP,IAAIE,OAAO,CAACC,MAAM,CAACC,KAAK,CAAC;gBACvBG;gBACAF,KAAK,CAAC,8BAA8B,EAAEN,SAAS,QAAQ,EAAEE,IAAI,CAAC;YAChE;YACA,MAAM,IAAIP,SAAS,CAAC,qBAAqB,EAAEK,SAAS,CAAC;QACvD;IACF;AACF,EAAC"}
|
package/dist/handleUpload.js
CHANGED
package/dist/handleUpload.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/handleUpload.ts"],"sourcesContent":["import type { HandleUpload } from '@payloadcms/plugin-cloud-storage/types'\nimport type { UTApi } from 'uploadthing/server'\n\nimport { APIError } from 'payload
|
|
1
|
+
{"version":3,"sources":["../src/handleUpload.ts"],"sourcesContent":["import type { HandleUpload } from '@payloadcms/plugin-cloud-storage/types'\nimport type { UTApi } from 'uploadthing/server'\n\nimport { APIError } from 'payload'\nimport { UTFile } from 'uploadthing/server'\n\nimport type { ACL } from './index.js'\n\ntype HandleUploadArgs = {\n acl: ACL\n utApi: UTApi\n}\n\nexport const getHandleUpload = ({ acl, utApi }: HandleUploadArgs): HandleUpload => {\n return async ({ data, file }) => {\n try {\n const { buffer, filename, mimeType } = file\n\n const blob = new Blob([buffer], { type: mimeType })\n const res = await utApi.uploadFiles(new UTFile([blob], filename), { acl })\n\n if (res.error) {\n throw new APIError(`Error uploading file: ${res.error.code} - ${res.error.message}`)\n }\n\n // Find matching data.sizes entry\n const foundSize = Object.keys(data.sizes || {}).find(\n (key) => data.sizes?.[key]?.filename === filename,\n )\n\n if (foundSize) {\n data.sizes[foundSize]._key = res.data?.key\n } else {\n data._key = res.data?.key\n data.filename = res.data?.name\n }\n\n return data\n } catch (error: unknown) {\n if (error instanceof Error) {\n // Interrogate uploadthing error which returns FiberFailure\n if ('toJSON' in error && typeof error.toJSON === 'function') {\n const json = error.toJSON() as {\n cause?: { defect?: { _id?: string; data?: { error?: string }; error?: string } }\n }\n if (json.cause?.defect?.error && json.cause.defect.data?.error) {\n throw new APIError(\n `Error uploading file with uploadthing: ${json.cause.defect.error} - ${json.cause.defect.data.error}`,\n )\n }\n } else {\n throw new APIError(`Error uploading file with uploadthing: ${error.message}`)\n }\n }\n }\n }\n}\n"],"names":["APIError","UTFile","getHandleUpload","acl","utApi","data","file","buffer","filename","mimeType","blob","Blob","type","res","uploadFiles","error","code","message","foundSize","Object","keys","sizes","find","key","_key","name","Error","toJSON","json","cause","defect"],"mappings":"AAGA,SAASA,QAAQ,QAAQ,UAAS;AAClC,SAASC,MAAM,QAAQ,qBAAoB;AAS3C,OAAO,MAAMC,kBAAkB,CAAC,EAAEC,GAAG,EAAEC,KAAK,EAAoB;IAC9D,OAAO,OAAO,EAAEC,IAAI,EAAEC,IAAI,EAAE;QAC1B,IAAI;YACF,MAAM,EAAEC,MAAM,EAAEC,QAAQ,EAAEC,QAAQ,EAAE,GAAGH;YAEvC,MAAMI,OAAO,IAAIC,KAAK;gBAACJ;aAAO,EAAE;gBAAEK,MAAMH;YAAS;YACjD,MAAMI,MAAM,MAAMT,MAAMU,WAAW,CAAC,IAAIb,OAAO;gBAACS;aAAK,EAAEF,WAAW;gBAAEL;YAAI;YAExE,IAAIU,IAAIE,KAAK,EAAE;gBACb,MAAM,IAAIf,SAAS,CAAC,sBAAsB,EAAEa,IAAIE,KAAK,CAACC,IAAI,CAAC,GAAG,EAAEH,IAAIE,KAAK,CAACE,OAAO,CAAC,CAAC;YACrF;YAEA,iCAAiC;YACjC,MAAMC,YAAYC,OAAOC,IAAI,CAACf,KAAKgB,KAAK,IAAI,CAAC,GAAGC,IAAI,CAClD,CAACC,MAAQlB,KAAKgB,KAAK,EAAE,CAACE,IAAI,EAAEf,aAAaA;YAG3C,IAAIU,WAAW;gBACbb,KAAKgB,KAAK,CAACH,UAAU,CAACM,IAAI,GAAGX,IAAIR,IAAI,EAAEkB;YACzC,OAAO;gBACLlB,KAAKmB,IAAI,GAAGX,IAAIR,IAAI,EAAEkB;gBACtBlB,KAAKG,QAAQ,GAAGK,IAAIR,IAAI,EAAEoB;YAC5B;YAEA,OAAOpB;QACT,EAAE,OAAOU,OAAgB;YACvB,IAAIA,iBAAiBW,OAAO;gBAC1B,2DAA2D;gBAC3D,IAAI,YAAYX,SAAS,OAAOA,MAAMY,MAAM,KAAK,YAAY;oBAC3D,MAAMC,OAAOb,MAAMY,MAAM;oBAGzB,IAAIC,KAAKC,KAAK,EAAEC,QAAQf,SAASa,KAAKC,KAAK,CAACC,MAAM,CAACzB,IAAI,EAAEU,OAAO;wBAC9D,MAAM,IAAIf,SACR,CAAC,uCAAuC,EAAE4B,KAAKC,KAAK,CAACC,MAAM,CAACf,KAAK,CAAC,GAAG,EAAEa,KAAKC,KAAK,CAACC,MAAM,CAACzB,IAAI,CAACU,KAAK,CAAC,CAAC;oBAEzG;gBACF,OAAO;oBACL,MAAM,IAAIf,SAAS,CAAC,uCAAuC,EAAEe,MAAME,OAAO,CAAC,CAAC;gBAC9E;YACF;QACF;IACF;AACF,EAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { CollectionOptions } from '@payloadcms/plugin-cloud-storage/types';
|
|
2
|
-
import type { Plugin } from 'payload
|
|
2
|
+
import type { Plugin } from 'payload';
|
|
3
3
|
import type { UTApiOptions } from 'uploadthing/types';
|
|
4
4
|
export type UploadthingStorageOptions = {
|
|
5
5
|
/**
|
|
@@ -15,12 +15,12 @@ export type UploadthingStorageOptions = {
|
|
|
15
15
|
/**
|
|
16
16
|
* Uploadthing Options
|
|
17
17
|
*/
|
|
18
|
-
options:
|
|
18
|
+
options: {
|
|
19
19
|
/**
|
|
20
20
|
* @default 'public-read'
|
|
21
21
|
*/
|
|
22
22
|
acl?: ACL;
|
|
23
|
-
};
|
|
23
|
+
} & UTApiOptions;
|
|
24
24
|
};
|
|
25
25
|
type UploadthingPlugin = (uploadthingStorageOptions: UploadthingStorageOptions) => Plugin;
|
|
26
26
|
/** NOTE: not synced with uploadthing's internal types. Need to modify if more options added */
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,iBAAiB,EAElB,MAAM,wCAAwC,CAAA;AAC/C,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,iBAAiB,EAElB,MAAM,wCAAwC,CAAA;AAC/C,OAAO,KAAK,EAAiB,MAAM,EAAE,MAAM,SAAS,CAAA;AACpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAUrD,MAAM,MAAM,yBAAyB,GAAG;IACtC;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,iBAAiB,EAAE,SAAS,CAAC,GAAG,IAAI,CAAC,CAAA;IAEtE;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IAEjB;;OAEG;IACH,OAAO,EAAE;QACP;;WAEG;QACH,GAAG,CAAC,EAAE,GAAG,CAAA;KACV,GAAG,YAAY,CAAA;CACjB,CAAA;AAED,KAAK,iBAAiB,GAAG,CAAC,yBAAyB,EAAE,yBAAyB,KAAK,MAAM,CAAA;AAEzF,+FAA+F;AAC/F,MAAM,MAAM,GAAG,GAAG,SAAS,GAAG,aAAa,CAAA;AAE3C,eAAO,MAAM,kBAAkB,EAAE,iBAuD9B,CAAA"}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type {\n Adapter,\n PluginOptions as CloudStoragePluginOptions,\n CollectionOptions,\n GeneratedAdapter,\n} from '@payloadcms/plugin-cloud-storage/types'\nimport type { Config, Plugin } from 'payload
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type {\n Adapter,\n PluginOptions as CloudStoragePluginOptions,\n CollectionOptions,\n GeneratedAdapter,\n} from '@payloadcms/plugin-cloud-storage/types'\nimport type { Config, Field, Plugin } from 'payload'\nimport type { UTApiOptions } from 'uploadthing/types'\n\nimport { cloudStoragePlugin } from '@payloadcms/plugin-cloud-storage'\nimport { UTApi } from 'uploadthing/server'\n\nimport { generateURL } from './generateURL.js'\nimport { getHandleDelete } from './handleDelete.js'\nimport { getHandleUpload } from './handleUpload.js'\nimport { getHandler } from './staticHandler.js'\n\nexport type UploadthingStorageOptions = {\n /**\n * Collection options to apply the adapter to.\n */\n collections: Record<string, Omit<CollectionOptions, 'adapter'> | true>\n\n /**\n * Whether or not to enable the plugin\n *\n * Default: true\n */\n enabled?: boolean\n\n /**\n * Uploadthing Options\n */\n options: {\n /**\n * @default 'public-read'\n */\n acl?: ACL\n } & UTApiOptions\n}\n\ntype UploadthingPlugin = (uploadthingStorageOptions: UploadthingStorageOptions) => Plugin\n\n/** NOTE: not synced with uploadthing's internal types. Need to modify if more options added */\nexport type ACL = 'private' | 'public-read'\n\nexport const uploadthingStorage: UploadthingPlugin =\n (uploadthingStorageOptions: UploadthingStorageOptions) =>\n (incomingConfig: Config): Config => {\n if (uploadthingStorageOptions.enabled === false) {\n return incomingConfig\n }\n\n // Default ACL to public-read\n if (!uploadthingStorageOptions.options.acl) {\n uploadthingStorageOptions.options.acl = 'public-read'\n }\n\n const adapter = uploadthingInternal(uploadthingStorageOptions, incomingConfig)\n\n // Add adapter to each collection option object\n const collectionsWithAdapter: CloudStoragePluginOptions['collections'] = Object.entries(\n uploadthingStorageOptions.collections,\n ).reduce(\n (acc, [slug, collOptions]) => ({\n ...acc,\n [slug]: {\n ...(collOptions === true ? {} : collOptions),\n\n // Disable payload access control if the ACL is public-read or not set\n // ...(uploadthingStorageOptions.options.acl === 'public-read'\n // ? { disablePayloadAccessControl: true }\n // : {}),\n\n adapter,\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 })(config)\n }\n\nfunction uploadthingInternal(options: UploadthingStorageOptions, incomingConfig: Config): Adapter {\n const fields: Field[] = [\n {\n name: '_key',\n type: 'text',\n admin: {\n hidden: true,\n },\n },\n ]\n\n return (): GeneratedAdapter => {\n const {\n options: { acl = 'public-read', ...utOptions },\n } = options\n\n const utApi = new UTApi(utOptions)\n\n return {\n name: 'uploadthing',\n fields,\n generateURL,\n handleDelete: getHandleDelete({ utApi }),\n handleUpload: getHandleUpload({ acl, utApi }),\n staticHandler: getHandler({ utApi }),\n }\n }\n}\n"],"names":["cloudStoragePlugin","UTApi","generateURL","getHandleDelete","getHandleUpload","getHandler","uploadthingStorage","uploadthingStorageOptions","incomingConfig","enabled","options","acl","adapter","uploadthingInternal","collectionsWithAdapter","Object","entries","collections","reduce","acc","slug","collOptions","config","map","collection","upload","disableLocalStorage","fields","name","type","admin","hidden","utOptions","utApi","handleDelete","handleUpload","staticHandler"],"mappings":"AASA,SAASA,kBAAkB,QAAQ,mCAAkC;AACrE,SAASC,KAAK,QAAQ,qBAAoB;AAE1C,SAASC,WAAW,QAAQ,mBAAkB;AAC9C,SAASC,eAAe,QAAQ,oBAAmB;AACnD,SAASC,eAAe,QAAQ,oBAAmB;AACnD,SAASC,UAAU,QAAQ,qBAAoB;AA+B/C,OAAO,MAAMC,qBACX,CAACC,4BACD,CAACC;QACC,IAAID,0BAA0BE,OAAO,KAAK,OAAO;YAC/C,OAAOD;QACT;QAEA,6BAA6B;QAC7B,IAAI,CAACD,0BAA0BG,OAAO,CAACC,GAAG,EAAE;YAC1CJ,0BAA0BG,OAAO,CAACC,GAAG,GAAG;QAC1C;QAEA,MAAMC,UAAUC,oBAAoBN,2BAA2BC;QAE/D,+CAA+C;QAC/C,MAAMM,yBAAmEC,OAAOC,OAAO,CACrFT,0BAA0BU,WAAW,EACrCC,MAAM,CACN,CAACC,KAAK,CAACC,MAAMC,YAAY,GAAM,CAAA;gBAC7B,GAAGF,GAAG;gBACN,CAACC,KAAK,EAAE;oBACN,GAAIC,gBAAgB,OAAO,CAAC,IAAIA,WAAW;oBAE3C,sEAAsE;oBACtE,8DAA8D;oBAC9D,4CAA4C;oBAC5C,WAAW;oBAEXT;gBACF;YACF,CAAA,GACA,CAAC;QAGH,gFAAgF;QAChF,MAAMU,SAAS;YACb,GAAGd,cAAc;YACjBS,aAAa,AAACT,CAAAA,eAAeS,WAAW,IAAI,EAAE,AAAD,EAAGM,GAAG,CAAC,CAACC;gBACnD,IAAI,CAACV,sBAAsB,CAACU,WAAWJ,IAAI,CAAC,EAAE;oBAC5C,OAAOI;gBACT;gBAEA,OAAO;oBACL,GAAGA,UAAU;oBACbC,QAAQ;wBACN,GAAI,OAAOD,WAAWC,MAAM,KAAK,WAAWD,WAAWC,MAAM,GAAG,CAAC,CAAC;wBAClEC,qBAAqB;oBACvB;gBACF;YACF;QACF;QAEA,OAAO1B,mBAAmB;YACxBiB,aAAaH;QACf,GAAGQ;IACL,EAAC;AAEH,SAAST,oBAAoBH,OAAkC,EAAEF,cAAsB;IACrF,MAAMmB,SAAkB;QACtB;YACEC,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLC,QAAQ;YACV;QACF;KACD;IAED,OAAO;QACL,MAAM,EACJrB,SAAS,EAAEC,MAAM,aAAa,EAAE,GAAGqB,WAAW,EAC/C,GAAGtB;QAEJ,MAAMuB,QAAQ,IAAIhC,MAAM+B;QAExB,OAAO;YACLJ,MAAM;YACND;YACAzB;YACAgC,cAAc/B,gBAAgB;gBAAE8B;YAAM;YACtCE,cAAc/B,gBAAgB;gBAAEO;gBAAKsB;YAAM;YAC3CG,eAAe/B,WAAW;gBAAE4B;YAAM;QACpC;IACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/staticHandler.ts"],"sourcesContent":["import type { StaticHandler } from '@payloadcms/plugin-cloud-storage/types'\nimport type { Where } from 'payload
|
|
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) retrievedDoc = result\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","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,iBAAiBO,MAAM,CAACC,UAAU,CAACC,OAAO,CAAC,CAAC,EAAEC,IAAI,EAAE;wBAClDL,GAAGM,IAAI,CAAC;4BACN,CAAC,CAAC,MAAM,EAAED,KAAK,SAAS,CAAC,CAAC,EAAE;gCAC1BJ,QAAQP;4BACV;wBACF;oBACF;gBACF;gBAEA,MAAMa,SAAS,MAAMjB,IAAIM,OAAO,CAACY,EAAE,CAACC,OAAO,CAAC;oBAC1ChB;oBACAH;oBACAoB,OAAO;wBAAEV;oBAAG;gBACd;gBAEA,IAAIO,QAAQR,eAAeQ;YAC7B;YAEA,IAAI,CAACR,cAAc;gBACjB,OAAO,IAAIY,SAAS,MAAM;oBAAEC,QAAQ;oBAAKC,YAAY;gBAAY;YACnE;YAEA,MAAMC,MAAM3B,mBAAmBY,cAAcL;YAC7C,IAAI,CAACoB,KAAK;gBACR,OAAO,IAAIH,SAAS,MAAM;oBAAEC,QAAQ;oBAAKC,YAAY;gBAAY;YACnE;YAEA,MAAM,EAAEE,KAAKC,SAAS,EAAE,GAAG,MAAM3B,MAAM4B,YAAY,CAACH;YAEpD,IAAI,CAACE,WAAW;gBACd,OAAO,IAAIL,SAAS,MAAM;oBAAEC,QAAQ;oBAAKC,YAAY;gBAAY;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"}
|
package/dist/utilities.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utilities.ts"],"sourcesContent":["/**\n * Extract '_key' value from the doc safely\n */\nexport const getKeyFromFilename = (doc: unknown, filename: string) => {\n if (\n doc &&\n typeof doc === 'object' &&\n 'filename' in doc &&\n doc.filename === filename &&\n '_key' in doc\n ) {\n return doc._key as string\n }\n if (doc && typeof doc === 'object' && 'sizes' in doc) {\n const sizes = doc.sizes\n if (typeof sizes === 'object' && sizes !== null) {\n for (const size of Object.values(sizes)) {\n if (size?.filename === filename && '_key' in size) {\n return size._key as string\n }\n }\n }\n }\n}\n"],"names":["getKeyFromFilename","doc","filename","_key","sizes","size","Object","values"],"
|
|
1
|
+
{"version":3,"sources":["../src/utilities.ts"],"sourcesContent":["/**\n * Extract '_key' value from the doc safely\n */\nexport const getKeyFromFilename = (doc: unknown, filename: string) => {\n if (\n doc &&\n typeof doc === 'object' &&\n 'filename' in doc &&\n doc.filename === filename &&\n '_key' in doc\n ) {\n return doc._key as string\n }\n if (doc && typeof doc === 'object' && 'sizes' in doc) {\n const sizes = doc.sizes\n if (typeof sizes === 'object' && sizes !== null) {\n for (const size of Object.values(sizes)) {\n if (size?.filename === filename && '_key' in size) {\n return size._key as string\n }\n }\n }\n }\n}\n"],"names":["getKeyFromFilename","doc","filename","_key","sizes","size","Object","values"],"mappings":"AAAA;;CAEC,GACD,OAAO,MAAMA,qBAAqB,CAACC,KAAcC;IAC/C,IACED,OACA,OAAOA,QAAQ,YACf,cAAcA,OACdA,IAAIC,QAAQ,KAAKA,YACjB,UAAUD,KACV;QACA,OAAOA,IAAIE,IAAI;IACjB;IACA,IAAIF,OAAO,OAAOA,QAAQ,YAAY,WAAWA,KAAK;QACpD,MAAMG,QAAQH,IAAIG,KAAK;QACvB,IAAI,OAAOA,UAAU,YAAYA,UAAU,MAAM;YAC/C,KAAK,MAAMC,QAAQC,OAAOC,MAAM,CAACH,OAAQ;gBACvC,IAAIC,MAAMH,aAAaA,YAAY,UAAUG,MAAM;oBACjD,OAAOA,KAAKF,IAAI;gBAClB;YACF;QACF;IACF;AACF,EAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/storage-uploadthing",
|
|
3
|
-
"version": "3.0.0-canary.
|
|
3
|
+
"version": "3.0.0-canary.f1f97ff",
|
|
4
4
|
"description": "Payload storage adapter for uploadthing",
|
|
5
5
|
"homepage": "https://payloadcms.com",
|
|
6
6
|
"repository": {
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"exports": {
|
|
15
15
|
".": {
|
|
16
16
|
"import": "./dist/index.js",
|
|
17
|
-
"
|
|
18
|
-
"
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"default": "./dist/index.js"
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
21
|
"main": "./dist/index.js",
|
|
@@ -25,21 +25,21 @@
|
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"uploadthing": "^6.10.1",
|
|
28
|
-
"@payloadcms/plugin-cloud-storage": "3.0.0-canary.
|
|
28
|
+
"@payloadcms/plugin-cloud-storage": "3.0.0-canary.f1f97ff"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"payload": "3.0.0-canary.
|
|
31
|
+
"payload": "3.0.0-canary.f1f97ff"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"payload": "3.0.0-canary.
|
|
34
|
+
"payload": "3.0.0-canary.f1f97ff"
|
|
35
35
|
},
|
|
36
36
|
"engines": {
|
|
37
|
-
"node": "
|
|
37
|
+
"node": "^18.20.2 || >=20.9.0"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
|
-
"build": "pnpm build:
|
|
40
|
+
"build": "pnpm build:types && pnpm build:swc",
|
|
41
41
|
"build:clean": "find . \\( -type d \\( -name build -o -name dist -o -name .cache \\) -o -type f -name tsconfig.tsbuildinfo \\) -exec rm -rf {} + && pnpm build",
|
|
42
|
-
"build:swc": "swc ./src -d ./dist --config-file .swcrc",
|
|
42
|
+
"build:swc": "swc ./src -d ./dist --config-file .swcrc --strip-leading-paths",
|
|
43
43
|
"build:types": "tsc --emitDeclarationOnly --outDir dist",
|
|
44
44
|
"clean": "rimraf {dist,*.tsbuildinfo}"
|
|
45
45
|
}
|