rudeshark.net/src/server/activitypub/outbox.ts

29 lines
907 B
TypeScript
Raw Normal View History

2018-04-01 12:18:36 +02:00
import * as express from 'express';
2018-04-01 21:15:27 +02:00
import context from '../../remote/activitypub/renderer/context';
import renderNote from '../../remote/activitypub/renderer/note';
import renderOrderedCollection from '../../remote/activitypub/renderer/ordered-collection';
2018-04-02 06:15:53 +02:00
import config from '../../config';
2018-04-07 19:30:37 +02:00
import Note from '../../models/note';
2018-04-08 08:15:22 +02:00
import User from '../../models/user';
2018-04-01 12:18:36 +02:00
2018-04-05 10:52:46 +02:00
const app = express.Router();
2018-04-01 12:18:36 +02:00
2018-04-08 08:15:22 +02:00
app.get('/users/:user/outbox', async (req, res) => {
const userId = req.params.user;
const user = await User.findOne({ _id: userId });
2018-04-07 19:30:37 +02:00
const notes = await Note.find({ userId: user._id }, {
2018-04-01 12:18:36 +02:00
limit: 20,
sort: { _id: -1 }
});
2018-04-07 23:55:26 +02:00
const renderedNotes = await Promise.all(notes.map(note => renderNote(note)));
2018-04-08 08:15:22 +02:00
const rendered = renderOrderedCollection(`${config.url}/users/${userId}/inbox`, user.notesCount, renderedNotes);
2018-04-01 12:18:36 +02:00
rendered['@context'] = context;
res.json(rendered);
2018-04-08 08:15:22 +02:00
});
2018-04-01 12:18:36 +02:00
export default app;