fix: accidental overwrite of hoisted internal variable

This commit is contained in:
Julian Lam
2024-02-14 11:56:21 -05:00
parent 5c04e8051c
commit 56cfae0766
3 changed files with 16 additions and 11 deletions

View File

@@ -57,16 +57,18 @@ module.exports = function (Posts) {
}; };
function modifyPost(post, fields) { function modifyPost(post, fields) {
const _intFields = [...intFields];
if (post) { if (post) {
if (activitypub.helpers.isUri(post.pid)) { if (activitypub.helpers.isUri(post.pid)) {
intFields.splice(intFields.indexOf('pid'), 1); _intFields.splice(_intFields.indexOf('pid'), 1);
intFields.splice(intFields.indexOf('uid'), 1); _intFields.splice(_intFields.indexOf('uid'), 1);
intFields.splice(intFields.indexOf('tid'), 1); _intFields.splice(_intFields.indexOf('tid'), 1);
} }
if (activitypub.helpers.isUri(post.toPid)) { if (activitypub.helpers.isUri(post.toPid)) {
intFields.splice(intFields.indexOf('toPid'), 1); _intFields.splice(_intFields.indexOf('toPid'), 1);
} }
db.parseIntFields(post, intFields, fields); 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;
} }

View File

@@ -95,12 +95,13 @@ function modifyTopic(topic, fields) {
return; return;
} }
const _intFields = [...intFields];
if (validator.isUUID(String(topic.tid))) { if (validator.isUUID(String(topic.tid))) {
intFields.splice(intFields.indexOf('uid'), 1); _intFields.splice(_intFields.indexOf('uid'), 1);
intFields.splice(intFields.indexOf('tid'), 1); _intFields.splice(_intFields.indexOf('tid'), 1);
intFields.splice(intFields.indexOf('mainPid'), 1); _intFields.splice(_intFields.indexOf('mainPid'), 1);
} }
db.parseIntFields(topic, intFields, fields); db.parseIntFields(topic, _intFields, fields);
if (topic.hasOwnProperty('title')) { if (topic.hasOwnProperty('title')) {
topic.titleRaw = topic.title; topic.titleRaw = topic.title;

View File

@@ -205,10 +205,12 @@ module.exports = function (User) {
return; return;
} }
const _intFields = [...intFields];
if (activitypub.helpers.isUri(user.uid)) { if (activitypub.helpers.isUri(user.uid)) {
intFields.splice(intFields.indexOf('uid'), 1); _intFields.splice(_intFields.indexOf('uid'), 1);
} }
db.parseIntFields(user, intFields, requestedFields); db.parseIntFields(user, _intFields, requestedFields);
if (user.hasOwnProperty('username')) { if (user.hasOwnProperty('username')) {
parseDisplayName(user, uidToSettings); parseDisplayName(user, uidToSettings);