diff --git a/api/src/api.js b/api/src/api.js index f4d251c..d63ede6 100644 --- a/api/src/api.js +++ b/api/src/api.js @@ -3,4 +3,5 @@ module.exports = { auth: require('./api/auth.js'), feed: require('./api/feed.js'), accounts: require('./api/accounts.js'), + me: require('./api/me.js'), } diff --git a/api/src/api/me.js b/api/src/api/me.js new file mode 100644 index 0000000..de0be22 --- /dev/null +++ b/api/src/api/me.js @@ -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) + }], + }, +} diff --git a/api/src/server.js b/api/src/server.js index 6505eb6..133c67c 100644 --- a/api/src/server.js +++ b/api/src/server.js @@ -33,7 +33,7 @@ global.apex = ActivitypubExpress({ activityParam: 'id', routes }) -const api = require('./api.js') +global.api = require('./api.js') const client = db.conn() // extensions for express @@ -64,11 +64,12 @@ app.on('apex-outbox', activity.federation.outbox) app.on('apex-inbox', activity.federation.inbox) // API defines -app.route(api.url('/auth/register')).post(api.auth.register.post) -app.route(api.url('/auth/login')).post(api.auth.login.post) -app.route(api.url('/feed/meet')).get(api.feed.meet.get) -app.route(api.url('/accounts/follow')).post(api.accounts.follow.post) -app.route(api.url('/accounts/unfollow')).post(api.accounts.unfollow.post) +/* POST */ app.route(api.url('/auth/register')).post(api.auth.register.post) +/* POST */ app.route(api.url('/auth/login')).post(api.auth.login.post) +/* GET */ app.route(api.url('/feed/meet')).get(api.feed.meet.get) +/* GET */ app.route(api.url('/me/pending_follows')).get(api.me.pending_follows.get) +/* 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 client.connect({ useNewUrlParser: true })