fix paths in topic thumbs
This commit is contained in:
Barış Soner Uşaklı
2026-01-23 17:13:27 -05:00
parent b2c6fbeddb
commit 310e90c782

View File

@@ -1,6 +1,7 @@
'use strict'; 'use strict';
const nconf = require('nconf'); const nconf = require('nconf');
const path = require('path');
const qs = require('querystring'); const qs = require('querystring');
const validator = require('validator'); const validator = require('validator');
@@ -311,17 +312,15 @@ async function addTags(topicData, req, res, currentPage, postAtIndex) {
async function addOGImageTags(res, topicData, postAtIndex) { async function addOGImageTags(res, topicData, postAtIndex) {
const uploads = postAtIndex ? await posts.uploads.listWithSizes(postAtIndex.pid) : []; const uploads = postAtIndex ? await posts.uploads.listWithSizes(postAtIndex.pid) : [];
const images = uploads.map((upload) => { const images = uploads.filter(Boolean);
upload.name = `${url + upload_url}/${upload.name}`;
return upload;
});
if (topicData.thumbs) { if (topicData.thumbs) {
const path = require('path');
const thumbs = topicData.thumbs.filter( const thumbs = topicData.thumbs.filter(
t => t && images.every(img => path.normalize(img.name) !== path.normalize(url + t.url)) t => t && images.every(img => path.normalize(img.name) !== path.normalize(t.path))
); );
images.push(...thumbs.map(thumbObj => ({ name: url + thumbObj.url }))); images.push(...thumbs.map(t => t.path));
} }
if (topicData.category.backgroundImage && (!postAtIndex || !postAtIndex.index)) { if (topicData.category.backgroundImage && (!postAtIndex || !postAtIndex.index)) {
images.push(topicData.category.backgroundImage); images.push(topicData.category.backgroundImage);
} }
@@ -332,13 +331,15 @@ async function addOGImageTags(res, topicData, postAtIndex) {
} }
function addOGImageTag(res, image) { function addOGImageTag(res, image) {
let imageUrl; const isObject = typeof image === 'object' && image.name;
if (typeof image === 'string' && !image.startsWith('http')) { let imageUrl = isObject ? image.name : image;
imageUrl = url + image.replace(new RegExp(`^${relative_path}`), ''); if (!(typeof imageUrl === 'string')) {
} else if (typeof image === 'object') { return;
imageUrl = image.name; }
} else {
imageUrl = image; if (!imageUrl.startsWith('http')) {
// (https://domain.com/forum) + (/assets/uploads) + (imagePath)
imageUrl = path.posix.join(url, upload_url, imageUrl);
} }
res.locals.metaTags.push({ res.locals.metaTags.push({
@@ -351,7 +352,7 @@ function addOGImageTag(res, image) {
noEscape: true, noEscape: true,
}); });
if (typeof image === 'object' && image.width && image.height) { if (isObject && image.width && image.height) {
res.locals.metaTags.push({ res.locals.metaTags.push({
property: 'og:image:width', property: 'og:image:width',
content: String(image.width), content: String(image.width),