mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-30 02:25:55 +01:00
fix: remove intFields hack and update db.parseIntFields to only parseInt if field value is a number
This commit is contained in:
@@ -11,11 +11,14 @@ if (!databaseName) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const primaryDB = require(`./${databaseName}`);
|
const primaryDB = require(`./${databaseName}`);
|
||||||
|
const utils = require('../utils');
|
||||||
|
|
||||||
primaryDB.parseIntFields = function (data, intFields, requestedFields) {
|
primaryDB.parseIntFields = function (data, intFields, requestedFields) {
|
||||||
intFields.forEach((field) => {
|
intFields.forEach((field) => {
|
||||||
if (!requestedFields || !requestedFields.length || requestedFields.includes(field)) {
|
if (!requestedFields || !requestedFields.length || requestedFields.includes(field)) {
|
||||||
data[field] = parseInt(data[field], 10) || 0;
|
data[field] = utils.isNumber(data[field]) ?
|
||||||
|
parseInt(data[field], 10) || 0 :
|
||||||
|
data[field];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -59,19 +59,8 @@ module.exports = function (Posts) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function modifyPost(post, fields) {
|
function modifyPost(post, fields) {
|
||||||
const _intFields = [...intFields];
|
|
||||||
|
|
||||||
if (post) {
|
if (post) {
|
||||||
['pid', 'uid', 'tid'].forEach((prop) => {
|
db.parseIntFields(post, intFields, fields);
|
||||||
if (
|
|
||||||
post.hasOwnProperty(prop) &&
|
|
||||||
(activitypub.helpers.isUri(post[prop]) || validator.isUUID(String(post[prop])))
|
|
||||||
) {
|
|
||||||
_intFields.splice(_intFields.indexOf(prop), 1);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
db.parseIntFields(post, _intFields, fields);
|
|
||||||
if (post.hasOwnProperty('upvotes') && post.hasOwnProperty('downvotes')) {
|
if (post.hasOwnProperty('upvotes') && post.hasOwnProperty('downvotes')) {
|
||||||
post.votes = post.upvotes - post.downvotes;
|
post.votes = post.upvotes - post.downvotes;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,13 +95,7 @@ function modifyTopic(topic, fields) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const _intFields = [...intFields];
|
db.parseIntFields(topic, intFields, fields);
|
||||||
if (validator.isUUID(String(topic.tid))) {
|
|
||||||
_intFields.splice(_intFields.indexOf('uid'), 1);
|
|
||||||
_intFields.splice(_intFields.indexOf('tid'), 1);
|
|
||||||
_intFields.splice(_intFields.indexOf('mainPid'), 1);
|
|
||||||
}
|
|
||||||
db.parseIntFields(topic, _intFields, fields);
|
|
||||||
|
|
||||||
if (topic.hasOwnProperty('title')) {
|
if (topic.hasOwnProperty('title')) {
|
||||||
topic.titleRaw = topic.title;
|
topic.titleRaw = topic.title;
|
||||||
|
|||||||
@@ -246,9 +246,12 @@ module.exports = function (Topics) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Topics.addPostToTopic = async function (tid, postData) {
|
Topics.addPostToTopic = async function (tid, postData) {
|
||||||
|
console.log('now in addPostToTopic', tid, postData);
|
||||||
const mainPid = await Topics.getTopicField(tid, 'mainPid');
|
const mainPid = await Topics.getTopicField(tid, 'mainPid');
|
||||||
|
console.log(mainPid);
|
||||||
if (!mainPid) {
|
if (!mainPid) {
|
||||||
await Topics.setTopicField(tid, 'mainPid', postData.pid);
|
await Topics.setTopicField(tid, 'mainPid', postData.pid);
|
||||||
|
console.log('what');
|
||||||
} else {
|
} else {
|
||||||
const upvotes = parseInt(postData.upvotes, 10) || 0;
|
const upvotes = parseInt(postData.upvotes, 10) || 0;
|
||||||
const downvotes = parseInt(postData.downvotes, 10) || 0;
|
const downvotes = parseInt(postData.downvotes, 10) || 0;
|
||||||
|
|||||||
@@ -205,12 +205,7 @@ module.exports = function (User) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const _intFields = [...intFields];
|
db.parseIntFields(user, intFields, requestedFields);
|
||||||
|
|
||||||
if (activitypub.helpers.isUri(user.uid)) {
|
|
||||||
_intFields.splice(_intFields.indexOf('uid'), 1);
|
|
||||||
}
|
|
||||||
db.parseIntFields(user, _intFields, requestedFields);
|
|
||||||
|
|
||||||
if (user.hasOwnProperty('username')) {
|
if (user.hasOwnProperty('username')) {
|
||||||
parseDisplayName(user, uidToSettings);
|
parseDisplayName(user, uidToSettings);
|
||||||
|
|||||||
Reference in New Issue
Block a user