paricafe/src/server/activitypub/inbox.ts

35 lines
643 B
TypeScript
Raw Normal View History

2018-04-01 01:58:49 -05:00
import * as bodyParser from 'body-parser';
import * as express from 'express';
2018-04-02 04:36:47 -05:00
import { parseRequest } from 'http-signature';
2018-04-01 01:58:49 -05:00
import queue from '../../queue';
const app = express();
2018-04-02 03:11:14 -05:00
2018-04-01 01:58:49 -05:00
app.disable('x-powered-by');
2018-04-02 03:11:14 -05:00
app.post('/@:user/inbox', bodyParser.json({
type() {
return true;
}
}), async (req, res) => {
2018-04-02 04:36:47 -05:00
let signature;
2018-04-01 01:58:49 -05:00
req.headers.authorization = 'Signature ' + req.headers.signature;
2018-04-01 01:58:49 -05:00
try {
2018-04-02 04:36:47 -05:00
signature = parseRequest(req);
2018-04-01 01:58:49 -05:00
} catch (exception) {
return res.sendStatus(401);
}
queue.create('http', {
2018-04-02 04:36:47 -05:00
type: 'processInbox',
inbox: req.body,
signature,
2018-04-01 01:58:49 -05:00
}).save();
2018-04-01 04:16:47 -05:00
return res.status(202).end();
2018-04-01 01:58:49 -05:00
});
export default app;