mirror of
https://git.sr.ht/~cadence/cloudtube
synced 2024-11-10 02:27:29 +00:00
16 lines
535 B
JavaScript
16 lines
535 B
JavaScript
|
const fetch = require("node-fetch")
|
||
|
const db = require("./db")
|
||
|
|
||
|
async function fetchChannel(ucid) {
|
||
|
// fetch
|
||
|
const channel = await fetch(`http://localhost:3000/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
|