improve logging

This commit is contained in:
les
2021-04-28 12:44:26 +02:00
parent f7ba790398
commit 5f8bbd68c8
16 changed files with 63 additions and 39 deletions

View File

@@ -6,7 +6,7 @@ module.exports = {
async boost (req, res) {
const match = req.body.object.match(`${config.baseurl}/federation/m/(.*)`)
if (!match || match.length < 2) { return res.status(404).send('Event not found!') }
log.debug(`boost ${match[1]}`)
log.info(`boost ${match[1]}`)
const event = await Event.findByPk(Number(match[1]))
if (!event) { return res.status(404).send('Event not found!') }
// TODO, has to be unique...
@@ -17,7 +17,7 @@ module.exports = {
async unboost (req, res) {
const match = req.body.object.match(`${config.baseurl}/federation/m/(.*)`)
if (!match || match.length < 2) { return res.status(404).send('Event not found!') }
log.debug(`unboost ${match[1]}`)
log.info(`unboost ${match[1]}`)
const event = await Event.findByPk(Number(match[1]))
if (!event) { return res.status(404).send('Event not found!') }
await event.update({ boost: event.boost.filter(actor => actor !== req.body.actor) })
@@ -27,7 +27,7 @@ module.exports = {
const match = req.body.object.match(`${config.baseurl}/federation/m/(.*)`)
if (!match || match.length < 2) { return res.status(404).send('Event not found!') }
const event = await Event.findByPk(Number(match[1]))
log.debug(`${req.body.actor} bookmark ${event.title} (${event.likes.length})`)
log.info(`${req.body.actor} bookmark ${event.title} (${event.likes.length})`)
if (!event) { return res.status(404).send('Event not found!') }
// TODO: has to be unique
await event.update({ likes: [...event.likes, req.body.actor] })
@@ -40,7 +40,7 @@ module.exports = {
const match = object.object.match(`${config.baseurl}/federation/m/(.*)`)
if (!match || match.length < 2) { return res.status(404).send('Event not found!') }
const event = await Event.findByPk(Number(match[1]))
log.debug(`${body.actor} unbookmark ${event.title} (${event.likes.length})`)
log.info(`${body.actor} unbookmark ${event.title} (${event.likes.length})`)
if (!event) { return res.status(404).send('Event not found!') }
await event.update({ likes: event.likes.filter(actor => actor !== body.actor) })
res.sendStatus(201)

View File

@@ -7,7 +7,6 @@ module.exports = {
// follow request from fediverse
async follow (req, res) {
const body = req.body
log.debug('follow')
if (typeof body.object !== 'string') { return }
const username = body.object.replace(`${config.baseurl}/federation/u/`, '')
if (username !== req.settings.instance_name) {
@@ -20,7 +19,7 @@ module.exports = {
// await user.addFollowers([req.fedi_user.id])
// await user.update({ followers: [...user.followers, body.actor] })
await req.fedi_user.update({ follower: true })
log.debug(`Followed by ${body.actor}`)
log.info(`Followed by ${body.actor}`)
const guid = crypto.randomBytes(16).toString('hex')
const message = {
'@context': 'https://www.w3.org/ns/activitystreams',
@@ -43,11 +42,11 @@ module.exports = {
}
if (body.actor !== body.object.actor || body.actor !== req.fedi_user.ap_id) {
log.debug('Unfollow an user created by a different actor !?!?')
log.info('Unfollow an user created by a different actor !?!?')
return res.status(400).send('Bad things')
}
await req.fedi_user.update({ follower: false })
log.debug(`Unfollowed by ${body.actor}`)
log.info(`Unfollowed by ${body.actor}`)
res.sendStatus(200)
}
}

View File

@@ -69,7 +69,7 @@ const Helpers = {
async sendEvent (event, type = 'Create') {
if (!settingsController.settings.enable_federation) {
log.debug('event not send, federation disabled')
log.info('event not send, federation disabled')
return
}
@@ -131,7 +131,7 @@ const Helpers = {
})
if (fedi_user) {
log.debug(`Create a new AP User => ${URL}`)
log.info(`Create a new AP User => ${URL}`)
fedi_user = await APUser.create({ ap_id: URL, object: fedi_user })
}
return fedi_user
@@ -208,13 +208,13 @@ const Helpers = {
// signature not valid, try without cache
user = await Helpers.getActor(req.body.actor, instance, true)
if (!user) {
log.debug(`Actor ${req.body.actor} not found`)
log.info(`Actor ${req.body.actor} not found`)
return res.status(401).send('Actor not found')
}
if (httpSignature.verifySignature(parsed, user.object.publicKey.publicKeyPem)) { return next() }
// still not valid
log.debug(`Invalid signature from user ${req.body.actor}`)
log.info(`Invalid signature from user ${req.body.actor}`)
res.send('Request signature could not be verified', 401)
}
}