summaryrefslogtreecommitdiff
path: root/src/api
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2017-08-10 22:06:47 +0900
committersyuilo <syuilotan@yahoo.co.jp>2017-08-10 22:06:47 +0900
commit84d0ad12d145238370628d73dadb640c74f61637 (patch)
tree4b32ee207d189f1acb0711cc7673b448528adc57 /src/api
parentpackage-lock.jsonはリポジトリに含めた方が良いらしい (diff)
downloadsharkey-84d0ad12d145238370628d73dadb640c74f61637.tar.gz
sharkey-84d0ad12d145238370628d73dadb640c74f61637.tar.bz2
sharkey-84d0ad12d145238370628d73dadb640c74f61637.zip
Fix typescript
Diffstat (limited to 'src/api')
-rw-r--r--src/api/server.ts4
-rw-r--r--src/api/service/github.ts7
2 files changed, 8 insertions, 3 deletions
diff --git a/src/api/server.ts b/src/api/server.ts
index 0e059f5d2e..c98167eb3e 100644
--- a/src/api/server.ts
+++ b/src/api/server.ts
@@ -45,7 +45,9 @@ app.post('/signup', require('./private/signup').default);
app.post('/signin', require('./private/signin').default);
app.use((req, res, next) => {
- res.locals.user = ((req.headers['cookie'] || '').match(/i=(!\w+)/) || [null, null])[1];
+ // req.headers['cookie'] は常に string ですが、型定義の都合上
+ // string | string[] になっているので string を明示しています
+ res.locals.user = ((req.headers['cookie'] as string || '').match(/i=(!\w+)/) || [null, null])[1];
next();
});
diff --git a/src/api/service/github.ts b/src/api/service/github.ts
index 0d6e663419..a631808ba5 100644
--- a/src/api/service/github.ts
+++ b/src/api/service/github.ts
@@ -22,8 +22,11 @@ module.exports = async (app: express.Application) => {
const handler = new EventEmitter();
app.post('/hooks/github', (req, res, next) => {
- if ((new Buffer(req.headers['x-hub-signature'])).equals(new Buffer(`sha1=${crypto.createHmac('sha1', config.github_bot.hook_secret).update(JSON.stringify(req.body)).digest('hex')}`))) {
- handler.emit(req.headers['x-github-event'], req.body);
+ // req.headers['x-hub-signature'] および
+ // req.headers['x-github-event'] は常に string ですが、型定義の都合上
+ // string | string[] になっているので string を明示しています
+ if ((new Buffer(req.headers['x-hub-signature'] as string)).equals(new Buffer(`sha1=${crypto.createHmac('sha1', config.github_bot.hook_secret).update(JSON.stringify(req.body)).digest('hex')}`))) {
+ handler.emit(req.headers['x-github-event'] as string, req.body);
res.sendStatus(200);
} else {
res.sendStatus(400);