payload-plugin-cloud-storage
Version:
Remote storage plugin for Payload CMS.
55 lines (54 loc) • 3.1 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const uploadHook_1 = __importDefault(require("./collection/uploadHook"));
const deleteHook_1 = __importDefault(require("./collection/deleteHook"));
const readHook_1 = __importDefault(require("./collection/readHook"));
const adminThumbnail_1 = __importDefault(require("./collection/adminThumbnail"));
const shouldApplyAdminThumbnail_1 = __importDefault(require("./validation/shouldApplyAdminThumbnail"));
const cloudStorage = (adapter, options) => {
var _a, _b;
const endpointFieldName = (_a = options === null || options === void 0 ? void 0 : options.endpointPropertyName) !== null && _a !== void 0 ? _a : 'cloudStorageUrl';
const disableLocalStorage = (_b = options === null || options === void 0 ? void 0 : options.disableLocalStorage) !== null && _b !== void 0 ? _b : true;
return (incomingConfig) => {
if (!incomingConfig.collections) {
return incomingConfig;
}
const config = {
...incomingConfig,
collections: incomingConfig.collections.map(collection => {
var _a;
if (collection.upload === true) {
collection.upload = {};
}
if (typeof collection.upload === 'object' && collection.upload !== null && !Array.isArray(collection.upload)) {
const { beforeChange = [], afterDelete = [], afterRead = [] } = collection.hooks || {};
const composedReadHooks = (options === null || options === void 0 ? void 0 : options.disableEndpointProperty) === true
? afterRead
: [...afterRead, (0, readHook_1.default)(adapter, endpointFieldName)];
collection.hooks = {
...collection.hooks,
beforeChange: [
...beforeChange,
(0, uploadHook_1.default)(adapter)
],
afterDelete: [
...afterDelete,
(0, deleteHook_1.default)(adapter)
],
afterRead: composedReadHooks
};
if ((options === null || options === void 0 ? void 0 : options.disableEndpointProperty) !== true && (0, shouldApplyAdminThumbnail_1.default)((_a = collection === null || collection === void 0 ? void 0 : collection.upload) === null || _a === void 0 ? void 0 : _a.adminThumbnail)) {
collection.upload.adminThumbnail = (0, adminThumbnail_1.default)(endpointFieldName, collection.upload.adminThumbnail);
}
collection.upload.disableLocalStorage = disableLocalStorage;
}
return collection;
})
};
return config;
};
};
exports.default = cloudStorage;