@nocobase/plugin-file-manager
Version:
Provides files storage services with files collection template and attachment field.
79 lines (77 loc) • 3.07 kB
JavaScript
/**
* This file is part of the NocoBase (R) project.
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
* Authors: NocoBase Team.
*
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
* For more information, please refer to: https://www.nocobase.com/agreement.
*/
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var actions_exports = {};
__export(actions_exports, {
default: () => actions_default
});
module.exports = __toCommonJS(actions_exports);
var import_actions = __toESM(require("@nocobase/actions"));
var import_attachments = require("./attachments");
var import_storage_validation = require("./storage-validation");
var storageActions = __toESM(require("./storages"));
function actions_default({ app }) {
app.resourcer.define({
name: "storages",
actions: storageActions,
middlewares: [
{
only: ["create", "update"],
handler: import_storage_validation.validateStorageMiddleware
}
]
});
app.resourcer.use(import_attachments.createMiddleware, { tag: "createMiddleware", after: "auth" });
app.resourcer.registerActionHandler("upload", import_actions.default.create);
app.resourcer.use(
async (ctx, next) => {
var _a;
await next();
try {
const { resourceName, actionName } = ctx.action;
const collection = ctx.db.getCollection(resourceName);
if (((_a = collection == null ? void 0 : collection.options) == null ? void 0 : _a.template) !== "file") {
return;
}
if (actionName === "create" || actionName === "upload") {
ctx.body = await ctx.body.reload();
}
} catch (error) {
console.log(error);
}
},
{ before: "dataWrapping" }
);
}