[PATCH cloudtube] Partially fix #29: add routes for /c/ and /user/ paths for channels
Export this patch
From: Lomanic <lomanic@hotmail.fr>
---
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 4751d5a..01c2c99 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
// normalise info, apply watched status
diff --git a/utils/youtube.js b/utils/youtube.js
index cc7e15a..c5e2d78 100644
--- a/utils/youtube.js
+++ b/utils/youtube.js
@@ -1,10 +1,10 @@
const {request} = require("./request")
const db = require("./db")
-async function fetchChannel(ucid, instance) {
+async function fetchChannel(ucid, path="channel", instance) {
if (!instance) throw new Error("No instance parameter provided")
// fetch
- 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())
// update database
const bestIcon = channel.authorThumbnails.slice(-1)[0]
const iconURL = bestIcon ? bestIcon.url : null
--
2.32.0