1
0
mirror of https://git.sr.ht/~cadence/cloudtube synced 2024-11-22 15:47:30 +00:00
cloudtube/utils/youtube.js
2021-01-12 23:49:00 +13:00

17 lines
606 B
JavaScript

const {request} = require("./request")
const db = require("./db")
async function fetchChannel(ucid, instance) {
if (!instance) throw new Error("No instance parameter provided")
// fetch
const channel = await request(`${instance}/api/v1/channels/${ucid}`).then(res => res.json())
// 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