1
0
mirror of https://git.sr.ht/~cadence/cloudtube synced 2024-11-26 09:27:30 +00:00
cloudtube/utils/youtube.js

17 lines
606 B
JavaScript
Raw Normal View History

const {request} = require("./request")
2020-08-30 13:54:59 +00:00
const db = require("./db")
2020-08-31 13:22:16 +00:00
async function fetchChannel(ucid, instance) {
2020-08-31 13:40:34 +00:00
if (!instance) throw new Error("No instance parameter provided")
2020-08-30 13:54:59 +00:00
// fetch
const channel = await request(`${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
}
module.exports.fetchChannel = fetchChannel