@payloadcms/plugin-cloud-storage 3.0.0-beta.29 → 3.0.0-beta.30
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/fields/getFields.d.ts.map +1 -1
- package/dist/fields/getFields.js +3 -1
- package/dist/fields/getFields.js.map +1 -1
- package/dist/hooks/afterRead.d.ts.map +1 -1
- package/dist/hooks/afterRead.js +1 -0
- package/dist/hooks/afterRead.js.map +1 -1
- package/dist/hooks/beforeChange.d.ts.map +1 -1
- package/dist/hooks/beforeChange.js +4 -1
- package/dist/hooks/beforeChange.js.map +1 -1
- package/dist/types.d.ts +11 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getFields.d.ts","sourceRoot":"","sources":["../../src/fields/getFields.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AAI5D,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAIpE,UAAU,IAAI;IACZ,OAAO,EAAE,gBAAgB,CAAA;IACzB,UAAU,EAAE,gBAAgB,CAAA;IAC5B,2BAA2B,CAAC,EAAE,IAAI,CAAA;IAClC,eAAe,CAAC,EAAE,eAAe,CAAA;IACjC,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,eAAO,MAAM,SAAS,mFAMnB,IAAI,KAAG,KAAK,
|
|
1
|
+
{"version":3,"file":"getFields.d.ts","sourceRoot":"","sources":["../../src/fields/getFields.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AAI5D,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAIpE,UAAU,IAAI;IACZ,OAAO,EAAE,gBAAgB,CAAA;IACzB,UAAU,EAAE,gBAAgB,CAAA;IAC5B,2BAA2B,CAAC,EAAE,IAAI,CAAA;IAClC,eAAe,CAAC,EAAE,eAAe,CAAA;IACjC,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,eAAO,MAAM,SAAS,mFAMnB,IAAI,KAAG,KAAK,EAuId,CAAA"}
|
package/dist/fields/getFields.js
CHANGED
|
@@ -19,7 +19,8 @@ export const getFields = ({ adapter, collection, disablePayloadAccessControl, ge
|
|
|
19
19
|
}
|
|
20
20
|
};
|
|
21
21
|
const fields = [
|
|
22
|
-
...collection.fields
|
|
22
|
+
...collection.fields,
|
|
23
|
+
...adapter.fields || []
|
|
23
24
|
];
|
|
24
25
|
// Inject a hook into all URL fields to generate URLs
|
|
25
26
|
let existingURLFieldIndex = -1;
|
|
@@ -75,6 +76,7 @@ export const getFields = ({ adapter, collection, disablePayloadAccessControl, ge
|
|
|
75
76
|
name: size.name,
|
|
76
77
|
type: 'group',
|
|
77
78
|
fields: [
|
|
79
|
+
...adapter.fields || [],
|
|
78
80
|
{
|
|
79
81
|
...existingSizeURLField || {},
|
|
80
82
|
...baseURLField,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/fields/getFields.ts"],"sourcesContent":["import type { GroupField, TextField } from 'payload/types'\nimport type { CollectionConfig, Field } from 'payload/types'\n\nimport path from 'path'\n\nimport type { GenerateFileURL, GeneratedAdapter } from '../types.js'\n\nimport { getAfterReadHook } from '../hooks/afterRead.js'\n\ninterface Args {\n adapter: GeneratedAdapter\n collection: CollectionConfig\n disablePayloadAccessControl?: true\n generateFileURL?: GenerateFileURL\n prefix?: string\n}\n\nexport const getFields = ({\n adapter,\n collection,\n disablePayloadAccessControl,\n generateFileURL,\n prefix,\n}: Args): Field[] => {\n const baseURLField: Field = {\n name: 'url',\n type: 'text',\n admin: {\n hidden: true,\n readOnly: true,\n },\n label: 'URL',\n }\n\n const basePrefixField: Field = {\n name: 'prefix',\n type: 'text',\n admin: {\n hidden: true,\n readOnly: true,\n },\n }\n\n const fields = [...collection.fields]\n\n // Inject a hook into all URL fields to generate URLs\n\n let existingURLFieldIndex = -1\n\n const existingURLField = fields.find((existingField, i) => {\n if ('name' in existingField && existingField.name === 'url') {\n existingURLFieldIndex = i\n return true\n }\n return false\n }) as TextField\n\n if (existingURLFieldIndex > -1) {\n fields.splice(existingURLFieldIndex, 1)\n }\n\n fields.push({\n ...baseURLField,\n ...(existingURLField || {}),\n hooks: {\n afterRead: [\n getAfterReadHook({ adapter, collection, disablePayloadAccessControl, generateFileURL }),\n ...(existingURLField?.hooks?.afterRead || []),\n ],\n },\n })\n\n if (typeof collection.upload === 'object' && collection.upload.imageSizes) {\n let existingSizesFieldIndex = -1\n\n const existingSizesField = fields.find((existingField, i) => {\n if ('name' in existingField && existingField.name === 'sizes') {\n existingSizesFieldIndex = i\n return true\n }\n\n return false\n }) as GroupField\n\n if (existingSizesFieldIndex > -1) {\n fields.splice(existingSizesFieldIndex, 1)\n }\n\n const sizesField: Field = {\n ...(existingSizesField || {}),\n name: 'sizes',\n type: 'group',\n admin: {\n hidden: true,\n },\n fields: collection.upload.imageSizes.map((size) => {\n const existingSizeField = existingSizesField?.fields.find(\n (existingField) => 'name' in existingField && existingField.name === size.name,\n ) as GroupField\n\n const existingSizeURLField = existingSizeField?.fields.find(\n (existingField) => 'name' in existingField && existingField.name === 'url',\n ) as GroupField\n\n return {\n ...existingSizeField,\n name: size.name,\n type: 'group',\n fields: [\n {\n ...(existingSizeURLField || {}),\n ...baseURLField,\n hooks: {\n afterRead: [\n getAfterReadHook({\n adapter,\n collection,\n disablePayloadAccessControl,\n generateFileURL,\n size,\n }),\n ...(existingSizeURLField?.hooks?.afterRead || []),\n ],\n },\n },\n ],\n }\n }),\n }\n\n fields.push(sizesField)\n }\n\n // If prefix is enabled, save it to db\n if (typeof prefix !== 'undefined') {\n let existingPrefixFieldIndex = -1\n\n const existingPrefixField = fields.find((existingField, i) => {\n if ('name' in existingField && existingField.name === 'prefix') {\n existingPrefixFieldIndex = i\n return true\n }\n return false\n }) as TextField\n\n if (existingPrefixFieldIndex > -1) {\n fields.splice(existingPrefixFieldIndex, 1)\n }\n\n fields.push({\n ...basePrefixField,\n ...(existingPrefixField || {}),\n defaultValue: path.posix.join(prefix),\n })\n }\n\n return fields\n}\n"],"names":["path","getAfterReadHook","getFields","adapter","collection","disablePayloadAccessControl","generateFileURL","prefix","baseURLField","name","type","admin","hidden","readOnly","label","basePrefixField","fields","existingURLFieldIndex","existingURLField","find","existingField","i","splice","push","hooks","afterRead","upload","imageSizes","existingSizesFieldIndex","existingSizesField","sizesField","map","size","existingSizeField","existingSizeURLField","existingPrefixFieldIndex","existingPrefixField","defaultValue","posix","join"],"rangeMappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/fields/getFields.ts"],"sourcesContent":["import type { GroupField, TextField } from 'payload/types'\nimport type { CollectionConfig, Field } from 'payload/types'\n\nimport path from 'path'\n\nimport type { GenerateFileURL, GeneratedAdapter } from '../types.js'\n\nimport { getAfterReadHook } from '../hooks/afterRead.js'\n\ninterface Args {\n adapter: GeneratedAdapter\n collection: CollectionConfig\n disablePayloadAccessControl?: true\n generateFileURL?: GenerateFileURL\n prefix?: string\n}\n\nexport const getFields = ({\n adapter,\n collection,\n disablePayloadAccessControl,\n generateFileURL,\n prefix,\n}: Args): Field[] => {\n const baseURLField: Field = {\n name: 'url',\n type: 'text',\n admin: {\n hidden: true,\n readOnly: true,\n },\n label: 'URL',\n }\n\n const basePrefixField: Field = {\n name: 'prefix',\n type: 'text',\n admin: {\n hidden: true,\n readOnly: true,\n },\n }\n\n const fields = [...collection.fields, ...(adapter.fields || [])]\n\n // Inject a hook into all URL fields to generate URLs\n\n let existingURLFieldIndex = -1\n\n const existingURLField = fields.find((existingField, i) => {\n if ('name' in existingField && existingField.name === 'url') {\n existingURLFieldIndex = i\n return true\n }\n return false\n }) as TextField\n\n if (existingURLFieldIndex > -1) {\n fields.splice(existingURLFieldIndex, 1)\n }\n\n fields.push({\n ...baseURLField,\n ...(existingURLField || {}),\n hooks: {\n afterRead: [\n getAfterReadHook({ adapter, collection, disablePayloadAccessControl, generateFileURL }),\n ...(existingURLField?.hooks?.afterRead || []),\n ],\n },\n })\n\n if (typeof collection.upload === 'object' && collection.upload.imageSizes) {\n let existingSizesFieldIndex = -1\n\n const existingSizesField = fields.find((existingField, i) => {\n if ('name' in existingField && existingField.name === 'sizes') {\n existingSizesFieldIndex = i\n return true\n }\n\n return false\n }) as GroupField\n\n if (existingSizesFieldIndex > -1) {\n fields.splice(existingSizesFieldIndex, 1)\n }\n\n const sizesField: Field = {\n ...(existingSizesField || {}),\n name: 'sizes',\n type: 'group',\n admin: {\n hidden: true,\n },\n fields: collection.upload.imageSizes.map((size) => {\n const existingSizeField = existingSizesField?.fields.find(\n (existingField) => 'name' in existingField && existingField.name === size.name,\n ) as GroupField\n\n const existingSizeURLField = existingSizeField?.fields.find(\n (existingField) => 'name' in existingField && existingField.name === 'url',\n ) as GroupField\n\n return {\n ...existingSizeField,\n name: size.name,\n type: 'group',\n fields: [\n ...(adapter.fields || []),\n {\n ...(existingSizeURLField || {}),\n ...baseURLField,\n hooks: {\n afterRead: [\n getAfterReadHook({\n adapter,\n collection,\n disablePayloadAccessControl,\n generateFileURL,\n size,\n }),\n ...(existingSizeURLField?.hooks?.afterRead || []),\n ],\n },\n },\n ],\n }\n }),\n }\n\n fields.push(sizesField)\n }\n\n // If prefix is enabled, save it to db\n if (typeof prefix !== 'undefined') {\n let existingPrefixFieldIndex = -1\n\n const existingPrefixField = fields.find((existingField, i) => {\n if ('name' in existingField && existingField.name === 'prefix') {\n existingPrefixFieldIndex = i\n return true\n }\n return false\n }) as TextField\n\n if (existingPrefixFieldIndex > -1) {\n fields.splice(existingPrefixFieldIndex, 1)\n }\n\n fields.push({\n ...basePrefixField,\n ...(existingPrefixField || {}),\n defaultValue: path.posix.join(prefix),\n })\n }\n\n return fields\n}\n"],"names":["path","getAfterReadHook","getFields","adapter","collection","disablePayloadAccessControl","generateFileURL","prefix","baseURLField","name","type","admin","hidden","readOnly","label","basePrefixField","fields","existingURLFieldIndex","existingURLField","find","existingField","i","splice","push","hooks","afterRead","upload","imageSizes","existingSizesFieldIndex","existingSizesField","sizesField","map","size","existingSizeField","existingSizeURLField","existingPrefixFieldIndex","existingPrefixField","defaultValue","posix","join"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAGA,OAAOA,UAAU,OAAM;AAIvB,SAASC,gBAAgB,QAAQ,wBAAuB;AAUxD,OAAO,MAAMC,YAAY,CAAC,EACxBC,OAAO,EACPC,UAAU,EACVC,2BAA2B,EAC3BC,eAAe,EACfC,MAAM,EACD;IACL,MAAMC,eAAsB;QAC1BC,MAAM;QACNC,MAAM;QACNC,OAAO;YACLC,QAAQ;YACRC,UAAU;QACZ;QACAC,OAAO;IACT;IAEA,MAAMC,kBAAyB;QAC7BN,MAAM;QACNC,MAAM;QACNC,OAAO;YACLC,QAAQ;YACRC,UAAU;QACZ;IACF;IAEA,MAAMG,SAAS;WAAIZ,WAAWY,MAAM;WAAMb,QAAQa,MAAM,IAAI,EAAE;KAAE;IAEhE,qDAAqD;IAErD,IAAIC,wBAAwB,CAAC;IAE7B,MAAMC,mBAAmBF,OAAOG,IAAI,CAAC,CAACC,eAAeC;QACnD,IAAI,UAAUD,iBAAiBA,cAAcX,IAAI,KAAK,OAAO;YAC3DQ,wBAAwBI;YACxB,OAAO;QACT;QACA,OAAO;IACT;IAEA,IAAIJ,wBAAwB,CAAC,GAAG;QAC9BD,OAAOM,MAAM,CAACL,uBAAuB;IACvC;IAEAD,OAAOO,IAAI,CAAC;QACV,GAAGf,YAAY;QACf,GAAIU,oBAAoB,CAAC,CAAC;QAC1BM,OAAO;YACLC,WAAW;gB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AI,CAACO;IACd;IAEA,sCAAsC;IACtC,IAAI,OAAOvB,WAAW,aAAa;QACjC,IAAI4B,2BAA2B,CAAC;QAEhC,MAAMC,sBAAsBpB,OAAOG,IAAI,CAAC,CAACC,eAAeC;YACtD,IAAI,UAAUD,iBAAiBA,cAAcX,IAAI,KAAK,UAAU;gBAC9D0B,2BAA2Bd;gBAC3B,OAAO;YACT;YACA,OAAO;QACT;QAEA,IAAIc,2BAA2B,CAAC,GAAG;YACjCnB,OAAOM,MAAM,CAACa,0BAA0B;QAC1C;QAEAnB,OAAOO,IAAI,CAAC;YACV,GAAGR,eAAe;YAClB,GAAIqB,uBAAuB,CAAC,CAAC;YAC7BC,cAAcrC,KAAKsC,KAAK,CAACC,IAAI,CAAChC;QAChC;IACF;IAEA,OAAOS;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"afterRead.d.ts","sourceRoot":"","sources":["../../src/hooks/afterRead.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAE3E,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAEpE,UAAU,IAAI;IACZ,OAAO,EAAE,gBAAgB,CAAA;IACzB,UAAU,EAAE,gBAAgB,CAAA;IAC5B,2BAA2B,CAAC,EAAE,OAAO,CAAA;IACrC,eAAe,CAAC,EAAE,eAAe,CAAA;IACjC,IAAI,CAAC,EAAE,SAAS,CAAA;CACjB;AAED,eAAO,MAAM,gBAAgB,gFACmD,IAAI,KAAG,
|
|
1
|
+
{"version":3,"file":"afterRead.d.ts","sourceRoot":"","sources":["../../src/hooks/afterRead.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAE3E,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAEpE,UAAU,IAAI;IACZ,OAAO,EAAE,gBAAgB,CAAA;IACzB,UAAU,EAAE,gBAAgB,CAAA;IAC5B,2BAA2B,CAAC,EAAE,OAAO,CAAA;IACrC,eAAe,CAAC,EAAE,eAAe,CAAA;IACjC,IAAI,CAAC,EAAE,SAAS,CAAA;CACjB;AAED,eAAO,MAAM,gBAAgB,gFACmD,IAAI,KAAG,SAyBpF,CAAA"}
|
package/dist/hooks/afterRead.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hooks/afterRead.ts"],"sourcesContent":["import type { CollectionConfig, FieldHook, ImageSize } from 'payload/types'\n\nimport type { GenerateFileURL, GeneratedAdapter } from '../types.js'\n\ninterface Args {\n adapter: GeneratedAdapter\n collection: CollectionConfig\n disablePayloadAccessControl?: boolean\n generateFileURL?: GenerateFileURL\n size?: ImageSize\n}\n\nexport const getAfterReadHook =\n ({ adapter, collection, disablePayloadAccessControl, generateFileURL, size }: Args): FieldHook =>\n async ({ data, value }) => {\n const filename = size ? data?.sizes?.[size.name]?.filename : data?.filename\n const prefix = data?.prefix\n let url = value\n\n if (disablePayloadAccessControl && filename) {\n url = await adapter.generateURL({\n collection,\n filename,\n prefix,\n })\n }\n\n if (generateFileURL) {\n url = await generateFileURL({\n collection,\n filename,\n prefix,\n size,\n })\n }\n\n return url\n }\n"],"names":["getAfterReadHook","adapter","collection","disablePayloadAccessControl","generateFileURL","size","data","value","filename","sizes","name","prefix","url","generateURL"],"rangeMappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/afterRead.ts"],"sourcesContent":["import type { CollectionConfig, FieldHook, ImageSize } from 'payload/types'\n\nimport type { GenerateFileURL, GeneratedAdapter } from '../types.js'\n\ninterface Args {\n adapter: GeneratedAdapter\n collection: CollectionConfig\n disablePayloadAccessControl?: boolean\n generateFileURL?: GenerateFileURL\n size?: ImageSize\n}\n\nexport const getAfterReadHook =\n ({ adapter, collection, disablePayloadAccessControl, generateFileURL, size }: Args): FieldHook =>\n async ({ data, value }) => {\n const filename = size ? data?.sizes?.[size.name]?.filename : data?.filename\n const prefix = data?.prefix\n let url = value\n\n if (disablePayloadAccessControl && filename) {\n url = await adapter.generateURL({\n collection,\n data,\n filename,\n prefix,\n })\n }\n\n if (generateFileURL) {\n url = await generateFileURL({\n collection,\n filename,\n prefix,\n size,\n })\n }\n\n return url\n }\n"],"names":["getAfterReadHook","adapter","collection","disablePayloadAccessControl","generateFileURL","size","data","value","filename","sizes","name","prefix","url","generateURL"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;","mappings":"AAYA,OAAO,MAAMA,mBACX,CAAC,EAAEC,OAAO,EAAEC,UAAU,EAAEC,2BAA2B,EAAEC,eAAe,EAAEC,IAAI,EAAQ,GAClF,OAAO,EAAEC,IAAI,EAAEC,KAAK,EAAE;QACpB,MAAMC,WAAWH,OAAOC,MAAMG,OAAO,CAACJ,KAAKK,IAAI,CAAC,EAAEF,WAAWF,MAAME;QACnE,MAAMG,SAASL,MAAMK;QACrB,IAAIC,MAAML;QAEV,IAAIJ,+BAA+BK,UAAU;YAC3CI,MAAM,MAAMX,QAAQY,WAAW,CAAC;gBAC9BX;gBACAI;gBACAE;gBACAG;YACF;QACF;QAEA,IAAIP,iBAAiB;YACnBQ,MAAM,MAAMR,gBAAgB;gBAC1BF;gBACAM;gBACAG;gBACAN;YACF;QACF;QAEA,OAAOO;IACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"beforeChange.d.ts","sourceRoot":"","sources":["../../src/hooks/beforeChange.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AACzD,OAAO,KAAK,EAAE,0BAA0B,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAEjF,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,mBAAmB,4BACJ,IAAI,KAAG,2BAA2B,QAAQ,GAAG,UAAU,
|
|
1
|
+
{"version":3,"file":"beforeChange.d.ts","sourceRoot":"","sources":["../../src/hooks/beforeChange.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AACzD,OAAO,KAAK,EAAE,0BAA0B,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAEjF,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,mBAAmB,4BACJ,IAAI,KAAG,2BAA2B,QAAQ,GAAG,UAAU,CA+ChF,CAAA"}
|
|
@@ -41,7 +41,10 @@ export const getBeforeChangeHook = ({ adapter, collection })=>async ({ data, ori
|
|
|
41
41
|
}
|
|
42
42
|
} catch (err) {
|
|
43
43
|
req.payload.logger.error(`There was an error while uploading files corresponding to the collection ${collection.slug} with filename ${data.filename}:`);
|
|
44
|
-
req.payload.logger.error(
|
|
44
|
+
req.payload.logger.error({
|
|
45
|
+
err
|
|
46
|
+
});
|
|
47
|
+
throw err;
|
|
45
48
|
}
|
|
46
49
|
return data;
|
|
47
50
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hooks/beforeChange.ts"],"sourcesContent":["import type { FileData, TypeWithID } from 'payload/types'\nimport type { CollectionBeforeChangeHook, CollectionConfig } from 'payload/types'\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 getBeforeChangeHook =\n ({ adapter, collection }: Args): CollectionBeforeChangeHook<FileData & TypeWithID> =>\n async ({ data, originalDoc, req }) => {\n try {\n const files = getIncomingFiles({ data, req })\n\n if (files.length > 0) {\n // If there is an original doc,\n // And we have new files,\n // We need to delete the old files before uploading new\n if (originalDoc) {\n let filesToDelete: string[] = []\n\n if (typeof originalDoc?.filename === 'string') {\n filesToDelete.push(originalDoc.filename)\n }\n\n if (typeof originalDoc.sizes === 'object') {\n filesToDelete = filesToDelete.concat(\n Object.values(originalDoc?.sizes || []).map(\n (resizedFileData) => resizedFileData?.filename,\n ),\n )\n }\n\n const deletionPromises = filesToDelete.map(async (filename) => {\n if (filename) {\n await adapter.handleDelete({ collection, doc: originalDoc, filename, req })\n }\n })\n\n await Promise.all(deletionPromises)\n }\n\n const promises = files.map(async (file) => {\n await adapter.handleUpload({ collection, data, file, req })\n })\n\n await Promise.all(promises)\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 ${data.filename}:`,\n )\n req.payload.logger.error(err)\n }\n return data\n }\n"],"names":["getIncomingFiles","getBeforeChangeHook","adapter","collection","data","originalDoc","req","files","length","filesToDelete","filename","push","sizes","concat","Object","values","map","resizedFileData","deletionPromises","handleDelete","doc","Promise","all","promises","file","handleUpload","err","payload","logger","error","slug"],"rangeMappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/beforeChange.ts"],"sourcesContent":["import type { FileData, TypeWithID } from 'payload/types'\nimport type { CollectionBeforeChangeHook, CollectionConfig } from 'payload/types'\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 getBeforeChangeHook =\n ({ adapter, collection }: Args): CollectionBeforeChangeHook<FileData & TypeWithID> =>\n async ({ data, originalDoc, req }) => {\n try {\n const files = getIncomingFiles({ data, req })\n\n if (files.length > 0) {\n // If there is an original doc,\n // And we have new files,\n // We need to delete the old files before uploading new\n if (originalDoc) {\n let filesToDelete: string[] = []\n\n if (typeof originalDoc?.filename === 'string') {\n filesToDelete.push(originalDoc.filename)\n }\n\n if (typeof originalDoc.sizes === 'object') {\n filesToDelete = filesToDelete.concat(\n Object.values(originalDoc?.sizes || []).map(\n (resizedFileData) => resizedFileData?.filename,\n ),\n )\n }\n\n const deletionPromises = filesToDelete.map(async (filename) => {\n if (filename) {\n await adapter.handleDelete({ collection, doc: originalDoc, filename, req })\n }\n })\n\n await Promise.all(deletionPromises)\n }\n\n const promises = files.map(async (file) => {\n await adapter.handleUpload({ collection, data, file, req })\n })\n\n await Promise.all(promises)\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 ${data.filename}:`,\n )\n req.payload.logger.error({ err })\n throw err\n }\n return data\n }\n"],"names":["getIncomingFiles","getBeforeChangeHook","adapter","collection","data","originalDoc","req","files","length","filesToDelete","filename","push","sizes","concat","Object","values","map","resizedFileData","deletionPromises","handleDelete","doc","Promise","all","promises","file","handleUpload","err","payload","logger","error","slug"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAKA,SAASA,gBAAgB,QAAQ,mCAAkC;AAOnE,OAAO,MAAMC,sBACX,CAAC,EAAEC,OAAO,EAAEC,UAAU,EAAQ,GAC9B,OAAO,EAAEC,IAAI,EAAEC,WAAW,EAAEC,GAAG,EAAE;QAC/B,IAAI;YACF,MAAMC,QAAQP,iBAAiB;gBAAEI;gBAAME;YAAI;YAE3C,IAAIC,MAAMC,MAAM,GAAG,GAAG;gBACpB,+BAA+B;gBAC/B,yBAAyB;gBACzB,uDAAuD;gBACvD,IAAIH,aAAa;oBACf,IAAII,gBAA0B,EAAE;oBAEhC,IAAI,OAAOJ,aAAaK,aAAa,UAAU;wBAC7CD,cAAcE,IAAI,CAACN,YAAYK,QAAQ;oBACzC;oBAEA,IAAI,OAAOL,YAAYO,KAAK,KAAK,UAAU;wBACzCH,gBAAgBA,cAAcI,MAAM,CAClCC,OAAOC,MAAM,CAACV,aAAaO,SAAS,EAAE,EAAEI,GAAG,CACzC,CAACC,kBAAoBA,iBAAiBP;oBAG5C;oBAEA,MAAMQ,mBAAmBT,cAAcO,GAAG,CAAC,OAAON;wBAChD,IAAIA,UAAU;4BACZ,MAAMR,QAAQiB,YAAY,CAAC;gCAAEhB;gCAAYiB,KAAKf;gCAAaK;gCAAUJ;4BAAI;wBAC3E;oBACF;oBAEA,MAAMe,QAAQC,GAAG,CAACJ;gBACpB;gBAEA,MAAMK,WAAWhB,MAAMS,GAAG,CAAC,OAAOQ;oBAChC,MAAMtB,QAAQuB,YAAY,CAAC;wBAAEtB;wBAAYC;wBAAMoB;wBAAMlB;oBAAI;gBAC3D;gBAEA,MAAMe,QAAQC,GAAG,CAACC;YACpB;QACF,EAAE,OAAOG,KAAc;YACrBpB,IAAIqB,OAAO,CAACC,MAAM,CAACC,KAAK,CACtB,CAAC,yEAAyE,EAAE1B,WAAW2B,IAAI,CAAC,eAAe,EAAE1B,KAAKM,QAAQ,CAAC,CAAC,CAAC;YAE/HJ,IAAIqB,OAAO,CAACC,MAAM,CAACC,KAAK,CAAC;gBAAEH;YAAI;YAC/B,MAAMA;QACR;QACA,OAAOtB;IACT,EAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
import type { FileData, ImageSize } from 'payload/types';
|
|
2
|
+
import type { Field, FileData, ImageSize } from 'payload/types';
|
|
3
3
|
import type { TypeWithID } from 'payload/types';
|
|
4
4
|
import type { CollectionConfig, PayloadRequestWithData } from 'payload/types';
|
|
5
5
|
export interface File {
|
|
@@ -26,17 +26,26 @@ export type HandleDelete = (args: {
|
|
|
26
26
|
}) => Promise<void> | void;
|
|
27
27
|
export type GenerateURL = (args: {
|
|
28
28
|
collection: CollectionConfig;
|
|
29
|
+
data: any;
|
|
29
30
|
filename: string;
|
|
30
31
|
prefix?: string;
|
|
31
32
|
}) => Promise<string> | string;
|
|
32
33
|
export type StaticHandler = (req: PayloadRequestWithData, args: {
|
|
34
|
+
doc?: TypeWithID;
|
|
33
35
|
params: {
|
|
34
36
|
collection: string;
|
|
35
37
|
filename: string;
|
|
36
38
|
};
|
|
37
39
|
}) => Promise<Response> | Response;
|
|
38
40
|
export interface GeneratedAdapter {
|
|
39
|
-
|
|
41
|
+
/**
|
|
42
|
+
* Additional fields to be injected into the base collection and image sizes
|
|
43
|
+
*/
|
|
44
|
+
fields?: Field[];
|
|
45
|
+
/**
|
|
46
|
+
* Generates the public URL for a file
|
|
47
|
+
*/
|
|
48
|
+
generateURL?: GenerateURL;
|
|
40
49
|
handleDelete: HandleDelete;
|
|
41
50
|
handleUpload: HandleUpload;
|
|
42
51
|
name: string;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAC/D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC/C,OAAO,KAAK,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAA;AAE7E,MAAM,WAAW,IAAI;IACnB,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,MAAM,CAAA;IAChB,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB;AAED,MAAM,MAAM,YAAY,GAAG,CAAC,IAAI,EA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,MAAM,CAAC,EAAE,MAAM,IAAI,CAAA;IACnB,aAAa,EAAE,aAAa,CAAA;CAC7B;AAED,MAAM,MAAM,OAAO,GAAG,CAAC,IAAI,EAAE;IAAE,UAAU,EAAE,gBAAgB,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,KAAK,gBAAgB,CAAA;AAEnG,MAAM,MAAM,eAAe,GAAG,CAAC,IAAI,EAAE;IACnC,UAAU,EAAE,gBAAgB,CAAA;IAC5B,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,SAAS,CAAA;CACjB,KAAK,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,CAAA;AAE9B,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,OAAO,GAAG,IAAI,CAAA;IACvB,mBAAmB,CAAC,EAAE,OAAO,CAAA;IAC7B,2BAA2B,CAAC,EAAE,IAAI,CAAA;IAClC,eAAe,CAAC,EAAE,eAAe,CAAA;IACjC,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,aAAa;IAC5B,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAA;IAC9C;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB"}
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { FileData, ImageSize } from 'payload/types'\nimport type { TypeWithID } from 'payload/types'\nimport type { CollectionConfig, PayloadRequestWithData } from 'payload/types'\n\nexport interface File {\n buffer: Buffer\n filename: string\n filesize: number\n mimeType: string\n tempFilePath?: string\n}\n\nexport type HandleUpload = (args: {\n collection: CollectionConfig\n data: any\n file: File\n req: PayloadRequestWithData\n}) => Promise<void> | void\n\nexport interface TypeWithPrefix {\n prefix?: string\n}\n\nexport type HandleDelete = (args: {\n collection: CollectionConfig\n doc: TypeWithID & FileData & TypeWithPrefix\n filename: string\n req: PayloadRequestWithData\n}) => Promise<void> | void\n\nexport type GenerateURL = (args: {\n collection: CollectionConfig\n filename: string\n prefix?: string\n}) => Promise<string> | string\n\nexport type StaticHandler = (\n req: PayloadRequestWithData,\n args: { params: { collection: string; filename: string } },\n) => Promise<Response> | Response\n\nexport interface GeneratedAdapter {\n generateURL
|
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { Field, FileData, ImageSize } from 'payload/types'\nimport type { TypeWithID } from 'payload/types'\nimport type { CollectionConfig, PayloadRequestWithData } from 'payload/types'\n\nexport interface File {\n buffer: Buffer\n filename: string\n filesize: number\n mimeType: string\n tempFilePath?: string\n}\n\nexport type HandleUpload = (args: {\n collection: CollectionConfig\n data: any\n file: File\n req: PayloadRequestWithData\n}) => Promise<void> | void\n\nexport interface TypeWithPrefix {\n prefix?: string\n}\n\nexport type HandleDelete = (args: {\n collection: CollectionConfig\n doc: TypeWithID & FileData & TypeWithPrefix\n filename: string\n req: PayloadRequestWithData\n}) => Promise<void> | void\n\nexport type GenerateURL = (args: {\n collection: CollectionConfig\n data: any\n filename: string\n prefix?: string\n}) => Promise<string> | string\n\nexport type StaticHandler = (\n req: PayloadRequestWithData,\n args: { doc?: TypeWithID; params: { collection: string; filename: string } },\n) => Promise<Response> | Response\n\nexport interface GeneratedAdapter {\n /**\n * Additional fields to be injected into the base collection and image sizes\n */\n fields?: Field[]\n /**\n * Generates the public URL for a file\n */\n generateURL?: GenerateURL\n handleDelete: HandleDelete\n handleUpload: HandleUpload\n name: string\n onInit?: () => void\n staticHandler: StaticHandler\n}\n\nexport type Adapter = (args: { collection: CollectionConfig; prefix?: string }) => GeneratedAdapter\n\nexport type GenerateFileURL = (args: {\n collection: CollectionConfig\n filename: string\n prefix?: string\n size?: ImageSize\n}) => Promise<string> | string\n\nexport interface CollectionOptions {\n adapter: Adapter | null\n disableLocalStorage?: boolean\n disablePayloadAccessControl?: true\n generateFileURL?: GenerateFileURL\n prefix?: string\n}\n\nexport interface PluginOptions {\n collections: Record<string, CollectionOptions>\n /**\n * Whether or not to enable the plugin\n *\n * Default: true\n */\n enabled?: boolean\n}\n"],"names":[],"rangeMappings":"","mappings":"AA2EA,WAQC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/plugin-cloud-storage",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.30",
|
|
4
4
|
"description": "The official cloud storage plugin for Payload CMS",
|
|
5
5
|
"homepage": "https://payloadcms.com",
|
|
6
6
|
"repository": {
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"@google-cloud/storage": "^7.7.0",
|
|
46
46
|
"@types/find-node-modules": "^2.1.2",
|
|
47
47
|
"@vercel/blob": "^0.22.3",
|
|
48
|
-
"payload": "3.0.0-beta.
|
|
48
|
+
"payload": "3.0.0-beta.30"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"@aws-sdk/client-s3": "^3.525.0",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"@azure/storage-blob": "^12.11.0",
|
|
55
55
|
"@google-cloud/storage": "^7.7.0",
|
|
56
56
|
"@vercel/blob": "^0.22.3",
|
|
57
|
-
"payload": "3.0.0-beta.
|
|
57
|
+
"payload": "3.0.0-beta.30"
|
|
58
58
|
},
|
|
59
59
|
"peerDependenciesMeta": {
|
|
60
60
|
"@aws-sdk/client-s3": {
|