2018-04-01 15:58:49 +09:00
|
|
|
import * as bodyParser from 'body-parser';
|
|
|
|
import * as express from 'express';
|
2018-04-02 18:36:47 +09:00
|
|
|
import { parseRequest } from 'http-signature';
|
2018-04-05 03:21:11 +09:00
|
|
|
import { createHttp } from '../../queue';
|
2018-04-01 15:58:49 +09:00
|
|
|
|
2018-04-05 17:52:46 +09:00
|
|
|
const app = express.Router();
|
2018-04-01 15:58:49 +09:00
|
|
|
|
2018-04-02 17:11:14 +09:00
|
|
|
app.post('/@:user/inbox', bodyParser.json({
|
|
|
|
type() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}), async (req, res) => {
|
2018-04-02 18:36:47 +09:00
|
|
|
let signature;
|
2018-04-01 15:58:49 +09:00
|
|
|
|
2018-04-02 00:36:36 +09:00
|
|
|
req.headers.authorization = 'Signature ' + req.headers.signature;
|
|
|
|
|
2018-04-01 15:58:49 +09:00
|
|
|
try {
|
2018-04-02 18:36:47 +09:00
|
|
|
signature = parseRequest(req);
|
2018-04-01 15:58:49 +09:00
|
|
|
} catch (exception) {
|
|
|
|
return res.sendStatus(401);
|
|
|
|
}
|
|
|
|
|
2018-04-05 03:21:11 +09:00
|
|
|
createHttp({
|
2018-04-02 18:36:47 +09:00
|
|
|
type: 'processInbox',
|
2018-04-04 23:12:35 +09:00
|
|
|
activity: req.body,
|
2018-04-02 18:36:47 +09:00
|
|
|
signature,
|
2018-04-01 15:58:49 +09:00
|
|
|
}).save();
|
|
|
|
|
2018-04-01 18:16:47 +09:00
|
|
|
return res.status(202).end();
|
2018-04-01 15:58:49 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
export default app;
|