Skip to content

Node.js based forum software built for the modern web

fix: add cache buster for uploaded acp uploaded images

Barış Soner Uşaklı88d4409a5cdf
diff --git a/install/package.json b/install/package.json
index d42f88014d..bf072c8974 100644
--- a/install/package.json
+++ b/install/package.json
@@ -113,10 +113,10 @@
"nodebb-plugin-spam-be-gone": "2.3.5",
"nodebb-plugin-web-push": "0.9.3",
"nodebb-rewards-essentials": "1.0.3",
- "nodebb-theme-harmony": "3.2.3",
+ "nodebb-theme-harmony": "3.2.7",
"nodebb-theme-lavender": "8.1.0",
- "nodebb-theme-peace": "3.1.2",
- "nodebb-theme-persona": "15.2.3",
+ "nodebb-theme-peace": "3.1.3",
+ "nodebb-theme-persona": "15.2.4",
"nodebb-widget-essentials": "8.0.9",
"nodemailer": "9.0.5",
"nprogress": "0.2.0",
diff --git a/public/src/admin/manage/category.js b/public/src/admin/manage/category.js
index a914094a61..11a20b245a 100644
--- a/public/src/admin/manage/category.js
+++ b/public/src/admin/manage/category.js
@@ -206,7 +206,7 @@ define('admin/manage/category', [
params: { cid: cid },
}, function (imageUrlOnServer) {
$('#category-image').val(imageUrlOnServer);
- previewEl.css('background-image', 'url(' + imageUrlOnServer + '?' + new Date().getTime() + ')');
+ previewEl.css('background-image', `url(${imageUrlOnServer}?v=${Date.now()})`);
modified($('#category-image'));
});
diff --git a/public/src/modules/helpers.common.js b/public/src/modules/helpers.common.js
index 07fe08da2c..e2774d8e41 100644
--- a/public/src/modules/helpers.common.js
+++ b/public/src/modules/helpers.common.js
@@ -25,6 +25,7 @@ module.exports = function (utils, Benchpress, tx, relative_path) {
generateGroupDisplayName,
membershipBtn,
spawnPrivilegeStates,
+ cacheBustedUrl,
localeToHTML,
renderDigestAvatar,
userAgentIcons,
@@ -213,7 +214,11 @@ module.exports = function (utils, Benchpress, tx, relative_path) {
}
if (category.backgroundImage) {
- style.push(`background-image: url(${category.backgroundImage})`);
+ const backgroundUrl = utils.cacheBustedUrl(
+ category.backgroundImage,
+ category['backgroundImage:updatedAt']
+ );
+ style.push(`background-image: url(${backgroundUrl})`);
if (category.imageClass) {
style.push(`background-size: ${category.imageClass}`);
}
@@ -301,6 +306,10 @@ module.exports = function (utils, Benchpress, tx, relative_path) {
}).join('');
}
+ function cacheBustedUrl(url, updatedAt) {
+ return escape(utils.cacheBustedUrl(url, updatedAt));
+ }
+
function localeToHTML(locale, fallback) {
locale = locale || fallback || 'en-GB';
return locale.replace('_', '-');
diff --git a/public/src/utils.common.js b/public/src/utils.common.js
index a7d55d66b5..9e4083d15a 100644
--- a/public/src/utils.common.js
+++ b/public/src/utils.common.js
@@ -478,6 +478,14 @@ const utils = {
return !utils.isAbsoluteUrl(url);
},
+ cacheBustedUrl: function (url, updatedAt) {
+ if (!url || !updatedAt) {
+ return url;
+ }
+ const separator = url.includes('?') ? '&' : '?';
+ return `${url}${separator}v=${updatedAt}`;
+ },
+
makeNumberHumanReadable: function (num, toFixed = 1) {
const n = parseInt(num, 10);
if (!n) {
diff --git a/src/controllers/admin/uploads.js b/src/controllers/admin/uploads.js
index 1278a020ca..44659c1942 100644
--- a/src/controllers/admin/uploads.js
+++ b/src/controllers/admin/uploads.js
@@ -6,6 +6,7 @@ const fs = require('fs');
const winston = require('winston');
const meta = require('../../meta');
+const categories = require('../../categories');
const posts = require('../../posts');
const file = require('../../file');
const image = require('../../image');
@@ -159,66 +160,68 @@ uploadsController.uploadCategoryPicture = async function (req, res, next) {
await validateUpload(uploadedFile, allowedImageTypes);
const filename = `category-${params.cid}${path.extname(uploadedFile.name)}`;
- await uploadImage(filename, 'category', uploadedFile, req, res, next);
+ const storedFile = await uploadImage(filename, 'category', uploadedFile, req);
+ await categories.setCategoryField(params.cid, 'backgroundImageUpdatedAt', Date.now());
+ res.json([storedFile]);
};
-uploadsController.uploadFavicon = async function (req, res, next) {
+uploadsController.uploadFavicon = async function (req, res) {
const uploadedFile = req.files[0];
const allowedTypes = ['image/x-icon', 'image/vnd.microsoft.icon'];
await validateUpload(uploadedFile, allowedTypes);
const filename = 'favicon' + path.extname(uploadedFile.name);
- await uploadImage(filename, 'system', uploadedFile, req, res, next);
+ const storedFile = await uploadImage(filename, 'system', uploadedFile, req);
+ await meta.configs.set('brand:favicon:updatedAt', Date.now());
+ res.json([storedFile]);
};
-uploadsController.uploadTouchIcon = async function (req, res, next) {
+uploadsController.uploadTouchIcon = async function (req, res) {
const uploadedFile = req.files[0];
const allowedTypes = ['image/png'];
const sizes = [36, 48, 72, 96, 144, 192, 512];
await validateUpload(uploadedFile, allowedTypes);
- try {
- const imageObj = await file.saveFileToLocal('touchicon-orig.png', 'system', uploadedFile.path);
- // Resize the image into squares for use as touch icons at various DPIs
- for (const size of sizes) {
- /* eslint-disable no-await-in-loop */
- await image.resizeImage({
- path: uploadedFile.path,
- target: path.join(nconf.get('upload_path'), 'system', `touchicon-${size}.png`),
- width: size,
- height: size,
- });
- }
- res.json([{ name: uploadedFile.name, url: imageObj.url }]);
- } catch (err) {
- next(err);
+
+ const imageObj = await file.saveFileToLocal('touchicon-orig.png', 'system', uploadedFile.path);
+ // Resize the image into squares for use as touch icons at various DPIs
+ for (const size of sizes) {
+ /* eslint-disable no-await-in-loop */
+ await image.resizeImage({
+ path: uploadedFile.path,
+ target: path.join(nconf.get('upload_path'), 'system', `touchicon-${size}.png`),
+ width: size,
+ height: size,
+ });
}
+ await meta.configs.set('brand:touchIcon:updatedAt', Date.now());
+ res.json([{ name: uploadedFile.name, url: imageObj.url }]);
};
-uploadsController.uploadMaskableIcon = async function (req, res, next) {
+uploadsController.uploadMaskableIcon = async function (req, res) {
const uploadedFile = req.files[0];
const allowedTypes = ['image/png'];
await validateUpload(uploadedFile, allowedTypes);
- try {
- const imageObj = await file.saveFileToLocal('maskableicon-orig.png', 'system', uploadedFile.path);
- res.json([{ name: uploadedFile.name, url: imageObj.url }]);
- } catch (err) {
- next(err);
- }
+ const imageObj = await file.saveFileToLocal('maskableicon-orig.png', 'system', uploadedFile.path);
+ await meta.configs.set('brand:maskableIcon:updatedAt', Date.now());
+ res.json([{ name: uploadedFile.name, url: imageObj.url }]);
};
-uploadsController.uploadScreenshot = async function (req, res, next) {
+uploadsController.uploadScreenshot = async function (req, res) {
const uploadedFile = req.files[0];
const allowedTypes = ['image/png', 'image/jpeg'];
await validateUpload(uploadedFile, allowedTypes);
- try {
- const imageObj = await file.saveFileToLocal('screenshot.png', 'system', uploadedFile.path);
- res.json([{ name: uploadedFile.name, url: imageObj.url }]);
- } catch (err) {
- next(err);
- }
+
+ const imageObj = await file.saveFileToLocal('screenshot.png', 'system', uploadedFile.path);
+ const { width, height } = await image.size(uploadedFile.path);
+ await meta.configs.setMultiple({
+ 'brand:screenshot:updatedAt': Date.now(),
+ 'brand:screenshot:width': width,
+ 'brand:screenshot:height': height,
+ });
+ res.json([{ name: uploadedFile.name, url: imageObj.url }]);
};
uploadsController.uploadFile = async function (req, res, next) {
@@ -233,32 +236,35 @@ uploadsController.uploadFile = async function (req, res, next) {
if (!await file.exists(path.join(nconf.get('upload_path'), params.folder))) {
return next(new Error('[[error:invalid-path]]'));
}
- try {
- const data = await file.saveFileToLocal(uploadedFile.name, params.folder, uploadedFile.path);
- res.json([{ url: data.url }]);
- } catch (err) {
- next(err);
- }
+
+ const data = await file.saveFileToLocal(uploadedFile.name, params.folder, uploadedFile.path);
+ res.json([{ url: data.url }]);
};
-uploadsController.uploadLogo = async function (req, res, next) {
- await upload('site-logo', req, res, next);
+uploadsController.uploadLogo = async function (req, res) {
+ const storedFile = await upload('site-logo', req);
+ await meta.configs.set('brand:logo:updatedAt', Date.now());
+ res.json([storedFile]);
};
-uploadsController.uploadDefaultAvatar = async function (req, res, next) {
- await upload('avatar-default', req, res, next);
+uploadsController.uploadDefaultAvatar = async function (req, res) {
+ const storedFile = await upload('avatar-default', req);
+ await meta.configs.set('defaultAvatar:updatedAt', Date.now());
+ res.json([storedFile]);
};
-uploadsController.uploadOgImage = async function (req, res, next) {
- await upload('og:image', req, res, next);
+uploadsController.uploadOgImage = async function (req, res) {
+ const storedFile = await upload('og:image', req);
+ await meta.configs.set('og:image:updatedAt', Date.now());
+ res.json([storedFile]);
};
-async function upload(name, req, res, next) {
+async function upload(name, req) {
const uploadedFile = req.files[0];
await validateUpload(uploadedFile, allowedImageTypes);
const filename = name + path.extname(uploadedFile.name);
- await uploadImage(filename, 'system', uploadedFile, req, res, next);
+ return await uploadImage(filename, 'system', uploadedFile, req);
}
async function validateUpload(uploadedFile, allowedTypes) {
@@ -267,48 +273,44 @@ async function validateUpload(uploadedFile, allowedTypes) {
}
}
-async function uploadImage(filename, folder, uploadedFile, req, res, next) {
+async function uploadImage(filename, folder, uploadedFile, req) {
let imageData;
- try {
- if (plugins.hooks.hasListeners('filter:uploadImage')) {
- imageData = await plugins.hooks.fire('filter:uploadImage', {
- image: uploadedFile,
- uid: req.uid,
- folder: folder,
- });
- } else {
- imageData = await file.saveFileToLocal(filename, folder, uploadedFile.path);
- }
- if (path.basename(filename, path.extname(filename)) === 'site-logo' && folder === 'system') {
- const uploadPath = path.join(nconf.get('upload_path'), folder, 'site-logo-x50.png');
- await image.resizeImage({
- path: uploadedFile.path,
- target: uploadPath,
- height: 50,
- });
- await meta.configs.set('brand:emailLogo', path.join(nconf.get('upload_url'), 'system/site-logo-x50.png'));
- const size = await image.size(uploadedFile.path);
- await meta.configs.setMultiple({
- 'brand:logo:width': size.width,
- 'brand:logo:height': size.height,
- });
- } else if (path.basename(filename, path.extname(filename)) === 'og:image' && folder === 'system') {
- const size = await image.size(uploadedFile.path);
- await meta.configs.setMultiple({
- 'og:image:width': size.width,
- 'og:image:height': size.height,
- });
- }
- res.json([
- {
- name: uploadedFile.name,
- url: imageData.url.startsWith('http') ?
- imageData.url :
- nconf.get('relative_path') + imageData.url,
- },
- ]);
- } catch (err) {
- next(err);
+ if (plugins.hooks.hasListeners('filter:uploadImage')) {
+ imageData = await plugins.hooks.fire('filter:uploadImage', {
+ image: uploadedFile,
+ uid: req.uid,
+ folder: folder,
+ });
+ } else {
+ imageData = await file.saveFileToLocal(filename, folder, uploadedFile.path);
+ }
+
+ if (path.basename(filename, path.extname(filename)) === 'site-logo' && folder === 'system') {
+ const uploadPath = path.join(nconf.get('upload_path'), folder, 'site-logo-x50.png');
+ await image.resizeImage({
+ path: uploadedFile.path,
+ target: uploadPath,
+ height: 50,
+ });
+ await meta.configs.set('brand:emailLogo', path.join(nconf.get('upload_url'), 'system/site-logo-x50.png'));
+ const size = await image.size(uploadedFile.path);
+ await meta.configs.setMultiple({
+ 'brand:logo:width': size.width,
+ 'brand:logo:height': size.height,
+ });
+ } else if (path.basename(filename, path.extname(filename)) === 'og:image' && folder === 'system') {
+ const size = await image.size(uploadedFile.path);
+ await meta.configs.setMultiple({
+ 'og:image:width': size.width,
+ 'og:image:height': size.height,
+ });
}
+
+ return {
+ name: uploadedFile.name,
+ url: imageData.url.startsWith('http') ?
+ imageData.url :
+ nconf.get('relative_path') + imageData.url,
+ };
}
diff --git a/src/controllers/index.js b/src/controllers/index.js
index abea35d516..55465fa89f 100644
--- a/src/controllers/index.js
+++ b/src/controllers/index.js
@@ -1,15 +1,14 @@
'use strict';
-const path = require('path');
const nconf = require('nconf');
const mime = require('mime').default;
const meta = require('../meta');
const user = require('../user');
const plugins = require('../plugins');
-const image = require('../image');
const privilegesHelpers = require('../privileges/helpers');
const helpers = require('./helpers');
+const utils = require('../utils');
const Controllers = module.exports;
@@ -286,17 +285,17 @@ Controllers.manifest = async function (req, res) {
};
if (meta.config['brand:screenshot']) {
- let sizes;
- try {
- const { width, height } = await image.size(path.join(nconf.get('base_dir'), meta.config['brand:screenshot'].replace('assets', 'public')));
- sizes = `${width}x${height}`;
- } catch (e) {
- // noop
- }
+ const width = meta.config['brand:screenshot:width'];
+ const height = meta.config['brand:screenshot:height'];
+ const sizes = width && height ? `${width}x${height}` : '';
+ const screenshotSrc = utils.cacheBustedUrl(
+ meta.config['brand:screenshot'],
+ meta.config['brand:screenshot:updatedAt']
+ );
manifest.screenshots = [
{
- src: `${nconf.get('relative_path')}${meta.config['brand:screenshot']}`,
- ...(sizes && { sizes }),
+ src: `${nconf.get('relative_path')}${screenshotSrc}`,
+ sizes: sizes || '',
type: mime.getType(meta.config['brand:screenshot']),
},
];
@@ -312,86 +311,33 @@ Controllers.manifest = async function (req, res) {
];
}
- if (meta.config['brand:touchIcon']) {
- manifest.icons.push({
- src: `${nconf.get('relative_path')}/assets/uploads/system/touchicon-36.png`,
- sizes: '36x36',
- type: 'image/png',
- density: 0.75,
- }, {
- src: `${nconf.get('relative_path')}/assets/uploads/system/touchicon-48.png`,
- sizes: '48x48',
- type: 'image/png',
- density: 1.0,
- }, {
- src: `${nconf.get('relative_path')}/assets/uploads/system/touchicon-72.png`,
- sizes: '72x72',
- type: 'image/png',
- density: 1.5,
- }, {
- src: `${nconf.get('relative_path')}/assets/uploads/system/touchicon-96.png`,
- sizes: '96x96',
- type: 'image/png',
- density: 2.0,
- }, {
- src: `${nconf.get('relative_path')}/assets/uploads/system/touchicon-144.png`,
- sizes: '144x144',
- type: 'image/png',
- density: 3.0,
- }, {
- src: `${nconf.get('relative_path')}/assets/uploads/system/touchicon-192.png`,
- sizes: '192x192',
- type: 'image/png',
- density: 4.0,
- }, {
- src: `${nconf.get('relative_path')}/assets/uploads/system/touchicon-512.png`,
- sizes: '512x512',
- type: 'image/png',
- density: 10.0,
- });
- } else {
+ const custom = meta.config['brand:touchIcon'];
+ const basePath = custom ?
+ `${nconf.get('relative_path')}/assets/uploads/system` :
+ `${nconf.get('relative_path')}/assets/images/touch`;
+
+ const sizes = [36, 48, 72, 96, 144, 192, 512];
+ const densities = [0.75, 1, 1.5, 2, 3, 4, 10];
+
+ sizes.forEach((size, index) => {
+ const src = custom ?
+ utils.cacheBustedUrl(`touchicon-${size}.png`, meta.config['brand:touchIcon:updatedAt']) :
+ `${size}.png`;
manifest.icons.push({
- src: `${nconf.get('relative_path')}/assets/images/touch/36.png`,
- sizes: '36x36',
- type: 'image/png',
- density: 0.75,
- }, {
- src: `${nconf.get('relative_path')}/assets/images/touch/48.png`,
- sizes: '48x48',
- type: 'image/png',
- density: 1.0,
- }, {
- src: `${nconf.get('relative_path')}/assets/images/touch/72.png`,
- sizes: '72x72',
- type: 'image/png',
- density: 1.5,
- }, {
- src: `${nconf.get('relative_path')}/assets/images/touch/96.png`,
- sizes: '96x96',
- type: 'image/png',
- density: 2.0,
- }, {
- src: `${nconf.get('relative_path')}/assets/images/touch/144.png`,
- sizes: '144x144',
- type: 'image/png',
- density: 3.0,
- }, {
- src: `${nconf.get('relative_path')}/assets/images/touch/192.png`,
- sizes: '192x192',
+ src: `${basePath}/${src}`,
+ sizes: `${size}x${size}`,
type: 'image/png',
- density: 4.0,
- }, {
- src: `${nconf.get('relative_path')}/assets/images/touch/512.png`,
- sizes: '512x512',
- type: 'image/png',
- density: 10.0,
+ density: densities[index],
});
- }
-
+ });
if (meta.config['brand:maskableIcon']) {
+ const maskableIconSrc = utils.cacheBustedUrl(
+ `/assets/uploads/system/maskableicon-orig.png`,
+ meta.config['brand:maskableIcon:updatedAt']
+ );
manifest.icons.push({
- src: `${nconf.get('relative_path')}/assets/uploads/system/maskableicon-orig.png`,
+ src: `${nconf.get('relative_path')}${maskableIconSrc}`,
sizes: '512x512',
type: 'image/png',
purpose: 'maskable',
diff --git a/src/groups/cover.js b/src/groups/cover.js
index 020f14314e..1eb36ffe4f 100644
--- a/src/groups/cover.js
+++ b/src/groups/cover.js
@@ -33,49 +33,56 @@ module.exports = function (Groups) {
tempPath = await image.writeImageDataToTempFile(data.imageData);
}
- const filename = `groupCover-${data.groupName}${path.extname(tempPath)}`;
+ await deleteCover(data.groupName);
+
+ const filename = `groupCover-${data.groupName}-${Date.now()}${path.extname(tempPath)}`;
const uploadData = await image.uploadImage(filename, 'files', {
path: tempPath,
uid: uid,
name: 'groupCover',
});
- const { url } = uploadData;
- await Groups.setGroupField(data.groupName, 'cover:url', url);
await image.resizeImage({
path: tempPath,
type: type,
width: 358,
});
- const thumbUploadData = await image.uploadImage(`groupCoverThumb-${data.groupName}${path.extname(tempPath)}`, 'files', {
+ const thumbFilename = `groupCoverThumb-${data.groupName}-${Date.now()}${path.extname(tempPath)}`;
+ const thumbUploadData = await image.uploadImage(thumbFilename, 'files', {
path: tempPath,
uid: uid,
name: 'groupCover',
});
- await Groups.setGroupField(data.groupName, 'cover:thumb:url', thumbUploadData.url);
- if (data.position) {
- await Groups.updateCoverPosition(data.groupName, data.position);
- }
+ await Groups.setGroupFields(data.groupName, {
+ 'cover:url': uploadData.url,
+ 'cover:thumb:url': thumbUploadData.url,
+ ...(data.position ? { 'cover:position': data.position } : {}),
+ });
- return { url: url };
+ return { url: uploadData.url };
} finally {
file.delete(tempPath);
}
};
Groups.removeCover = async function (data) {
+ await deleteCover(data.groupName);
+ await db.deleteObjectFields(`group:${data.groupName}`, ['cover:url', 'cover:thumb:url', 'cover:position']);
+ };
+
+ async function deleteCover(groupName) {
const fields = ['cover:url', 'cover:thumb:url'];
- const values = await Groups.getGroupFields(data.groupName, fields);
- await Promise.all(fields.map((field) => {
+ const values = await Groups.getGroupFields(groupName, fields);
+ await Promise.all(fields.map(async (field) => {
if (!values[field] || !values[field].startsWith(`${nconf.get('relative_path')}/assets/uploads/files/`)) {
return;
}
const filename = values[field].split('/').pop();
const filePath = path.join(nconf.get('upload_path'), 'files', filename);
- return file.delete(filePath);
+ if (file.isPathInside(nconf.get('upload_path'), filePath)) {
+ await file.delete(filePath);
+ }
}));
-
- await db.deleteObjectFields(`group:${data.groupName}`, ['cover:url', 'cover:thumb:url', 'cover:position']);
- };
+ }
};
diff --git a/src/groups/data.js b/src/groups/data.js
index 822affa05b..d193e27d2f 100644
--- a/src/groups/data.js
+++ b/src/groups/data.js
@@ -66,7 +66,14 @@ module.exports = function (Groups) {
Groups.setGroupField = async function (groupName, field, value) {
await db.setObjectField(`group:${groupName}`, field, value);
- plugins.hooks.fire('action:group.set', { field: field, value: value, type: 'set' });
+ plugins.hooks.fire('action:group.set', { groupName, field, value, type: 'set' });
+ };
+
+ Groups.setGroupFields = async function (groupName, data) {
+ await db.setObject(`group:${groupName}`, data);
+ for (const [field, value] of Object.entries(data)) {
+ plugins.hooks.fire('action:group.set', { groupName, field, value, type: 'set' });
+ }
};
async function modifyGroups(groups, fields) {
diff --git a/src/meta/tags.js b/src/meta/tags.js
index eaaf0a487a..74a20c707a 100644
--- a/src/meta/tags.js
+++ b/src/meta/tags.js
@@ -4,6 +4,7 @@ const nconf = require('nconf');
const winston = require('winston');
const plugins = require('../plugins');
+const utils = require('../utils');
const Meta = require('./index');
@@ -48,18 +49,19 @@ Tags.parse = async (req, data, meta, link) => {
if (Meta.config['brand:logo'] && !isAPI) {
defaultTags.push({
name: 'msapplication-square150x150logo',
- content: Meta.config['brand:logo'],
+ content: utils.cacheBustedUrl(Meta.config['brand:logo'], Meta.config['brand:logo:updatedAt']),
});
}
- const faviconPath = Meta.config['brand:favicon'] || `${relative_path}/assets/uploads/system/favicon.ico`;
- const cacheBuster = Meta.config['cache-buster'] || '';
+ const faviconPath = Meta.config['brand:favicon'] ?
+ utils.cacheBustedUrl(Meta.config['brand:favicon'], Meta.config['brand:favicon:updatedAt']) :
+ `${relative_path}/assets/uploads/system/favicon.ico`;
// Link Tags
const defaultLinks = isAPI ? [] : [{
rel: 'icon',
type: 'image/x-icon',
- href: `${faviconPath}${cacheBuster ? `?${cacheBuster}` : ''}`,
+ href: faviconPath,
}, {
rel: 'manifest',
href: `${relative_path}/manifest.webmanifest`,
@@ -110,69 +112,31 @@ Tags.parse = async (req, data, meta, link) => {
};
function addTouchIcons(defaultLinks) {
- if (Meta.config['brand:touchIcon']) {
- defaultLinks.push({
- rel: 'apple-touch-icon',
- href: `${relative_path + upload_url}/system/touchicon-orig.png`,
- }, {
- rel: 'icon',
- sizes: '36x36',
- href: `${relative_path + upload_url}/system/touchicon-36.png`,
- }, {
- rel: 'icon',
- sizes: '48x48',
- href: `${relative_path + upload_url}/system/touchicon-48.png`,
- }, {
- rel: 'icon',
- sizes: '72x72',
- href: `${relative_path + upload_url}/system/touchicon-72.png`,
- }, {
- rel: 'icon',
- sizes: '96x96',
- href: `${relative_path + upload_url}/system/touchicon-96.png`,
- }, {
- rel: 'icon',
- sizes: '144x144',
- href: `${relative_path + upload_url}/system/touchicon-144.png`,
- }, {
- rel: 'icon',
- sizes: '192x192',
- href: `${relative_path + upload_url}/system/touchicon-192.png`,
- });
- } else {
- defaultLinks.push({
- rel: 'apple-touch-icon',
- href: `${relative_path}/assets/images/touch/512.png`,
- }, {
- rel: 'icon',
- sizes: '36x36',
- href: `${relative_path}/assets/images/touch/36.png`,
- }, {
- rel: 'icon',
- sizes: '48x48',
- href: `${relative_path}/assets/images/touch/48.png`,
- }, {
- rel: 'icon',
- sizes: '72x72',
- href: `${relative_path}/assets/images/touch/72.png`,
- }, {
- rel: 'icon',
- sizes: '96x96',
- href: `${relative_path}/assets/images/touch/96.png`,
- }, {
- rel: 'icon',
- sizes: '144x144',
- href: `${relative_path}/assets/images/touch/144.png`,
- }, {
- rel: 'icon',
- sizes: '192x192',
- href: `${relative_path}/assets/images/touch/192.png`,
- }, {
- rel: 'icon',
- sizes: '512x512',
- href: `${relative_path}/assets/images/touch/512.png`,
- });
- }
+ const custom = Meta.config['brand:touchIcon'];
+ const updatedAt = Meta.config['brand:touchIcon:updatedAt'];
+
+ const config = custom ? {
+ basePath: `${relative_path + upload_url}/system`,
+ appleIcon: 'touchicon-orig.png',
+ sizes: [36, 48, 72, 96, 144, 192],
+ name: size => utils.cacheBustedUrl(`touchicon-${size}.png`, updatedAt),
+ } : {
+ basePath: `${relative_path}/assets/images/touch`,
+ appleIcon: '512.png',
+ sizes: [36, 48, 72, 96, 144, 192, 512],
+ name: size => `${size}.png`,
+ };
+
+ defaultLinks.push({
+ rel: 'apple-touch-icon',
+ href: `${config.basePath}/${config.appleIcon}`,
+ });
+
+ config.sizes.forEach(size => defaultLinks.push({
+ rel: 'icon',
+ sizes: `${size}x${size}`,
+ href: `${config.basePath}/${config.name(size)}`,
+ }));
}
function addIfNotExists(meta, keyName, tagName, value) {
@@ -201,6 +165,8 @@ async function addSiteOGImage(meta) {
ogImage = url + ogImage;
}
+ ogImage = utils.cacheBustedUrl(ogImage, Meta.config[`${key}:updatedAt`]);
+
const { images } = await plugins.hooks.fire('filter:meta.addSiteOGImage', {
images: [{
url: ogImage || `${url}/assets/images/[email protected]`,
diff --git a/src/middleware/render.js b/src/middleware/render.js
index 3b80500734..d2eab67aa3 100644
--- a/src/middleware/render.js
+++ b/src/middleware/render.js
@@ -160,6 +160,7 @@ module.exports = function (middleware) {
'brand:logo:url': meta.config['brand:logo:url'] || '',
'brand:logo:alt': meta.config['brand:logo:alt'] || '',
'brand:logo:display': meta.config['brand:logo'] ? '' : 'hide',
+ 'brand:logo:updatedAt': meta.config['brand:logo:updatedAt'] || '',
allowRegistration: registrationType === 'normal',
searchEnabled: plugins.hooks.hasListeners('filter:search.query'),
postQueueEnabled: !!meta.config.postQueue,
diff --git a/src/notifications.js b/src/notifications.js
index 026de53f9c..aebc6fbca7 100644
--- a/src/notifications.js
+++ b/src/notifications.js
@@ -145,7 +145,9 @@ Notifications.getMultiple = async function (nids) {
notification.bodyShort = notification.bodyShort.replace(/([\s\S]*?),[\s\S]*?,([\s\S]*?)/, '$1, [[global:guest]], $2');
}
} else if (notification.image === 'brand:logo' || !notification.image) {
- notification.image = meta.config['brand:logo'] || `${nconf.get('relative_path')}/assets/logo.png`;
+ notification.image = meta.config['brand:logo'] ?
+ utils.cacheBustedUrl(meta.config['brand:logo'], meta.config['brand:logo:updatedAt']) :
+ `${nconf.get('relative_path')}/assets/logo.png`;
}
}
});
diff --git a/src/user/data.js b/src/user/data.js
index ffa5ddf7a7..d7857bb0a9 100644
--- a/src/user/data.js
+++ b/src/user/data.js
@@ -498,7 +498,8 @@ module.exports = function (User) {
if (!meta.config.defaultAvatar) {
return '';
}
- return meta.config.defaultAvatar.startsWith('http') ? meta.config.defaultAvatar : relative_path + meta.config.defaultAvatar;
+ const src = utils.cacheBustedUrl(meta.config.defaultAvatar, meta.config['defaultAvatar:updatedAt']);
+ return src.startsWith('http') ? src : relative_path + src;
};
User.setUserField = async function (uid, field, value) {
diff --git a/src/user/picture.js b/src/user/picture.js
index e97d46609e..c379705422 100644
--- a/src/user/picture.js
+++ b/src/user/picture.js
@@ -56,11 +56,10 @@ module.exports = function (User) {
await deletePicture(data.uid, 'cover:url');
}
- await User.setUserField(data.uid, 'cover:url', uploadData.url);
-
- if (data.position) {
- await User.updateCoverPosition(data.uid, data.position);
- }
+ await User.setUserFields(data.uid, {
+ 'cover:url': uploadData.url,
+ ...(data.position ? { 'cover:position': data.position } : {}),
+ });
return {
url: uploadData.url,
@@ -267,7 +266,9 @@ module.exports = function (User) {
return false;
}
const filename = value.split('/').pop();
- return path.join(nconf.get('upload_path'), `profile/uid-${uid}`, filename);
+ const resolved = path.join(nconf.get('upload_path'), `profile/uid-${uid}`, filename);
+ return file.isPathInside(nconf.get('upload_path'), resolved) ?
+ resolved :
+ false;
}
-
};
diff --git a/src/views/groups/details.tpl b/src/views/groups/details.tpl
index 500c8ef996..f338df145f 100644
--- a/src/views/groups/details.tpl
+++ b/src/views/groups/details.tpl
@@ -1,5 +1,5 @@
<div component="groups/container" class="groups details flex-fill">
- <div class="cover position-absolute start-0 top-0" component="groups/cover" style="background-image: url({group.cover:url}?{config.cache-buster}); background-position: {group.cover:position};">
+ <div class="cover position-absolute start-0 top-0" component="groups/cover" style="background-image: url({group.cover:url}); background-position: {group.cover:position};">
<div class="container">
{{{ if group.isOwner }}}
<div class="controls text-center">