paricafe/src/server/activitypub/inbox.ts

33 lines
622 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-04 13:21:11 -05:00
import { createHttp } from '../../queue';
2018-04-01 01:58:49 -05:00
2018-04-05 03:52:46 -05:00
const app = express.Router();
2018-04-01 01:58:49 -05:00
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);
}
2018-04-04 13:21:11 -05:00
createHttp({
2018-04-02 04:36:47 -05:00
type: 'processInbox',
2018-04-04 09:12:35 -05:00
activity: req.body,
2018-04-02 04:36:47 -05:00
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;