mirror of
https://git.sr.ht/~cadence/cloudtube
synced 2026-05-26 12:32:25 +00:00
Move utils folder and fix published text
This commit is contained in:
parent
643f1e0889
commit
2e69dfc4b7
16 changed files with 53 additions and 619 deletions
16
utils/youtube.js
Normal file
16
utils/youtube.js
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
const fetch = require("node-fetch")
|
||||
const db = require("./db")
|
||||
|
||||
async function fetchChannel(ucid, instance) {
|
||||
if (!instance) throw new Error("No instance parameter provided")
|
||||
// fetch
|
||||
const channel = await fetch(`${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
|
||||
Loading…
Add table
Add a link
Reference in a new issue