1
0
mirror of https://git.sr.ht/~cadence/cloudtube synced 2024-11-22 07:37:29 +00:00

Partially fix #29: add routes for /c/ and /user/ paths for channels

This commit is contained in:
Lomanic 2021-11-13 02:17:07 +01:00 committed by Cadence Ember
parent 5e6b2bf31c
commit 6de9abd499
2 changed files with 6 additions and 6 deletions

View File

@ -1,16 +1,16 @@
const {render} = require("pinski/plugins") const {render} = require("pinski/plugins")
const constants = require("../utils/constants")
const {fetchChannel} = require("../utils/youtube") const {fetchChannel} = require("../utils/youtube")
const {getUser} = require("../utils/getuser") const {getUser} = require("../utils/getuser")
const converters = require("../utils/converters") const converters = require("../utils/converters")
module.exports = [ module.exports = [
{ {
route: `/channel/(${constants.regex.ucid})`, methods: ["GET"], code: async ({req, fill, url}) => { route: `/(c|channel|user)/(.+)`, methods: ["GET"], code: async ({req, fill, url}) => {
const id = fill[0] const path = fill[0]
const id = fill[1]
const user = getUser(req) const user = getUser(req)
const settings = user.getSettingsOrDefaults() const settings = user.getSettingsOrDefaults()
const data = await fetchChannel(id, settings.instance) const data = await fetchChannel(id, path, settings.instance)
const subscribed = user.isSubscribed(id) const subscribed = user.isSubscribed(id)
const instanceOrigin = settings.instance const instanceOrigin = settings.instance

View File

@ -1,7 +1,7 @@
const {request} = require("./request") const {request} = require("./request")
const db = require("./db") const db = require("./db")
async function fetchChannel(ucid, instance) { async function fetchChannel(ucid, path="channel", instance) {
function updateGoodData(channel) { function updateGoodData(channel) {
const bestIcon = channel.authorThumbnails.slice(-1)[0] const bestIcon = channel.authorThumbnails.slice(-1)[0]
const iconURL = bestIcon ? bestIcon.url : null const iconURL = bestIcon ? bestIcon.url : null
@ -39,7 +39,7 @@ async function fetchChannel(ucid, instance) {
} }
/** @type {any} */ /** @type {any} */
const channel = await request(`${instance}/api/v1/channels/${ucid}`).then(res => res.json()) const channel = await request(`${instance}/api/v1/channels/${ucid}?second__path=${path}`).then(res => res.json())
// handle the case where the channel has a newly discovered error // handle the case where the channel has a newly discovered error
if (channel.error) { if (channel.error) {