From 6de9abd499b596ce2e11bf2537e7322b01543615 Mon Sep 17 00:00:00 2001 From: Lomanic Date: Sat, 13 Nov 2021 02:17:07 +0100 Subject: [PATCH] Partially fix #29: add routes for /c/ and /user/ paths for channels --- api/channels.js | 8 ++++---- utils/youtube.js | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/api/channels.js b/api/channels.js index 56320a3..38f3d75 100644 --- a/api/channels.js +++ b/api/channels.js @@ -1,16 +1,16 @@ 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") module.exports = [ { - route: `/channel/(${constants.regex.ucid})`, methods: ["GET"], code: async ({req, fill, url}) => { - const id = fill[0] + route: `/(c|channel|user)/(.+)`, methods: ["GET"], code: async ({req, fill, url}) => { + const path = fill[0] + const id = fill[1] const user = getUser(req) 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 instanceOrigin = settings.instance diff --git a/utils/youtube.js b/utils/youtube.js index 991b884..5e6b417 100644 --- a/utils/youtube.js +++ b/utils/youtube.js @@ -1,7 +1,7 @@ const {request} = require("./request") const db = require("./db") -async function fetchChannel(ucid, instance) { +async function fetchChannel(ucid, path="channel", instance) { function updateGoodData(channel) { const bestIcon = channel.authorThumbnails.slice(-1)[0] const iconURL = bestIcon ? bestIcon.url : null @@ -39,7 +39,7 @@ async function fetchChannel(ucid, instance) { } /** @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 if (channel.error) { -- 2.45.2