egirlskey/src/server/activitypub/note.ts

29 lines
728 B
TypeScript
Raw Normal View History

2018-04-01 09:12:51 +00:00
import * as express from 'express';
2018-04-01 19:15:27 +00:00
import context from '../../remote/activitypub/renderer/context';
import render from '../../remote/activitypub/renderer/note';
2018-04-07 17:30:37 +00:00
import Note from '../../models/note';
2018-04-01 09:12:51 +00:00
2018-04-05 08:52:46 +00:00
const app = express.Router();
2018-04-01 09:12:51 +00:00
2018-04-07 21:55:26 +00:00
app.get('/notes/:note', async (req, res, next) => {
2018-04-01 09:12:51 +00:00
const accepted = req.accepts(['html', 'application/activity+json', 'application/ld+json']);
2018-04-01 09:20:17 +00:00
if (!(['application/activity+json', 'application/ld+json'] as any[]).includes(accepted)) {
2018-04-01 09:12:51 +00:00
return next();
}
2018-04-07 17:30:37 +00:00
const note = await Note.findOne({
2018-04-07 21:55:26 +00:00
_id: req.params.note
});
2018-04-07 21:55:26 +00:00
2018-04-07 17:30:37 +00:00
if (note === null) {
return res.sendStatus(404);
}
2018-04-07 21:55:26 +00:00
const rendered = await render(note);
2018-04-01 10:18:36 +00:00
rendered['@context'] = context;
2018-04-01 09:12:51 +00:00
2018-04-01 10:18:36 +00:00
res.json(rendered);
2018-04-01 09:12:51 +00:00
});
export default app;