mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-03-06 12:31:33 +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'];
|
const allowedTypes = ['image/x-icon', 'image/vnd.microsoft.icon'];
|
||||||
|
|
||||||
await validateUpload(uploadedFile, allowedTypes);
|
await validateUpload(uploadedFile, allowedTypes);
|
||||||
try {
|
const filename = 'favicon' + path.extname(uploadedFile.name);
|
||||||
const imageObj = await file.saveFileToLocal('favicon.ico', 'system', uploadedFile.path);
|
await uploadImage(filename, 'system', uploadedFile, req, res, next);
|
||||||
res.json([{ name: uploadedFile.name, url: imageObj.url }]);
|
|
||||||
} catch (err) {
|
|
||||||
next(err);
|
|
||||||
} finally {
|
|
||||||
file.delete(uploadedFile.path);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
uploadsController.uploadTouchIcon = async function (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;
|
let imageData;
|
||||||
try {
|
try {
|
||||||
if (plugins.hooks.hasListeners('filter:uploadImage')) {
|
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 {
|
} else {
|
||||||
imageData = await file.saveFileToLocal(filename, folder, uploadedFile.path);
|
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,
|
'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) {
|
} catch (err) {
|
||||||
next(err);
|
next(err);
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@@ -57,8 +57,8 @@ Tags.parse = async (req, data, meta, link) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const faviconPath = `${relative_path}/assets/uploads/system/favicon.ico`;
|
const faviconPath = Meta.config['brand:favicon'] || `${relative_path}/assets/uploads/system/favicon.ico`;
|
||||||
const cacheBuster = `${Meta.config['cache-buster'] ? `?${Meta.config['cache-buster']}` : ''}`;
|
const cacheBuster = Meta.config['cache-buster'] || '';
|
||||||
|
|
||||||
// Link Tags
|
// Link Tags
|
||||||
const defaultLinks = isAPI ? [] : [{
|
const defaultLinks = isAPI ? [] : [{
|
||||||
|
|||||||
Reference in New Issue
Block a user