egirlskey/src/server/activitypub/user.ts

27 lines
749 B
TypeScript
Raw Normal View History

2018-04-01 03:33:26 +00:00
import * as express from 'express';
2018-04-02 04:15:53 +00:00
import config from '../../config';
2018-04-01 19:15:27 +00:00
import context from '../../remote/activitypub/renderer/context';
import render from '../../remote/activitypub/renderer/person';
2018-04-01 11:07:04 +00:00
import withUser from './with-user';
const respond = withUser(username => `${config.url}/@${username}`, (user, req, res) => {
const rendered = render(user);
rendered['@context'] = context;
res.json(rendered);
});
2018-04-05 08:52:46 +00:00
const app = express.Router();
2018-04-01 11:07:04 +00:00
app.get('/@:user', (req, res, next) => {
const accepted = req.accepts(['html', 'application/activity+json', 'application/ld+json']);
2018-04-01 13:09:25 +00:00
if ((['application/activity+json', 'application/ld+json'] as any[]).includes(accepted)) {
2018-04-01 11:07:04 +00:00
respond(req, res, next);
} else {
next();
}
});
export default app;