mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
refactor: remove verbose logs,
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const winston = require('winston');
|
|
||||||
const nconf = require('nconf');
|
const nconf = require('nconf');
|
||||||
|
|
||||||
const db = require('../database');
|
const db = require('../database');
|
||||||
@@ -22,7 +21,9 @@ Actors.assert = async (ids, options = {}) => {
|
|||||||
if (!Array.isArray(ids)) {
|
if (!Array.isArray(ids)) {
|
||||||
ids = [ids];
|
ids = [ids];
|
||||||
}
|
}
|
||||||
|
if (!ids.length) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
// Existance in failure cache is automatic assertion failure
|
// Existance in failure cache is automatic assertion failure
|
||||||
if (ids.some(id => failedWebfingerCache.has(id))) {
|
if (ids.some(id => failedWebfingerCache.has(id))) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const { generateKeyPairSync } = require('crypto');
|
const { generateKeyPairSync } = require('crypto');
|
||||||
const winston = require('winston');
|
|
||||||
const nconf = require('nconf');
|
const nconf = require('nconf');
|
||||||
const validator = require('validator');
|
const validator = require('validator');
|
||||||
const cheerio = require('cheerio');
|
const cheerio = require('cheerio');
|
||||||
@@ -15,7 +14,7 @@ const ttl = require('../cache/ttl');
|
|||||||
const user = require('../user');
|
const user = require('../user');
|
||||||
const activitypub = require('.');
|
const activitypub = require('.');
|
||||||
|
|
||||||
const webfingerRegex = /^(@|acct:)?[\w\-]+@.+$/;
|
const webfingerRegex = /^(@|acct:)?[\w-]+@.+$/;
|
||||||
const webfingerCache = ttl({
|
const webfingerCache = ttl({
|
||||||
max: 5000,
|
max: 5000,
|
||||||
ttl: 1000 * 60 * 60 * 24, // 24 hours
|
ttl: 1000 * 60 * 60 * 24, // 24 hours
|
||||||
|
|||||||
@@ -440,7 +440,10 @@ inbox.undo = async (req) => {
|
|||||||
id = id || object.object; // remote announces
|
id = id || object.object; // remote announces
|
||||||
const exists = await posts.exists(id);
|
const exists = await posts.exists(id);
|
||||||
if (!exists) {
|
if (!exists) {
|
||||||
// winston.verbose(`[activitypub/inbox/undo] Attempted to undo announce of ${id} but couldn't find it, so doing nothing.`);
|
// winston.verbose(
|
||||||
|
// `[activitypub/inbox/undo] Attempted to undo announce of ${id} but couldn't find it, so doing nothing.
|
||||||
|
// `);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
await activitypub.notes.announce.remove(id, actor);
|
await activitypub.notes.announce.remove(id, actor);
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
const nconf = require('nconf');
|
const nconf = require('nconf');
|
||||||
const winston = require('winston');
|
// const winston = require('winston');
|
||||||
|
|
||||||
const db = require('../database');
|
const db = require('../database');
|
||||||
const user = require('../user');
|
const user = require('../user');
|
||||||
@@ -135,7 +135,7 @@ activitypubApi.create.note = enabledCheck(async (caller, { pid }) => {
|
|||||||
|
|
||||||
const allowed = await privileges.posts.can('topics:read', pid, activitypub._constants.uid);
|
const allowed = await privileges.posts.can('topics:read', pid, activitypub._constants.uid);
|
||||||
if (!allowed) {
|
if (!allowed) {
|
||||||
winston.verbose(`[activitypub/api] Not federating creation of pid ${pid} to the fediverse due to privileges.`);
|
// winston.verbose(`[activitypub/api] Not federating creation of pid ${pid} to the fediverse due to privileges.`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -195,7 +195,9 @@ activitypubApi.update.note = enabledCheck(async (caller, { post }) => {
|
|||||||
|
|
||||||
const allowed = await privileges.posts.can('topics:read', post.pid, activitypub._constants.uid);
|
const allowed = await privileges.posts.can('topics:read', post.pid, activitypub._constants.uid);
|
||||||
if (!allowed) {
|
if (!allowed) {
|
||||||
winston.verbose(`[activitypub/api] Not federating update of pid ${post.pid} to the fediverse due to privileges.`);
|
// winston.verbose(
|
||||||
|
// `[activitypub/api] Not federating update of pid ${post.pid} to the fediverse due to privileges.`
|
||||||
|
// );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,7 +227,7 @@ activitypubApi.delete.note = enabledCheck(async (caller, { pid }) => {
|
|||||||
|
|
||||||
const allowed = await privileges.posts.can('topics:read', pid, activitypub._constants.uid);
|
const allowed = await privileges.posts.can('topics:read', pid, activitypub._constants.uid);
|
||||||
if (!allowed) {
|
if (!allowed) {
|
||||||
winston.verbose(`[activitypub/api] Not federating update of pid ${pid} to the fediverse due to privileges.`);
|
// winston.verbose(`[activitypub/api] Not federating update of pid ${pid} to the fediverse due to privileges.`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,30 +31,30 @@ middleware.assertS2S = async function (req, res, next) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
middleware.validate = async function (req, res, next) {
|
middleware.validate = async function (req, res, next) {
|
||||||
winston.verbose('[middleware/activitypub] Validating incoming payload...');
|
// winston.verbose('[middleware/activitypub] Validating incoming payload...');
|
||||||
|
|
||||||
// Sanity-check payload schema
|
// Sanity-check payload schema
|
||||||
const required = ['id', 'type', 'actor', 'object'];
|
const required = ['id', 'type', 'actor', 'object'];
|
||||||
if (!required.every(prop => req.body.hasOwnProperty(prop))) {
|
if (!required.every(prop => req.body.hasOwnProperty(prop))) {
|
||||||
winston.verbose('[middleware/activitypub] Request body missing required properties.');
|
// winston.verbose('[middleware/activitypub] Request body missing required properties.');
|
||||||
return res.sendStatus(400);
|
return res.sendStatus(400);
|
||||||
}
|
}
|
||||||
winston.verbose('[middleware/activitypub] Request body check passed.');
|
// winston.verbose('[middleware/activitypub] Request body check passed.');
|
||||||
|
|
||||||
// History check
|
// History check
|
||||||
const seen = await db.isSortedSetMember('activities:datetime', req.body.id);
|
const seen = await db.isSortedSetMember('activities:datetime', req.body.id);
|
||||||
if (seen) {
|
if (seen) {
|
||||||
winston.verbose(`[middleware/activitypub] Activity already seen, ignoring (${req.body.id}).`);
|
// winston.verbose(`[middleware/activitypub] Activity already seen, ignoring (${req.body.id}).`);
|
||||||
return res.sendStatus(200);
|
return res.sendStatus(200);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checks the validity of the incoming payload against the sender and rejects on failure
|
// Checks the validity of the incoming payload against the sender and rejects on failure
|
||||||
const verified = await activitypub.verify(req);
|
const verified = await activitypub.verify(req);
|
||||||
if (!verified) {
|
if (!verified) {
|
||||||
winston.verbose('[middleware/activitypub] HTTP signature verification failed.');
|
// winston.verbose('[middleware/activitypub] HTTP signature verification failed.');
|
||||||
return res.sendStatus(400);
|
return res.sendStatus(400);
|
||||||
}
|
}
|
||||||
winston.verbose('[middleware/activitypub] HTTP signature verification passed.');
|
// winston.verbose('[middleware/activitypub] HTTP signature verification passed.');
|
||||||
|
|
||||||
let { actor, object } = req.body;
|
let { actor, object } = req.body;
|
||||||
|
|
||||||
@@ -74,10 +74,10 @@ middleware.validate = async function (req, res, next) {
|
|||||||
const objectHostname = new URL(object.id).hostname;
|
const objectHostname = new URL(object.id).hostname;
|
||||||
// require that all actors have the same hostname as the object for now
|
// require that all actors have the same hostname as the object for now
|
||||||
if (!actorHostnames.every(actorHostname => actorHostname === objectHostname)) {
|
if (!actorHostnames.every(actorHostname => actorHostname === objectHostname)) {
|
||||||
winston.verbose('[middleware/activitypub] Origin check failed, stripping object down to id.');
|
// winston.verbose('[middleware/activitypub] Origin check failed, stripping object down to id.');
|
||||||
req.body.object = [object.id];
|
req.body.object = [object.id];
|
||||||
}
|
}
|
||||||
winston.verbose('[middleware/activitypub] Origin check passed.');
|
// winston.verbose('[middleware/activitypub] Origin check passed.');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cross-check key ownership against received actor
|
// Cross-check key ownership against received actor
|
||||||
@@ -89,10 +89,10 @@ middleware.validate = async function (req, res, next) {
|
|||||||
return [v.substring(0, index), v.slice(index + 1)];
|
return [v.substring(0, index), v.slice(index + 1)];
|
||||||
})).get('keyId');
|
})).get('keyId');
|
||||||
if (`"${compare}"` !== keyId) {
|
if (`"${compare}"` !== keyId) {
|
||||||
winston.verbose('[middleware/activitypub] Key ownership cross-check failed.');
|
// winston.verbose('[middleware/activitypub] Key ownership cross-check failed.');
|
||||||
return res.sendStatus(403);
|
return res.sendStatus(403);
|
||||||
}
|
}
|
||||||
winston.verbose('[middleware/activitypub] Key ownership cross-check passed.');
|
// winston.verbose('[middleware/activitypub] Key ownership cross-check passed.');
|
||||||
|
|
||||||
next();
|
next();
|
||||||
};
|
};
|
||||||
@@ -100,12 +100,12 @@ middleware.validate = async function (req, res, next) {
|
|||||||
middleware.resolveObjects = async function (req, res, next) {
|
middleware.resolveObjects = async function (req, res, next) {
|
||||||
const { type, object } = req.body;
|
const { type, object } = req.body;
|
||||||
if (type !== 'Delete' && (typeof object === 'string' || (Array.isArray(object) && object.every(o => typeof o === 'string')))) {
|
if (type !== 'Delete' && (typeof object === 'string' || (Array.isArray(object) && object.every(o => typeof o === 'string')))) {
|
||||||
winston.verbose('[middleware/activitypub] Resolving object(s)...');
|
// winston.verbose('[middleware/activitypub] Resolving object(s)...');
|
||||||
try {
|
try {
|
||||||
req.body.object = await activitypub.helpers.resolveObjects(object);
|
req.body.object = await activitypub.helpers.resolveObjects(object);
|
||||||
winston.verbose('[middleware/activitypub] Object(s) successfully resolved.');
|
// winston.verbose('[middleware/activitypub] Object(s) successfully resolved.');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
winston.verbose('[middleware/activitypub] Failed to resolve object(s).');
|
// winston.verbose('[middleware/activitypub] Failed to resolve object(s).');
|
||||||
return res.sendStatus(424);
|
return res.sendStatus(424);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const winston = require('winston');
|
|
||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
|
|
||||||
const db = require('../database');
|
const db = require('../database');
|
||||||
@@ -52,7 +51,6 @@ Attachments.update = async (pid, attachments) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Attachments.empty = async (pids) => {
|
Attachments.empty = async (pids) => {
|
||||||
winston.verbose(`[posts/attachments] Emptying attachments for ids ${pids.join(', ')}.`);
|
|
||||||
const zsets = pids.map(pid => `post:${pid}:attachments`);
|
const zsets = pids.map(pid => `post:${pid}:attachments`);
|
||||||
const hashes = await db.getSortedSetsMembers(zsets);
|
const hashes = await db.getSortedSetsMembers(zsets);
|
||||||
let keys = hashes.reduce((memo, hashes) => new Set([...memo, ...hashes]), new Set());
|
let keys = hashes.reduce((memo, hashes) => new Set([...memo, ...hashes]), new Set());
|
||||||
|
|||||||
Reference in New Issue
Block a user