29 lines
651 B
JavaScript
29 lines
651 B
JavaScript
|
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
|
||
|
}
|