Fixes in reports (generating a CSV).
Added caching of generated images in mosaico handler. Various other fixes.
This commit is contained in:
parent
055c4c6b51
commit
66702b5edc
39 changed files with 545 additions and 278 deletions
|
@ -7,7 +7,7 @@ const { AppType } = require('../../shared/app');
|
|||
|
||||
const routerFactory = require('../lib/router-async');
|
||||
|
||||
function getRouter(appType) {
|
||||
async function getRouter(appType) {
|
||||
const router = routerFactory.create();
|
||||
|
||||
if (appType === AppType.TRUSTED) {
|
||||
|
|
|
@ -4,7 +4,7 @@ const passport = require('../../lib/passport');
|
|||
|
||||
const bluebird = require('bluebird');
|
||||
const premailerApi = require('premailer-api');
|
||||
const premailerPrepareAsync = bluebird.promisify(premailerApi.prepare);
|
||||
const premailerPrepareAsync = bluebird.promisify(premailerApi.prepare.bind(premailerApi));
|
||||
|
||||
const router = require('../../lib/router-async').create();
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ users.registerRestrictedAccessTokenMethod('ckeditor', async ({entityTypeId, enti
|
|||
});
|
||||
|
||||
|
||||
function getRouter(appType) {
|
||||
async function getRouter(appType) {
|
||||
const router = routerFactory.create();
|
||||
|
||||
if (appType === AppType.SANDBOXED) {
|
||||
|
|
|
@ -33,7 +33,7 @@ users.registerRestrictedAccessTokenMethod('codeeditor', async ({entityTypeId, en
|
|||
});
|
||||
|
||||
|
||||
function getRouter(appType) {
|
||||
async function getRouter(appType) {
|
||||
const router = routerFactory.create();
|
||||
|
||||
if (appType === AppType.SANDBOXED) {
|
||||
|
|
|
@ -33,7 +33,7 @@ users.registerRestrictedAccessTokenMethod('grapesjs', async ({entityTypeId, enti
|
|||
});
|
||||
|
||||
|
||||
function getRouter(appType) {
|
||||
async function getRouter(appType) {
|
||||
const router = routerFactory.create();
|
||||
|
||||
if (appType === AppType.SANDBOXED) {
|
||||
|
|
|
@ -31,6 +31,8 @@ const { AppType } = require('../../shared/app');
|
|||
|
||||
const {castToInteger} = require('../lib/helpers');
|
||||
|
||||
const { fileCache } = require('../lib/file-cache');
|
||||
|
||||
|
||||
users.registerRestrictedAccessTokenMethod('mosaico', async ({entityTypeId, entityId}) => {
|
||||
if (entityTypeId === 'template') {
|
||||
|
@ -131,7 +133,7 @@ function sanitizeSize(val, min, max, defaultVal, allowNull) {
|
|||
|
||||
|
||||
|
||||
function getRouter(appType) {
|
||||
async function getRouter(appType) {
|
||||
const router = routerFactory.create();
|
||||
|
||||
if (appType === AppType.SANDBOXED) {
|
||||
|
@ -161,14 +163,14 @@ function getRouter(appType) {
|
|||
router.use('/templates/:mosaicoTemplateId/edres', express.static(path.join(__dirname, '..', '..', 'client', 'static', 'mosaico', 'templates', 'versafix-1', 'edres')));
|
||||
|
||||
// This is the final fallback for a block thumbnail, so that at least something gets returned
|
||||
router.getAsync('/templates/:mosaicoTemplateId/edres/:fileName', async (req, res, next) => {
|
||||
router.getAsync('/templates/:mosaicoTemplateId/edres/:fileName', await fileCache('mosaico-block-thumbnails', config.mosaico.fileCache.blockThumbnails, req => req.params.fileName), async (req, res) => {
|
||||
let labelText = req.params.fileName.replace(/\.png$/, '');
|
||||
labelText = labelText.replace(/[_]/g, ' ');
|
||||
labelText = capitalize.words(labelText);
|
||||
|
||||
const image = await placeholderImage(340, 100, labelText, '#ffffff');
|
||||
res.set('Content-Type', 'image/' + image.format);
|
||||
image.stream.pipe(res);
|
||||
image.stream.pipe(res.fileCacheResponse);
|
||||
});
|
||||
|
||||
fileHelpers.installUploadHandler(router, '/upload/:type/:entityId', files.ReplacementBehavior.RENAME, null, 'file', resp => {
|
||||
|
@ -225,7 +227,7 @@ function getRouter(appType) {
|
|||
|
||||
} else if (appType === AppType.TRUSTED || appType === AppType.PUBLIC) { // Mosaico editor loads the images from TRUSTED endpoint. This is hard to change because the index.html has to come from TRUSTED.
|
||||
// So we serve /mosaico/img under both endpoints. There is no harm in it.
|
||||
router.getAsync('/img', async (req, res) => {
|
||||
router.getAsync('/img', await fileCache('mosaico-images', config.mosaico.fileCache.images), async (req, res) => {
|
||||
const method = req.query.method;
|
||||
const params = req.query.params;
|
||||
let [width, height] = params.split(',');
|
||||
|
@ -248,7 +250,7 @@ function getRouter(appType) {
|
|||
height = sanitizeSize(height, 1, 2048, 300, true);
|
||||
|
||||
let filePath;
|
||||
const url = req.query.src;
|
||||
const url = req.query.src || '';
|
||||
|
||||
const mosaicoLegacyUrlPrefix = getTrustedUrl(`mosaico/uploads/`);
|
||||
if (url.startsWith(mosaicoLegacyUrlPrefix)) {
|
||||
|
@ -262,7 +264,7 @@ function getRouter(appType) {
|
|||
}
|
||||
|
||||
res.set('Content-Type', 'image/' + image.format);
|
||||
image.stream.pipe(res);
|
||||
image.stream.pipe(res.fileCacheResponse);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -334,7 +334,7 @@ router.getAsync('/:cid/widget', cors(corsOptions), async (req, res) => {
|
|||
|
||||
await injectCustomFormData(req.query.fid || list.default_form, 'web_subscribe', data);
|
||||
|
||||
const renderAsync = bluebird.promisify(res.render);
|
||||
const renderAsync = bluebird.promisify(res.render.bind(res));
|
||||
const html = await renderAsync('subscription/widget-subscribe', data);
|
||||
|
||||
const response = {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue