payload-s3-upload
Version:
Send Payload CMS uploads to Amazon S3
28 lines • 1.5 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const client_s3_1 = require("@aws-sdk/client-s3");
const buildUploadHook_1 = __importDefault(require("./buildUploadHook"));
const buildDeleteHook_1 = __importDefault(require("./buildDeleteHook"));
const pluginPayloadS3Upload = (s3Client) => {
const client = s3Client instanceof client_s3_1.S3Client ? s3Client : new client_s3_1.S3Client(s3Client);
return (payloadConfig) => {
const uploadCollections = payloadConfig.collections.filter((collection) => { var _a; return ((_a = collection.upload) === null || _a === void 0 ? void 0 : _a.s3) != null; });
uploadCollections.forEach((collection) => {
if (collection.hooks == null)
collection.hooks = {};
if (collection.hooks.beforeChange == null)
collection.hooks.beforeChange = [];
if (collection.hooks.afterDelete == null)
collection.hooks.afterDelete = [];
collection.hooks.beforeChange.push((0, buildUploadHook_1.default)(client, collection));
collection.hooks.afterDelete.push((0, buildDeleteHook_1.default)(client, collection));
delete collection.upload.s3;
});
return payloadConfig;
};
};
exports.default = pluginPayloadS3Upload;
//# sourceMappingURL=plugin.js.map