mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-02-16 03:27:59 +01:00
feat: closes https://github.com/NodeBB/NodeBB/pull/11970
allow favicons via upload plugins dont hardcoded favicon url to /assets/uploads and use whats saved in acp field
This commit is contained in:
@@ -168,14 +168,8 @@ uploadsController.uploadFavicon = async function (req, res, next) {
|
||||
const allowedTypes = ['image/x-icon', 'image/vnd.microsoft.icon'];
|
||||
|
||||
await validateUpload(uploadedFile, allowedTypes);
|
||||
try {
|
||||
const imageObj = await file.saveFileToLocal('favicon.ico', 'system', uploadedFile.path);
|
||||
res.json([{ name: uploadedFile.name, url: imageObj.url }]);
|
||||
} catch (err) {
|
||||
next(err);
|
||||
} finally {
|
||||
file.delete(uploadedFile.path);
|
||||
}
|
||||
const filename = 'favicon' + path.extname(uploadedFile.name);
|
||||
await uploadImage(filename, 'system', uploadedFile, req, res, next);
|
||||
};
|
||||
|
||||
uploadsController.uploadTouchIcon = async function (req, res, next) {
|
||||
@@ -274,7 +268,11 @@ async function uploadImage(filename, folder, uploadedFile, req, res, next) {
|
||||
let imageData;
|
||||
try {
|
||||
if (plugins.hooks.hasListeners('filter:uploadImage')) {
|
||||
imageData = await plugins.hooks.fire('filter:uploadImage', { image: uploadedFile, uid: req.uid, folder: folder });
|
||||
imageData = await plugins.hooks.fire('filter:uploadImage', {
|
||||
image: uploadedFile,
|
||||
uid: req.uid,
|
||||
folder: folder,
|
||||
});
|
||||
} else {
|
||||
imageData = await file.saveFileToLocal(filename, folder, uploadedFile.path);
|
||||
}
|
||||
@@ -299,7 +297,14 @@ async function uploadImage(filename, folder, uploadedFile, req, res, next) {
|
||||
'og:image:height': size.height,
|
||||
});
|
||||
}
|
||||
res.json([{ name: uploadedFile.name, url: imageData.url.startsWith('http') ? imageData.url : nconf.get('relative_path') + imageData.url }]);
|
||||
res.json([
|
||||
{
|
||||
name: uploadedFile.name,
|
||||
url: imageData.url.startsWith('http') ?
|
||||
imageData.url :
|
||||
nconf.get('relative_path') + imageData.url,
|
||||
},
|
||||
]);
|
||||
} catch (err) {
|
||||
next(err);
|
||||
} finally {
|
||||
|
||||
@@ -57,8 +57,8 @@ Tags.parse = async (req, data, meta, link) => {
|
||||
});
|
||||
}
|
||||
|
||||
const faviconPath = `${relative_path}/assets/uploads/system/favicon.ico`;
|
||||
const cacheBuster = `${Meta.config['cache-buster'] ? `?${Meta.config['cache-buster']}` : ''}`;
|
||||
const faviconPath = Meta.config['brand:favicon'] || `${relative_path}/assets/uploads/system/favicon.ico`;
|
||||
const cacheBuster = Meta.config['cache-buster'] || '';
|
||||
|
||||
// Link Tags
|
||||
const defaultLinks = isAPI ? [] : [{
|
||||
|
||||
Reference in New Issue
Block a user