cleaning
This commit is contained in:
@@ -99,7 +99,6 @@ api.get('/export/:type', exportController.export)
|
|||||||
|
|
||||||
// get events in this range
|
// get events in this range
|
||||||
api.get('/event/:month/:year', eventController.getAll)
|
api.get('/event/:month/:year', eventController.getAll)
|
||||||
// api.get('/event/:month/:year', eventController.getAfter)
|
|
||||||
|
|
||||||
// Handle 404
|
// Handle 404
|
||||||
api.use(function(req, res) {
|
api.use(function(req, res) {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ module.exports = {
|
|||||||
if (typeof body.object !== 'string') return
|
if (typeof body.object !== 'string') return
|
||||||
const username = body.object.replace(`${config.baseurl}/federation/u/`, '')
|
const username = body.object.replace(`${config.baseurl}/federation/u/`, '')
|
||||||
const user = await User.findOne({ where: { username }})
|
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
|
// check for duplicate
|
||||||
if (user.followers.indexOf(body.actor) === -1) {
|
if (user.followers.indexOf(body.actor) === -1) {
|
||||||
|
|||||||
@@ -70,10 +70,12 @@ const Helpers = {
|
|||||||
// try with cache first if not forced
|
// try with cache first if not forced
|
||||||
if (!force && actorCache[url]) return actorCache[url]
|
if (!force && actorCache[url]) return actorCache[url]
|
||||||
const user = await fetch(url, { headers: {'Accept': 'application/jrd+json, application/json'} })
|
const user = await fetch(url, { headers: {'Accept': 'application/jrd+json, application/json'} })
|
||||||
.then(res => res.json())
|
.then(res => {
|
||||||
.catch(e => {
|
if (!res.ok) {
|
||||||
debug(e)
|
debug('[ERR] Actor %s => %s', url, res.statusText)
|
||||||
return false
|
return false
|
||||||
|
}
|
||||||
|
return res.json()
|
||||||
})
|
})
|
||||||
actorCache[url] = user
|
actorCache[url] = user
|
||||||
return user
|
return user
|
||||||
@@ -82,7 +84,7 @@ const Helpers = {
|
|||||||
// ref: https://blog.joinmastodon.org/2018/07/how-to-make-friends-and-verify-requests/
|
// ref: https://blog.joinmastodon.org/2018/07/how-to-make-friends-and-verify-requests/
|
||||||
async verifySignature(req, res, next) {
|
async verifySignature(req, res, next) {
|
||||||
let user = await Helpers.getActor(req.body.actor)
|
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
|
// little hack -> https://github.com/joyent/node-http-signature/pull/83
|
||||||
req.headers.authorization = 'Signature ' + req.headers.signature
|
req.headers.authorization = 'Signature ' + req.headers.signature
|
||||||
@@ -95,6 +97,7 @@ const Helpers = {
|
|||||||
|
|
||||||
// signature not valid, try without cache
|
// signature not valid, try without cache
|
||||||
user = await Helpers.getActor(req.body.actor, true)
|
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()
|
if (httpSignature.verifySignature(parsed, user.publicKey.publicKeyPem)) return next()
|
||||||
|
|
||||||
// still not valid
|
// still not valid
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ router.post('/u/:name/inbox', Helpers.verifySignature, async (req, res) => {
|
|||||||
// this is a reply
|
// this is a reply
|
||||||
if (b.object.type === 'Note' && b.object.inReplyTo) {
|
if (b.object.type === 'Note' && b.object.inReplyTo) {
|
||||||
await Comments.create(b)
|
await Comments.create(b)
|
||||||
res.sendStatus(201)
|
res.status(201).send()
|
||||||
} else {
|
} else {
|
||||||
console.error('Create what? ', b.object.type)
|
console.error('Create what? ', b.object.type)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user