Files can be added to templates and managed in a dedicated "Files" view.
Mosaico integration in progress. The files seem to be working for Mosaico.
This commit is contained in:
parent
c85f2d4440
commit
b5cdf57f72
23 changed files with 506 additions and 164 deletions
|
@ -2,13 +2,11 @@
|
|||
|
||||
const passport = require('../../lib/passport');
|
||||
const files = require('../../models/files');
|
||||
|
||||
const router = require('../../lib/router-async').create();
|
||||
const multer = require('../../lib/multer');
|
||||
const fileHelpers = require('../../lib/file-helpers');
|
||||
|
||||
router.postAsync('/files-table/:type/:entityId', passport.loggedIn, async (req, res) => {
|
||||
const files = await files.listFilesDTAjax(req.context, req.params.type, req.params.entityId, req.body);
|
||||
return res.json(files);
|
||||
return res.json(await files.listDTAjax(req.context, req.params.type, req.params.entityId, req.body));
|
||||
});
|
||||
|
||||
router.getAsync('/files/:type/:fileId', passport.loggedIn, async (req, res) => {
|
||||
|
@ -17,22 +15,11 @@ router.getAsync('/files/:type/:fileId', passport.loggedIn, async (req, res) => {
|
|||
return res.download(file.path, file.name);
|
||||
});
|
||||
|
||||
router.getAsync('/files-by-name/:type/:entityId/:fileName', passport.loggedIn, async (req, res) => {
|
||||
const file = await templates.getFileByName(req.context, req.params.type, req.params.entityId, req.params.fileName);
|
||||
res.type(file.mimetype);
|
||||
// return res.sendFile(file.path); FIXME - remove this comment if the download below is OK
|
||||
return res.download(file.path, file.name);
|
||||
});
|
||||
|
||||
|
||||
router.putAsync('/files/:type/:entityId', passport.loggedIn, multer.array('file'), async (req, res) => {
|
||||
const summary = await files.createFiles(req.context, req.params.type, req.params.entityId, req.files);
|
||||
return res.json(summary);
|
||||
});
|
||||
|
||||
router.deleteAsync('/files/:type/:fileId', passport.loggedIn, async (req, res) => {
|
||||
await files.removeFile(req.context, req.params.type, req.params.fileId);
|
||||
return res.json();
|
||||
});
|
||||
|
||||
fileHelpers.installUploadHandler(router, '/files/:type/:entityId');
|
||||
|
||||
module.exports = router;
|
|
@ -4,7 +4,7 @@ const passport = require('../../lib/passport');
|
|||
const _ = require('../../lib/translate')._;
|
||||
const reports = require('../../models/reports');
|
||||
const reportProcessor = require('../../lib/report-processor');
|
||||
const fileHelpers = require('../../lib/file-helpers');
|
||||
const reportHelpers = require('../../lib/report-helpers');
|
||||
const shares = require('../../models/shares');
|
||||
const contextHelpers = require('../../lib/context-helpers');
|
||||
|
||||
|
@ -62,14 +62,14 @@ router.getAsync('/report-content/:id', async (req, res) => {
|
|||
await shares.enforceEntityPermission(req.context, 'report', req.params.id, 'viewContent');
|
||||
|
||||
const report = await reports.getByIdWithTemplate(contextHelpers.getAdminContext(), req.params.id);
|
||||
res.sendFile(fileHelpers.getReportContentFile(report));
|
||||
res.sendFile(reportHelpers.getReportContentFile(report));
|
||||
});
|
||||
|
||||
router.getAsync('/report-output/:id', async (req, res) => {
|
||||
await shares.enforceEntityPermission(req.context, 'report', req.params.id, 'viewOutput');
|
||||
|
||||
const report = await reports.getByIdWithTemplate(contextHelpers.getAdminContext(), req.params.id);
|
||||
res.sendFile(fileHelpers.getReportOutputFile(report));
|
||||
res.sendFile(reportHelpers.getReportOutputFile(report));
|
||||
});
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue