fix: parseIntFields for tids

This commit is contained in:
Julian Lam
2024-02-20 14:09:06 -05:00
parent cfbbf4ca86
commit 31fd135f6e

View File

@@ -1,5 +1,7 @@
'use strict'; 'use strict';
const validator = require('validator');
const db = require('../database'); const db = require('../database');
const plugins = require('../plugins'); const plugins = require('../plugins');
const activitypub = require('../activitypub'); const activitypub = require('../activitypub');
@@ -60,14 +62,15 @@ function modifyPost(post, fields) {
const _intFields = [...intFields]; const _intFields = [...intFields];
if (post) { if (post) {
if (activitypub.helpers.isUri(post.pid)) { ['pid', 'uid', 'tid', 'toPid'].forEach((prop) => {
_intFields.splice(_intFields.indexOf('pid'), 1); if (
_intFields.splice(_intFields.indexOf('uid'), 1); post.hasOwnProperty(prop) && post[prop] &&
_intFields.splice(_intFields.indexOf('tid'), 1); (activitypub.helpers.isUri(post[prop]) || validator.isUUID(post[prop]))
} ) {
if (activitypub.helpers.isUri(post.toPid)) { _intFields.splice(_intFields.indexOf(prop), 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;