mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-05-09 12:47:06 +02:00
fix: use file.exists instead of try/catch to detect missing email logo (#14154)
The previous ENOENT check in getLogoSize never worked because image.size passes the path directly to sharp, which throws a plain Error with message "Input file is missing" rather than a Node.js ENOENT error. This caused saving any admin settings to fail when brand:logo was set but the x50 file was missing (e.g. after a fresh deployment).
This commit is contained in:
@@ -6,6 +6,7 @@ const path = require('path');
|
|||||||
const winston = require('winston');
|
const winston = require('winston');
|
||||||
|
|
||||||
const db = require('../database');
|
const db = require('../database');
|
||||||
|
const file = require('../file');
|
||||||
const pubsub = require('../pubsub');
|
const pubsub = require('../pubsub');
|
||||||
const Meta = require('./index');
|
const Meta = require('./index');
|
||||||
const translator = require('../translator');
|
const translator = require('../translator');
|
||||||
@@ -212,20 +213,17 @@ async function getLogoSize(data) {
|
|||||||
if (!data['brand:logo']) {
|
if (!data['brand:logo']) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const x50Path = path.join(nconf.get('upload_path'), 'system', 'site-logo-x50.png');
|
||||||
let size;
|
let size;
|
||||||
try {
|
if (await file.exists(x50Path)) {
|
||||||
size = await image.size(path.join(nconf.get('upload_path'), 'system', 'site-logo-x50.png'));
|
size = await image.size(x50Path);
|
||||||
} catch (err) {
|
} else {
|
||||||
if (err.code === 'ENOENT') {
|
// For whatever reason the x50 logo wasn't generated, gracefully error out
|
||||||
// For whatever reason the x50 logo wasn't generated, gracefully error out
|
winston.warn('[logo] The email-safe logo doesn\'t seem to have been created, please re-upload your site logo.');
|
||||||
winston.warn('[logo] The email-safe logo doesn\'t seem to have been created, please re-upload your site logo.');
|
size = {
|
||||||
size = {
|
height: 0,
|
||||||
height: 0,
|
width: 0,
|
||||||
width: 0,
|
};
|
||||||
};
|
|
||||||
} else {
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
data['brand:emailLogo'] = nconf.get('url') + path.join(nconf.get('upload_url'), 'system', 'site-logo-x50.png');
|
data['brand:emailLogo'] = nconf.get('url') + path.join(nconf.get('upload_url'), 'system', 'site-logo-x50.png');
|
||||||
data['brand:emailLogo:height'] = size.height;
|
data['brand:emailLogo:height'] = size.height;
|
||||||
|
|||||||
Reference in New Issue
Block a user