Added API pending_follows (Matches) + some refactoring

This commit is contained in:
Niko 2022-02-16 18:09:36 +01:00
parent c6d48b65a3
commit e3c3bf6b11
3 changed files with 45 additions and 6 deletions

View File

@ -3,4 +3,5 @@ module.exports = {
auth: require('./api/auth.js'), auth: require('./api/auth.js'),
feed: require('./api/feed.js'), feed: require('./api/feed.js'),
accounts: require('./api/accounts.js'), accounts: require('./api/accounts.js'),
me: require('./api/me.js'),
} }

37
api/src/api/me.js Normal file
View File

@ -0,0 +1,37 @@
const auth = require('../auth.js')
module.exports = {
pending_follows: {
get: [auth.enforceSession, async (req, res) => {
let follows
const result = {
from_me: [],
to_me: [],
}
follows = await db.table.objects().find({
actor: apID(res.locals.user.username),
type: 'Follow',
rejected: undefined,
accepted: undefined,
})
for (var i = 0; i < follows.length; i++) {
const account = await api.accounts.getAccount(follows[i].actor)
result.from_me.push(account)
}
follows = await db.table.objects().find({
object: apID(res.locals.user.username),
type: 'Follow',
rejected: undefined,
accepted: undefined,
}).toArray()
for (var i = 0; i < follows.length; i++) {
const account = await api.accounts.getAccount(follows[i].actor)
result.to_me.push(account)
}
return res.json(result)
}],
},
}

View File

@ -33,7 +33,7 @@ global.apex = ActivitypubExpress({
activityParam: 'id', activityParam: 'id',
routes routes
}) })
const api = require('./api.js') global.api = require('./api.js')
const client = db.conn() const client = db.conn()
// extensions for express // extensions for express
@ -64,11 +64,12 @@ app.on('apex-outbox', activity.federation.outbox)
app.on('apex-inbox', activity.federation.inbox) app.on('apex-inbox', activity.federation.inbox)
// API defines // API defines
app.route(api.url('/auth/register')).post(api.auth.register.post) /* POST */ app.route(api.url('/auth/register')).post(api.auth.register.post)
app.route(api.url('/auth/login')).post(api.auth.login.post) /* POST */ app.route(api.url('/auth/login')).post(api.auth.login.post)
app.route(api.url('/feed/meet')).get(api.feed.meet.get) /* GET */ app.route(api.url('/feed/meet')).get(api.feed.meet.get)
app.route(api.url('/accounts/follow')).post(api.accounts.follow.post) /* GET */ app.route(api.url('/me/pending_follows')).get(api.me.pending_follows.get)
app.route(api.url('/accounts/unfollow')).post(api.accounts.unfollow.post) /* POST */ app.route(api.url('/accounts/follow')).post(api.accounts.follow.post)
/* POST */ app.route(api.url('/accounts/unfollow')).post(api.accounts.unfollow.post)
// initialize // initialize
client.connect({ useNewUrlParser: true }) client.connect({ useNewUrlParser: true })