payloadcms-import-export-plugin
Version:
A comprehensive Payload CMS plugin that enables seamless import and export of collection data with support for CSV and JSON formats, featuring advanced field mapping, duplicate handling, and batch processing capabilities.
86 lines (85 loc) • 2.62 kB
JavaScript
import { createExport } from './export/createExport.js';
import { download } from './export/download.js';
import { getFields } from './export/getFields.js';
export const getExportCollection = ({ config, pluginConfig })=>{
const { overrideExportCollection } = pluginConfig;
const beforeOperation = [];
const afterChange = [];
let collection = {
slug: 'exports',
access: {
update: ()=>false
},
admin: {
components: {
edit: {
SaveButton: 'payloadcms-import-export-plugin/rsc#ExportSaveButton'
}
},
custom: {
disableDownload: pluginConfig.disableDownload ?? false,
disableSave: pluginConfig.disableSave ?? false
},
group: false,
useAsTitle: 'name'
},
disableDuplicate: true,
endpoints: [
{
handler: (req)=>{
return download(req, pluginConfig.debug);
},
method: 'post',
path: '/download'
}
],
fields: getFields(config, pluginConfig),
hooks: {
afterChange,
beforeOperation
},
upload: {
filesRequiredOnCreate: false,
hideFileInputOnCreate: true,
hideRemoveFile: true
}
};
if (typeof overrideExportCollection === 'function') {
collection = overrideExportCollection(collection);
}
if (pluginConfig.disableJobsQueue) {
beforeOperation.push(async ({ args, operation, req })=>{
if (operation !== 'create') {
return;
}
const { user } = req;
const debug = pluginConfig.debug;
await createExport({
input: {
...args.data,
debug,
user
},
req
});
});
} else {
afterChange.push(async ({ doc, operation, req })=>{
if (operation !== 'create') {
return;
}
const input = {
...doc,
exportsCollection: collection.slug,
user: req?.user?.id || req?.user?.user?.id,
userCollection: 'users'
};
await req.payload.jobs.queue({
input,
task: 'createCollectionExport'
});
});
}
return collection;
};
//# sourceMappingURL=getExportCollection.js.map