1
0
mirror of https://git.sr.ht/~cadence/cloudtube synced 2024-09-19 18:57:30 +00:00
cloudtube/api/utils/youtube.js

26 lines
873 B
JavaScript
Raw Normal View History

2020-08-30 13:54:59 +00:00
const fetch = require("node-fetch")
const db = require("./db")
2020-08-31 13:22:16 +00:00
async function fetchChannel(ucid, instance) {
2020-08-30 13:54:59 +00:00
// fetch
2020-08-31 13:22:16 +00:00
const channel = await fetch(`${instance}/api/v1/channels/${ucid}`).then(res => res.json())
2020-08-30 13:54:59 +00:00
// update database
const bestIcon = channel.authorThumbnails.slice(-1)[0]
const iconURL = bestIcon ? bestIcon.url : null
db.prepare("REPLACE INTO Channels (ucid, name, icon_url) VALUES (?, ?, ?)").run([channel.authorId, channel.author, iconURL])
// return
return channel
}
2020-08-30 15:14:05 +00:00
function fetchChannelLatest(ucid) {
return fetch(`http://localhost:3000/api/v1/channels/${ucid}/latest`).then(res => res.json()).then(root => {
root.forEach(video => {
video.descriptionHtml = video.descriptionHtml.replace(/<a /g, '<a tabindex="-1" ')
})
return root
})
}
2020-08-30 13:54:59 +00:00
module.exports.fetchChannel = fetchChannel
2020-08-30 15:14:05 +00:00
module.exports.fetchChannelLatest = fetchChannelLatest