@payloadcms/plugin-cloud-storage 4.0.0-internal.d28e9fb → 4.0.0-internal.e16cf59
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,CAsG/E,CAAA"}
|
|
@@ -10,28 +10,6 @@ export const getAfterChangeHook = ({ adapter, collection })=>async ({ doc, opera
|
|
|
10
10
|
req
|
|
11
11
|
});
|
|
12
12
|
if (files.length > 0) {
|
|
13
|
-
// If there is a previous doc, files and the operation is update,
|
|
14
|
-
// delete the old files before uploading the new ones.
|
|
15
|
-
if (previousDoc && operation === 'update') {
|
|
16
|
-
let filesToDelete = [];
|
|
17
|
-
if (typeof previousDoc?.filename === 'string') {
|
|
18
|
-
filesToDelete.push(previousDoc.filename);
|
|
19
|
-
}
|
|
20
|
-
if (typeof previousDoc.sizes === 'object') {
|
|
21
|
-
filesToDelete = filesToDelete.concat(Object.values(previousDoc?.sizes || []).map((resizedFileData)=>resizedFileData?.filename));
|
|
22
|
-
}
|
|
23
|
-
const deletionPromises = filesToDelete.map(async (filename)=>{
|
|
24
|
-
if (filename) {
|
|
25
|
-
await adapter.handleDelete({
|
|
26
|
-
collection,
|
|
27
|
-
doc: previousDoc,
|
|
28
|
-
filename,
|
|
29
|
-
req
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
await Promise.all(deletionPromises);
|
|
34
|
-
}
|
|
35
13
|
const uploadResults = await Promise.all(files.filter((file)=>!file.clientUploadContext).map((file)=>adapter.handleUpload({
|
|
36
14
|
clientUploadContext: file.clientUploadContext,
|
|
37
15
|
collection,
|
|
@@ -43,15 +21,16 @@ export const getAfterChangeHook = ({ adapter, collection })=>async ({ doc, opera
|
|
|
43
21
|
...acc,
|
|
44
22
|
...metadata
|
|
45
23
|
}), {});
|
|
24
|
+
let docWithMetadata = doc;
|
|
46
25
|
if (Object.keys(uploadMetadata).length > 0) {
|
|
26
|
+
if (!req.context) {
|
|
27
|
+
req.context = {};
|
|
28
|
+
}
|
|
29
|
+
req.context.skipCloudStorage = true;
|
|
30
|
+
// Clear to prevent re-processing
|
|
31
|
+
req.file = undefined;
|
|
32
|
+
req.payloadUploadSizes = undefined;
|
|
47
33
|
try {
|
|
48
|
-
if (!req.context) {
|
|
49
|
-
req.context = {};
|
|
50
|
-
}
|
|
51
|
-
req.context.skipCloudStorage = true;
|
|
52
|
-
// Clear to prevent re-processing
|
|
53
|
-
req.file = undefined;
|
|
54
|
-
req.payloadUploadSizes = undefined;
|
|
55
34
|
await req.payload.update({
|
|
56
35
|
id: doc.id,
|
|
57
36
|
collection: collection.slug,
|
|
@@ -59,14 +38,40 @@ export const getAfterChangeHook = ({ adapter, collection })=>async ({ doc, opera
|
|
|
59
38
|
depth: 0,
|
|
60
39
|
req
|
|
61
40
|
});
|
|
41
|
+
} finally{
|
|
62
42
|
delete req.context.skipCloudStorage;
|
|
63
|
-
return {
|
|
64
|
-
...doc,
|
|
65
|
-
...uploadMetadata
|
|
66
|
-
};
|
|
67
|
-
} catch (updateError) {
|
|
68
|
-
req.payload.logger.warn(`Failed to persist upload data for collection ${collection.slug} document ${doc.id}: ${String(updateError)}`);
|
|
69
43
|
}
|
|
44
|
+
docWithMetadata = {
|
|
45
|
+
...doc,
|
|
46
|
+
...uploadMetadata
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
// Delete previous files only after the new upload and metadata
|
|
50
|
+
// persistence have succeeded. Deleting earlier would orphan the
|
|
51
|
+
// record if a later step throws (e.g. a user-defined afterChange
|
|
52
|
+
// hook on the same collection).
|
|
53
|
+
if (previousDoc && operation === 'update') {
|
|
54
|
+
let filesToDelete = [];
|
|
55
|
+
if (typeof previousDoc?.filename === 'string') {
|
|
56
|
+
filesToDelete.push(previousDoc.filename);
|
|
57
|
+
}
|
|
58
|
+
if (typeof previousDoc.sizes === 'object') {
|
|
59
|
+
filesToDelete = filesToDelete.concat(Object.values(previousDoc?.sizes || []).map((resizedFileData)=>resizedFileData?.filename));
|
|
60
|
+
}
|
|
61
|
+
const deletionPromises = filesToDelete.map(async (filename)=>{
|
|
62
|
+
if (filename && filename !== docWithMetadata.filename) {
|
|
63
|
+
await adapter.handleDelete({
|
|
64
|
+
collection,
|
|
65
|
+
doc: previousDoc,
|
|
66
|
+
filename,
|
|
67
|
+
req
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
await Promise.all(deletionPromises);
|
|
72
|
+
}
|
|
73
|
+
if (docWithMetadata !== doc) {
|
|
74
|
+
return docWithMetadata;
|
|
70
75
|
}
|
|
71
76
|
}
|
|
72
77
|
} catch (err) {
|
|
@@ -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 // 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
|
|
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 const uploadResults = await Promise.all(\n files\n .filter((file) => !file.clientUploadContext)\n .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 let docWithMetadata = doc\n\n if (Object.keys(uploadMetadata).length > 0) {\n if (!req.context) {\n req.context = {}\n }\n req.context.skipCloudStorage = true\n\n // Clear to prevent re-processing\n req.file = undefined\n req.payloadUploadSizes = undefined\n\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 } finally {\n delete req.context.skipCloudStorage\n }\n\n docWithMetadata = { ...doc, ...uploadMetadata }\n }\n\n // Delete previous files only after the new upload and metadata\n // persistence have succeeded. Deleting earlier would orphan the\n // record if a later step throws (e.g. a user-defined afterChange\n // hook on the same collection).\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 && filename !== docWithMetadata.filename) {\n await adapter.handleDelete({ collection, doc: previousDoc, filename, req })\n }\n })\n\n await Promise.all(deletionPromises)\n }\n\n if (docWithMetadata !== doc) {\n return docWithMetadata\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","uploadResults","Promise","all","filter","file","clientUploadContext","map","handleUpload","uploadMetadata","result","reduce","acc","metadata","docWithMetadata","Object","keys","undefined","payloadUploadSizes","payload","update","id","slug","depth","filesToDelete","filename","push","sizes","concat","values","resizedFileData","deletionPromises","handleDelete","err","logger","error"],"mappings":"AAIA,SAASA,gBAAgB,QAAQ,mCAAkC;AAOnE,OAAO,MAAMC,qBACX,CAAC,EAAEC,OAAO,EAAEC,UAAU,EAAQ,GAC9B,OAAO,EAAEC,GAAG,EAAEC,SAAS,EAAEC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;gBAEA,+DAA+D;gBAC/D,gEAAgE;gBAChE,iEAAiE;gBACjE,gCAAgC;gBAChC,IAAIf,eAAeD,cAAc,UAAU;oBACzC,IAAI+B,gBAA0B,EAAE;oBAEhC,IAAI,OAAO9B,aAAa+B,aAAa,UAAU;wBAC7CD,cAAcE,IAAI,CAAChC,YAAY+B,QAAQ;oBACzC;oBAEA,IAAI,OAAO/B,YAAYiC,KAAK,KAAK,UAAU;wBACzCH,gBAAgBA,cAAcI,MAAM,CAClCb,OAAOc,MAAM,CAACnC,aAAaiC,SAAS,EAAE,EAAEpB,GAAG,CACzC,CAACuB,kBAAoBA,iBAAiBL;oBAG5C;oBAEA,MAAMM,mBAAmBP,cAAcjB,GAAG,CAAC,OAAOkB;wBAChD,IAAIA,YAAYA,aAAaX,gBAAgBW,QAAQ,EAAE;4BACrD,MAAMnC,QAAQ0C,YAAY,CAAC;gCAAEzC;gCAAYC,KAAKE;gCAAa+B;gCAAU9B;4BAAI;wBAC3E;oBACF;oBAEA,MAAMO,QAAQC,GAAG,CAAC4B;gBACpB;gBAEA,IAAIjB,oBAAoBtB,KAAK;oBAC3B,OAAOsB;gBACT;YACF;QACF,EAAE,OAAOmB,KAAc;YACrBtC,IAAIwB,OAAO,CAACe,MAAM,CAACC,KAAK,CACtB,CAAC,yEAAyE,EAAE5C,WAAW+B,IAAI,CAAC,eAAe,EAAE9B,IAAIiC,QAAQ,CAAC,CAAC,CAAC;YAE9H9B,IAAIwB,OAAO,CAACe,MAAM,CAACC,KAAK,CAAC;gBAAEF;YAAI;YAC/B,MAAMA;QACR;QACA,OAAOzC;IACT,EAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/plugin-cloud-storage",
|
|
3
|
-
"version": "4.0.0-internal.
|
|
3
|
+
"version": "4.0.0-internal.e16cf59",
|
|
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": "4.0.0-internal.
|
|
54
|
+
"@payloadcms/ui": "4.0.0-internal.e16cf59"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@types/find-node-modules": "^2.1.2",
|
|
58
58
|
"@types/react": "19.2.14",
|
|
59
59
|
"@types/react-dom": "19.2.3",
|
|
60
|
-
"payload": "4.0.0-internal.
|
|
60
|
+
"payload": "4.0.0-internal.e16cf59"
|
|
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": "4.0.0-internal.
|
|
65
|
+
"payload": "4.0.0-internal.e16cf59"
|
|
66
66
|
},
|
|
67
67
|
"publishConfig": {
|
|
68
68
|
"registry": "https://registry.npmjs.org/"
|