From 653dbe5fb6e3015564b66a3e35adf25dc4125f2c Mon Sep 17 00:00:00 2001 From: Jay Date: Tue, 3 Jul 2018 22:14:14 +0800 Subject: [PATCH] update --- route/google/index.js | 14 ++++++++++++++ route/index.js | 1 + 2 files changed, 15 insertions(+) diff --git a/route/google/index.js b/route/google/index.js index 3088435..daa8a7f 100644 --- a/route/google/index.js +++ b/route/google/index.js @@ -1,4 +1,5 @@ const Router = require('koa-router') +const xml2js = require('xml2js') const r = new Router() // const koaBody = require('koa-body') const { @@ -9,6 +10,19 @@ const { } = require('../../libs/line-message') r.get('/youtube/webhook', async (c, n) => { + let mode = c.query['hub.mode'] || '' + let verifyToken = c.query['hub.verify_token'] || '' + let challenge = c.query['hub.challenge'] + + if (mode) { + if (mode === 'subscribe') { + c.status = 200 + c.body = challenge + } else { + c.status = 403 + c.body = '' + } + } }) r.post('/youtube/webhook', getRaw, async (c, n) => { diff --git a/route/index.js b/route/index.js index b5a3547..930270b 100644 --- a/route/index.js +++ b/route/index.js @@ -2,6 +2,7 @@ const Router = require('koa-router') const r = new Router() r.use('/line', require('./line').routes()) +r.use('/google', require('./google').routes()) // r.use('/twitch', require('./twitch').routes()) module.exports = r