This commit is contained in:
les
2019-09-11 19:12:24 +02:00
parent 93baf01a55
commit 2fe956d117
65 changed files with 762 additions and 721 deletions

View File

@@ -8,25 +8,25 @@ module.exports = {
// follow request from fediverse
async follow (req, res) {
const body = req.body
if (typeof body.object !== 'string') return
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.status(404).send('User not found')
const user = await User.findOne({ where: { username } })
if (!user) { return res.status(404).send('User not found') }
// check for duplicate
if (user.followers.indexOf(body.actor) === -1) {
if (!user.followers.includes(body.actor)) {
await user.update({ followers: [...user.followers, body.actor] })
debug('%s followed by %s (%d)', username, body.actor, user.followers.length)
} else {
debug('duplicate %s followed by %s', username, body.actor)
}
const guid = crypto.randomBytes(16).toString('hex')
let message = {
const message = {
'@context': 'https://www.w3.org/ns/activitystreams',
'id': `${config.baseurl}/federation/${guid}`,
'type': 'Accept',
'actor': `${config.baseurl}/federation/u/${user.username}`,
'object': body,
'object': body
}
Helpers.signAndSend(message, user, body.actor)
res.sendStatus(200)
@@ -36,8 +36,8 @@ module.exports = {
async unfollow (req, res) {
const body = req.body
const username = body.object.object.replace(`${config.baseurl}/federation/u/`, '')
const user = await User.findOne({ where: { username }})
if (!user) return res.status(404).send('User not found')
const user = await User.findOne({ where: { username } })
if (!user) { return res.status(404).send('User not found') }
if (body.actor !== body.object.actor) {
debug('Unfollow an user created by a different actor !?!?')