add fan page notify, add twitch route, todo: twitch webhook reg

This commit is contained in:
Jay
2018-06-27 00:59:53 +08:00
parent f409e6ff61
commit 1f3057df69
15 changed files with 377 additions and 51 deletions
+2 -20
View File
@@ -1,32 +1,14 @@
const Router = require('koa-router')
const r = new Router()
// const koaBody = require('koa-body')
const rawBody = require('raw-body')
const {
verifyLine
verifyLine,
getRaw
} = require('../../libs/middleware')
const {
textMessage
} = require('../../libs/line-message')
const getRaw = async (c, n) => {
let raw = await rawBody(c.req, {
length: c.request.length,
limit: '5mb',
encoding: c.request.charset
})
c.request.raw = raw
let txt = raw instanceof Buffer ? raw.toString() : raw
if (c.request.type === 'application/json') {
try {
c.request.body = JSON.parse(txt)
} catch (err) {
c.request.body = txt
}
}
return n()
}
r.post('/', getRaw, verifyLine, async (c, n) => {
console.log(JSON.stringify(c.request.body, null, 2))
if (!('events' in c.request.body)) return c.throw(400, 'data struct error')