This commit is contained in:
les 2019-08-09 00:19:57 +02:00
parent bb32611e73
commit e96880fc92
4 changed files with 10 additions and 8 deletions

View file

@ -99,7 +99,6 @@ api.get('/export/:type', exportController.export)
// get events in this range
api.get('/event/:month/:year', eventController.getAll)
// api.get('/event/:month/:year', eventController.getAfter)
// Handle 404
api.use(function(req, res) {

View file

@ -11,7 +11,7 @@ module.exports = {
if (typeof body.object !== 'string') return
const username = body.object.replace(`${config.baseurl}/federation/u/`, '')
const user = await User.findOne({ where: { username }})
if (!user) return res.sendStatus(404)
if (!user) return res.status(404).send('User not found')
// check for duplicate
if (user.followers.indexOf(body.actor) === -1) {

View file

@ -70,10 +70,12 @@ const Helpers = {
// try with cache first if not forced
if (!force && actorCache[url]) return actorCache[url]
const user = await fetch(url, { headers: {'Accept': 'application/jrd+json, application/json'} })
.then(res => res.json())
.catch(e => {
debug(e)
.then(res => {
if (!res.ok) {
debug('[ERR] Actor %s => %s', url, res.statusText)
return false
}
return res.json()
})
actorCache[url] = user
return user
@ -82,7 +84,7 @@ const Helpers = {
// ref: https://blog.joinmastodon.org/2018/07/how-to-make-friends-and-verify-requests/
async verifySignature(req, res, next) {
let user = await Helpers.getActor(req.body.actor)
if (!user) res.send('Actor not found', 401)
if (!user) return res.send('Actor not found', 401)
// little hack -> https://github.com/joyent/node-http-signature/pull/83
req.headers.authorization = 'Signature ' + req.headers.signature
@ -95,6 +97,7 @@ const Helpers = {
// signature not valid, try without cache
user = await Helpers.getActor(req.body.actor, true)
if (!user) return res.send('Actor not found', 401)
if (httpSignature.verifySignature(parsed, user.publicKey.publicKeyPem)) return next()
// still not valid

View file

@ -63,7 +63,7 @@ router.post('/u/:name/inbox', Helpers.verifySignature, async (req, res) => {
// this is a reply
if (b.object.type === 'Note' && b.object.inReplyTo) {
await Comments.create(b)
res.sendStatus(201)
res.status(201).send()
} else {
console.error('Create what? ', b.object.type)
}