youtube webhook not fin
This commit is contained in:
parent
d7c64b3c65
commit
88e412e33a
28
libs/api-action/google.js
Normal file
28
libs/api-action/google.js
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
const axios = require('axios')
|
||||||
|
const config = require('../../config')
|
||||||
|
|
||||||
|
const subYoutube = async (id = '') => {
|
||||||
|
let url = 'https://pubsubhubbub.appspot.com/subscribe'
|
||||||
|
if (typeof id !== 'string' || id.trim().length === 0) return null
|
||||||
|
id = id.trim()
|
||||||
|
|
||||||
|
let data = {
|
||||||
|
'hub.mode': 'subscribe',
|
||||||
|
'hub.topic': `https://www.youtube.com/xml/feeds/videos.xml?channel_id=${id}`,
|
||||||
|
'hub.callback': `${config.url.replace(/\/$/, '')}/google/youtube/webhook?id=${id}`,
|
||||||
|
'hub.lease_seconds': 86400
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await axios({
|
||||||
|
data,
|
||||||
|
url,
|
||||||
|
method: 'post'
|
||||||
|
})
|
||||||
|
} catch (err) {}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
subYoutube
|
||||||
|
}
|
@ -23,7 +23,8 @@
|
|||||||
"koa-router": "^7.4.0",
|
"koa-router": "^7.4.0",
|
||||||
"pg": "^7.4.3",
|
"pg": "^7.4.3",
|
||||||
"raw-body": "^2.3.3",
|
"raw-body": "^2.3.3",
|
||||||
"request": "^2.87.0"
|
"request": "^2.87.0",
|
||||||
|
"xml2js": "^0.4.19"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"standard": "^11.0.1"
|
"standard": "^11.0.1"
|
||||||
|
18
route/google/index.js
Normal file
18
route/google/index.js
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
const Router = require('koa-router')
|
||||||
|
const r = new Router()
|
||||||
|
// const koaBody = require('koa-body')
|
||||||
|
const {
|
||||||
|
getRaw
|
||||||
|
} = require('../../libs/middleware')
|
||||||
|
const {
|
||||||
|
textMessage
|
||||||
|
} = require('../../libs/line-message')
|
||||||
|
|
||||||
|
r.get('/youtube/webhook', async (c, n) => {
|
||||||
|
})
|
||||||
|
|
||||||
|
r.post('/youtube/webhook', getRaw, async (c, n) => {
|
||||||
|
console.log(JSON.stringify(c.request.body, null, 2))
|
||||||
|
})
|
||||||
|
|
||||||
|
module.exports = r
|
Loading…
Reference in New Issue
Block a user