summaryrefslogtreecommitdiff
path: root/src/server/activitypub/note.ts
blob: 1c2e695b80b621017629a32ced9288e4a3489f59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import * as express from 'express';
import context from '../../remote/activitypub/renderer/context';
import render from '../../remote/activitypub/renderer/note';
import Note from '../../models/note';

const app = express.Router();

app.get('/notes/:note', async (req, res, next) => {
	const accepted = req.accepts(['html', 'application/activity+json', 'application/ld+json']);
	if (!(['application/activity+json', 'application/ld+json'] as any[]).includes(accepted)) {
		return next();
	}

	const note = await Note.findOne({
		_id: req.params.note
	});

	if (note === null) {
		return res.sendStatus(404);
	}

	const rendered = await render(note);
	rendered['@context'] = context;

	res.json(rendered);
});

export default app;