allow favicons via upload plugins
dont hardcoded favicon url to /assets/uploads and use whats saved in acp field
This commit is contained in:
Barış Soner Uşaklı
2026-02-09 11:47:28 -05:00
parent dda0480abf
commit 007efc21d4
2 changed files with 17 additions and 12 deletions

View File

@@ -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 {

View File

@@ -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 ? [] : [{