1
0
mirror of https://git.sr.ht/~cadence/cloudtube synced 2024-11-14 04:17:29 +00:00
cloudtube/api/channels.js

31 lines
1.1 KiB
JavaScript
Raw Normal View History

2020-08-29 13:21:48 +00:00
const {render} = require("pinski/plugins")
const constants = require("../utils/constants")
const {fetchChannel} = require("../utils/youtube")
const {getUser} = require("../utils/getuser")
const converters = require("../utils/converters")
2020-08-29 13:21:48 +00:00
module.exports = [
{
2020-08-30 13:54:59 +00:00
route: `/channel/(${constants.regex.ucid})`, methods: ["GET"], code: async ({req, fill}) => {
2020-08-29 13:21:48 +00:00
const id = fill[0]
2020-08-30 13:54:59 +00:00
const user = getUser(req)
2020-08-31 13:22:16 +00:00
const settings = user.getSettingsOrDefaults()
const data = await fetchChannel(id, settings.instance)
2020-08-30 13:54:59 +00:00
const subscribed = user.isSubscribed(id)
const instanceOrigin = settings.instance
// normalise info, apply watched status
if (!data.second__subCountText && data.subCount) {
data.second__subCountText = converters.subscriberCountToText(data.subCount)
}
2020-12-29 10:07:23 +00:00
const watchedVideos = user.getWatchedVideos()
if (data.latestVideos) {
data.latestVideos.forEach(video => {
converters.normaliseVideoInfo(video)
2020-12-29 10:07:23 +00:00
video.watched = watchedVideos.includes(video.videoId)
})
}
return render(200, "pug/channel.pug", {data, subscribed, instanceOrigin})
2020-08-29 13:21:48 +00:00
}
}
]