@payloadcms/plugin-cloud-storage 3.74.0-internal.bc57c0d → 3.74.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":"afterChange.d.ts","sourceRoot":"","sources":["../../src/hooks/afterChange.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,gBAAgB,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAEhG,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAInD,UAAU,IAAI;IACZ,OAAO,EAAE,gBAAgB,CAAA;IACzB,UAAU,EAAE,gBAAgB,CAAA;CAC7B;AAED,eAAO,MAAM,kBAAkB,4BACH,IAAI,KAAG,yBAAyB,CAAC,QAAQ,GAAG,UAAU,
|
|
1
|
+
{"version":3,"file":"afterChange.d.ts","sourceRoot":"","sources":["../../src/hooks/afterChange.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,gBAAgB,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAEhG,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAInD,UAAU,IAAI;IACZ,OAAO,EAAE,gBAAgB,CAAA;IACzB,UAAU,EAAE,gBAAgB,CAAA;CAC7B;AAED,eAAO,MAAM,kBAAkB,4BACH,IAAI,KAAG,yBAAyB,CAAC,QAAQ,GAAG,UAAU,CA0F/E,CAAA"}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { getIncomingFiles } from '../utilities/getIncomingFiles.js';
|
|
2
2
|
export const getAfterChangeHook = ({ adapter, collection })=>async ({ doc, operation, previousDoc, req })=>{
|
|
3
|
+
// Skip if this is an internal update to prevent infinite loop
|
|
4
|
+
if (req.context?.skipCloudStorage) {
|
|
5
|
+
return doc;
|
|
6
|
+
}
|
|
3
7
|
try {
|
|
4
8
|
const files = getIncomingFiles({
|
|
5
9
|
data: doc,
|
|
@@ -41,6 +45,10 @@ export const getAfterChangeHook = ({ adapter, collection })=>async ({ doc, opera
|
|
|
41
45
|
}), {});
|
|
42
46
|
if (Object.keys(uploadMetadata).length > 0) {
|
|
43
47
|
try {
|
|
48
|
+
if (!req.context) {
|
|
49
|
+
req.context = {};
|
|
50
|
+
}
|
|
51
|
+
req.context.skipCloudStorage = true;
|
|
44
52
|
await req.payload.update({
|
|
45
53
|
id: doc.id,
|
|
46
54
|
collection: collection.slug,
|
|
@@ -48,6 +56,7 @@ export const getAfterChangeHook = ({ adapter, collection })=>async ({ doc, opera
|
|
|
48
56
|
depth: 0,
|
|
49
57
|
req
|
|
50
58
|
});
|
|
59
|
+
delete req.context.skipCloudStorage;
|
|
51
60
|
return {
|
|
52
61
|
...doc,
|
|
53
62
|
...uploadMetadata
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hooks/afterChange.ts"],"sourcesContent":["import type { CollectionAfterChangeHook, CollectionConfig, FileData, TypeWithID } from 'payload'\n\nimport type { GeneratedAdapter } from '../types.js'\n\nimport { getIncomingFiles } from '../utilities/getIncomingFiles.js'\n\ninterface Args {\n adapter: GeneratedAdapter\n collection: CollectionConfig\n}\n\nexport const getAfterChangeHook =\n ({ adapter, collection }: Args): CollectionAfterChangeHook<FileData & TypeWithID> =>\n async ({ doc, operation, previousDoc, req }) => {\n try {\n const files = getIncomingFiles({ data: doc, req })\n\n if (files.length > 0) {\n // If there is a previous doc, files and the operation is update,\n // delete the old files before uploading the new ones.\n if (previousDoc && operation === 'update') {\n let filesToDelete: string[] = []\n\n if (typeof previousDoc?.filename === 'string') {\n filesToDelete.push(previousDoc.filename)\n }\n\n if (typeof previousDoc.sizes === 'object') {\n filesToDelete = filesToDelete.concat(\n Object.values(previousDoc?.sizes || []).map(\n (resizedFileData) => resizedFileData?.filename as string,\n ),\n )\n }\n\n const deletionPromises = filesToDelete.map(async (filename) => {\n if (filename) {\n await adapter.handleDelete({ collection, doc: previousDoc, filename, req })\n }\n })\n\n await Promise.all(deletionPromises)\n }\n\n const uploadResults = await Promise.all(\n files.map((file) =>\n adapter.handleUpload({\n clientUploadContext: file.clientUploadContext,\n collection,\n data: doc,\n file,\n req,\n }),\n ),\n )\n\n const uploadMetadata = uploadResults\n .filter(\n (result): result is Partial<FileData & TypeWithID> =>\n result != null && typeof result === 'object',\n )\n .reduce(\n (acc, metadata) => ({ ...acc, ...metadata }),\n {} as Partial<FileData & TypeWithID>,\n )\n\n if (Object.keys(uploadMetadata).length > 0) {\n try {\n await req.payload.update({\n id: doc.id,\n collection: collection.slug,\n data: uploadMetadata,\n depth: 0,\n req,\n })\n return { ...doc, ...uploadMetadata }\n } catch (updateError: unknown) {\n req.payload.logger.warn(\n `Failed to persist upload data for collection ${collection.slug} document ${doc.id}: ${String(updateError)}`,\n )\n }\n }\n }\n } catch (err: unknown) {\n req.payload.logger.error(\n `There was an error while uploading files corresponding to the collection ${collection.slug} with filename ${doc.filename}:`,\n )\n req.payload.logger.error({ err })\n throw err\n }\n return doc\n }\n"],"names":["getIncomingFiles","getAfterChangeHook","adapter","collection","doc","operation","previousDoc","req","files","data","length","filesToDelete","filename","push","sizes","concat","Object","values","map","resizedFileData","deletionPromises","handleDelete","Promise","all","uploadResults","file","handleUpload","clientUploadContext","uploadMetadata","filter","result","reduce","acc","metadata","keys","payload","update","id","slug","depth","updateError","logger","warn","String","err","error"],"mappings":"AAIA,SAASA,gBAAgB,QAAQ,mCAAkC;AAOnE,OAAO,MAAMC,qBACX,CAAC,EAAEC,OAAO,EAAEC,UAAU,EAAQ,GAC9B,OAAO,EAAEC,GAAG,EAAEC,SAAS,EAAEC,WAAW,EAAEC,GAAG,EAAE;QACzC,IAAI;YACF,
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/afterChange.ts"],"sourcesContent":["import type { CollectionAfterChangeHook, CollectionConfig, FileData, TypeWithID } from 'payload'\n\nimport type { GeneratedAdapter } from '../types.js'\n\nimport { getIncomingFiles } from '../utilities/getIncomingFiles.js'\n\ninterface Args {\n adapter: GeneratedAdapter\n collection: CollectionConfig\n}\n\nexport const getAfterChangeHook =\n ({ adapter, collection }: Args): CollectionAfterChangeHook<FileData & TypeWithID> =>\n async ({ doc, operation, previousDoc, req }) => {\n // Skip if this is an internal update to prevent infinite loop\n if (req.context?.skipCloudStorage) {\n return doc\n }\n\n try {\n const files = getIncomingFiles({ data: doc, req })\n\n if (files.length > 0) {\n // If there is a previous doc, files and the operation is update,\n // delete the old files before uploading the new ones.\n if (previousDoc && operation === 'update') {\n let filesToDelete: string[] = []\n\n if (typeof previousDoc?.filename === 'string') {\n filesToDelete.push(previousDoc.filename)\n }\n\n if (typeof previousDoc.sizes === 'object') {\n filesToDelete = filesToDelete.concat(\n Object.values(previousDoc?.sizes || []).map(\n (resizedFileData) => resizedFileData?.filename as string,\n ),\n )\n }\n\n const deletionPromises = filesToDelete.map(async (filename) => {\n if (filename) {\n await adapter.handleDelete({ collection, doc: previousDoc, filename, req })\n }\n })\n\n await Promise.all(deletionPromises)\n }\n\n const uploadResults = await Promise.all(\n files.map((file) =>\n adapter.handleUpload({\n clientUploadContext: file.clientUploadContext,\n collection,\n data: doc,\n file,\n req,\n }),\n ),\n )\n\n const uploadMetadata = uploadResults\n .filter(\n (result): result is Partial<FileData & TypeWithID> =>\n result != null && typeof result === 'object',\n )\n .reduce(\n (acc, metadata) => ({ ...acc, ...metadata }),\n {} as Partial<FileData & TypeWithID>,\n )\n\n if (Object.keys(uploadMetadata).length > 0) {\n try {\n if (!req.context) {\n req.context = {}\n }\n req.context.skipCloudStorage = true\n\n await req.payload.update({\n id: doc.id,\n collection: collection.slug,\n data: uploadMetadata,\n depth: 0,\n req,\n })\n delete req.context.skipCloudStorage\n return { ...doc, ...uploadMetadata }\n } catch (updateError: unknown) {\n req.payload.logger.warn(\n `Failed to persist upload data for collection ${collection.slug} document ${doc.id}: ${String(updateError)}`,\n )\n }\n }\n }\n } catch (err: unknown) {\n req.payload.logger.error(\n `There was an error while uploading files corresponding to the collection ${collection.slug} with filename ${doc.filename}:`,\n )\n req.payload.logger.error({ err })\n throw err\n }\n return doc\n }\n"],"names":["getIncomingFiles","getAfterChangeHook","adapter","collection","doc","operation","previousDoc","req","context","skipCloudStorage","files","data","length","filesToDelete","filename","push","sizes","concat","Object","values","map","resizedFileData","deletionPromises","handleDelete","Promise","all","uploadResults","file","handleUpload","clientUploadContext","uploadMetadata","filter","result","reduce","acc","metadata","keys","payload","update","id","slug","depth","updateError","logger","warn","String","err","error"],"mappings":"AAIA,SAASA,gBAAgB,QAAQ,mCAAkC;AAOnE,OAAO,MAAMC,qBACX,CAAC,EAAEC,OAAO,EAAEC,UAAU,EAAQ,GAC9B,OAAO,EAAEC,GAAG,EAAEC,SAAS,EAAEC,WAAW,EAAEC,GAAG,EAAE;QACzC,8DAA8D;QAC9D,IAAIA,IAAIC,OAAO,EAAEC,kBAAkB;YACjC,OAAOL;QACT;QAEA,IAAI;YACF,MAAMM,QAAQV,iBAAiB;gBAAEW,MAAMP;gBAAKG;YAAI;YAEhD,IAAIG,MAAME,MAAM,GAAG,GAAG;gBACpB,iEAAiE;gBACjE,sDAAsD;gBACtD,IAAIN,eAAeD,cAAc,UAAU;oBACzC,IAAIQ,gBAA0B,EAAE;oBAEhC,IAAI,OAAOP,aAAaQ,aAAa,UAAU;wBAC7CD,cAAcE,IAAI,CAACT,YAAYQ,QAAQ;oBACzC;oBAEA,IAAI,OAAOR,YAAYU,KAAK,KAAK,UAAU;wBACzCH,gBAAgBA,cAAcI,MAAM,CAClCC,OAAOC,MAAM,CAACb,aAAaU,SAAS,EAAE,EAAEI,GAAG,CACzC,CAACC,kBAAoBA,iBAAiBP;oBAG5C;oBAEA,MAAMQ,mBAAmBT,cAAcO,GAAG,CAAC,OAAON;wBAChD,IAAIA,UAAU;4BACZ,MAAMZ,QAAQqB,YAAY,CAAC;gCAAEpB;gCAAYC,K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,WAAWqC,IAAI,CAAC,eAAe,EAAEpC,IAAIU,QAAQ,CAAC,CAAC,CAAC;YAE9HP,IAAI8B,OAAO,CAACM,MAAM,CAACI,KAAK,CAAC;gBAAED;YAAI;YAC/B,MAAMA;QACR;QACA,OAAO1C;IACT,EAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/plugin-cloud-storage",
|
|
3
|
-
"version": "3.74.0
|
|
3
|
+
"version": "3.74.0",
|
|
4
4
|
"description": "The official cloud storage plugin for Payload CMS",
|
|
5
5
|
"homepage": "https://payloadcms.com",
|
|
6
6
|
"repository": {
|
|
@@ -51,18 +51,18 @@
|
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"find-node-modules": "^2.1.3",
|
|
53
53
|
"range-parser": "^1.2.1",
|
|
54
|
-
"@payloadcms/ui": "3.74.0
|
|
54
|
+
"@payloadcms/ui": "3.74.0"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@types/find-node-modules": "^2.1.2",
|
|
58
58
|
"@types/react": "19.2.9",
|
|
59
59
|
"@types/react-dom": "19.2.3",
|
|
60
|
-
"payload": "3.74.0
|
|
60
|
+
"payload": "3.74.0"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
63
|
"react": "^19.0.1 || ^19.1.2 || ^19.2.1",
|
|
64
64
|
"react-dom": "^19.0.1 || ^19.1.2 || ^19.2.1",
|
|
65
|
-
"payload": "3.74.0
|
|
65
|
+
"payload": "3.74.0"
|
|
66
66
|
},
|
|
67
67
|
"publishConfig": {
|
|
68
68
|
"registry": "https://registry.npmjs.org/"
|