diff options
author | metamuffin <metamuffin@disroot.org> | 2025-01-30 16:45:06 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-01-30 16:45:06 +0100 |
commit | bfc5552a8eba07897c2ed626b49c085d97fdfa0d (patch) | |
tree | 2eaff957b4a744e55710502c81f7ce38a3f86294 /server | |
parent | 32a05b5ec244d4d8143993b082f8d3f86a0a4ecd (diff) | |
download | jellything-bfc5552a8eba07897c2ed626b49c085d97fdfa0d.tar jellything-bfc5552a8eba07897c2ed626b49c085d97fdfa0d.tar.bz2 jellything-bfc5552a8eba07897c2ed626b49c085d97fdfa0d.tar.zst |
external ids and urls
Diffstat (limited to 'server')
-rw-r--r-- | server/src/routes/external_compat.rs | 41 | ||||
-rw-r--r-- | server/src/routes/mod.rs | 4 |
2 files changed, 45 insertions, 0 deletions
diff --git a/server/src/routes/external_compat.rs b/server/src/routes/external_compat.rs new file mode 100644 index 0000000..7babfa5 --- /dev/null +++ b/server/src/routes/external_compat.rs @@ -0,0 +1,41 @@ +/* + This file is part of jellything (https://codeberg.org/metamuffin/jellything) + which is licensed under the GNU Affero General Public License (version 3); see /COPYING. + Copyright (C) 2025 metamuffin <metamuffin.org> +*/ +use super::ui::{account::session::Session, error::MyResult}; +use crate::routes::ui::node::rocket_uri_macro_r_library_node; +use anyhow::anyhow; +use jellybase::database::Database; +use rocket::{get, response::Redirect, State}; + +#[get("/watch?<v>")] +pub fn r_ext_youtube_watch(_session: Session, db: &State<Database>, v: &str) -> MyResult<Redirect> { + if v.len() != 11 { + Err(anyhow!("video id length incorrect"))? + } + let Some(id) = db.get_node_external_id("youtube:video", v)? else { + Err(anyhow!("element not found"))? + }; + let node = db.get_node(id)?.ok_or(anyhow!("node missing"))?; + Ok(Redirect::to(rocket::uri!(r_library_node(&node.slug)))) +} + +#[get("/channel/<id>")] +pub fn r_ext_youtube_channel( + _session: Session, + db: &State<Database>, + id: &str, +) -> MyResult<Redirect> { + let Some(id) = (if id.starts_with("UC") { + db.get_node_external_id("youtube:channel", id)? + } else if id.starts_with("@") { + db.get_node_external_id("youtube:channel-name", id)? + } else { + Err(anyhow!("unknown channel id format"))? + }) else { + Err(anyhow!("channel not found"))? + }; + let node = db.get_node(id)?.ok_or(anyhow!("node missing"))?; + Ok(Redirect::to(rocket::uri!(r_library_node(&node.slug)))) +} diff --git a/server/src/routes/mod.rs b/server/src/routes/mod.rs index 600d544..5fb9b26 100644 --- a/server/src/routes/mod.rs +++ b/server/src/routes/mod.rs @@ -7,6 +7,7 @@ use self::playersync::{r_streamsync, PlayersyncChannels}; use crate::{database::Database, routes::ui::error::MyResult}; use api::{r_api_account_login, r_api_asset_token_raw, r_api_root, r_api_version}; use base64::Engine; +use external_compat::{r_ext_youtube_channel, r_ext_youtube_watch}; use jellybase::{federation::Federation, CONF, SECRETS}; use log::warn; use rand::random; @@ -48,6 +49,7 @@ use userdata::{ }; pub mod api; +pub mod external_compat; pub mod playersync; pub mod stream; pub mod ui; @@ -140,6 +142,8 @@ pub fn build_rocket(database: Database, federation: Federation) -> Rocket<Build> r_api_account_login, r_api_root, r_api_asset_token_raw, + r_ext_youtube_watch, + r_ext_youtube_channel, ], ) } |