aboutsummaryrefslogtreecommitdiff
path: root/server/src/compat
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-04-29 15:19:36 +0200
committermetamuffin <metamuffin@disroot.org>2025-04-29 15:19:36 +0200
commitf73aa32549743b2967160d38c1622199c41524a4 (patch)
tree0fa290fbf9b14d7bfd3803f8cc4618c6c9829330 /server/src/compat
parentf62c7f2a8cc143454779dc99334ca9fc80ddabd5 (diff)
downloadjellything-f73aa32549743b2967160d38c1622199c41524a4.tar
jellything-f73aa32549743b2967160d38c1622199c41524a4.tar.bz2
jellything-f73aa32549743b2967160d38c1622199c41524a4.tar.zst
aaaaaaa
Diffstat (limited to 'server/src/compat')
-rw-r--r--server/src/compat/jellyfin/mod.rs85
-rw-r--r--server/src/compat/youtube.rs34
2 files changed, 54 insertions, 65 deletions
diff --git a/server/src/compat/jellyfin/mod.rs b/server/src/compat/jellyfin/mod.rs
index 9d5c93e..20f8c7e 100644
--- a/server/src/compat/jellyfin/mod.rs
+++ b/server/src/compat/jellyfin/mod.rs
@@ -6,25 +6,22 @@
pub mod models;
use crate::{
- logic::session::Session,
- ui::{
- account::login_logic,
- assets::{
- rocket_uri_macro_r_asset, rocket_uri_macro_r_item_backdrop,
- rocket_uri_macro_r_item_poster,
- },
- error::MyResult,
- node::{aspect_class, DatabaseNodeUserDataExt},
- sort::{filter_and_sort_nodes, FilterProperty, NodeFilterSort, SortOrder, SortProperty},
- },
+ helper::A,
+ ui::{account::login_logic, error::MyResult},
};
use anyhow::{anyhow, Context};
use jellybase::{database::Database, CONF};
use jellycommon::{
+ api::{FilterProperty, NodeFilterSort, SortOrder, SortProperty},
+ routes::{u_asset, u_node_slug_backdrop, u_node_slug_poster},
stream::{StreamContainer, StreamSpec},
user::{NodeUserData, WatchedState},
MediaInfo, Node, NodeID, NodeKind, SourceTrack, SourceTrackKind, Visibility,
};
+use jellylogic::{
+ filter_sort::filter_and_sort_nodes, node::DatabaseNodeUserDataExt, session::Session,
+};
+use jellyui::node_page::aspect_class;
use models::*;
use rocket::{
get,
@@ -86,7 +83,7 @@ pub fn r_jellyfin_quickconnect_enabled() -> Json<Value> {
}
#[get("/System/Endpoint")]
-pub fn r_jellyfin_system_endpoint(_session: Session) -> Json<Value> {
+pub fn r_jellyfin_system_endpoint(_session: A<Session>) -> Json<Value> {
Json(json!({
"IsLocal": false,
"IsInNetwork": false,
@@ -95,7 +92,7 @@ pub fn r_jellyfin_system_endpoint(_session: Session) -> Json<Value> {
use rocket_ws::{Message, Stream, WebSocket};
#[get("/socket")]
-pub fn r_jellyfin_socket(_session: Session, ws: WebSocket) -> Stream!['static] {
+pub fn r_jellyfin_socket(_session: A<Session>, ws: WebSocket) -> Stream!['static] {
Stream! { ws =>
for await message in ws {
eprintln!("{message:?}");
@@ -105,7 +102,7 @@ pub fn r_jellyfin_socket(_session: Session, ws: WebSocket) -> Stream!['static] {
}
#[get("/System/Info")]
-pub fn r_jellyfin_system_info(_session: Session) -> Json<Value> {
+pub fn r_jellyfin_system_info(_session: A<Session>) -> Json<Value> {
Json(json!({
"OperatingSystemDisplayName": "",
"HasPendingRestart": false,
@@ -135,7 +132,7 @@ pub fn r_jellyfin_system_info(_session: Session) -> Json<Value> {
}
#[get("/DisplayPreferences/usersettings")]
-pub fn r_jellyfin_displaypreferences_usersettings(_session: Session) -> Json<Value> {
+pub fn r_jellyfin_displaypreferences_usersettings(_session: A<Session>) -> Json<Value> {
Json(json!({
"Id": "3ce5b65d-e116-d731-65d1-efc4a30ec35c",
"SortBy": "SortName",
@@ -153,53 +150,53 @@ pub fn r_jellyfin_displaypreferences_usersettings(_session: Session) -> Json<Val
}
#[post("/DisplayPreferences/usersettings")]
-pub fn r_jellyfin_displaypreferences_usersettings_post(_session: Session) {}
+pub fn r_jellyfin_displaypreferences_usersettings_post(_session: A<Session>) {}
#[get("/Users/<id>")]
-pub fn r_jellyfin_users_id(session: Session, id: &str) -> Json<Value> {
+pub fn r_jellyfin_users_id(session: A<Session>, id: &str) -> Json<Value> {
let _ = id;
- Json(user_object(session.user.name))
+ Json(user_object(session.0.user.name))
}
#[get("/Items/<id>/Images/Primary?<fillWidth>&<tag>")]
#[allow(non_snake_case)]
pub fn r_jellyfin_items_image_primary(
- _session: Session,
+ _session: A<Session>,
id: &str,
fillWidth: Option<usize>,
tag: String,
) -> Redirect {
if tag == "poster" {
- Redirect::permanent(rocket::uri!(r_item_poster(id, fillWidth)))
+ Redirect::permanent(u_node_slug_poster(id, fillWidth.unwrap_or(1024)))
} else {
- Redirect::permanent(rocket::uri!(r_asset(tag, fillWidth)))
+ Redirect::permanent(u_asset(&tag, fillWidth.unwrap_or(1024)))
}
}
#[get("/Items/<id>/Images/Backdrop/0?<maxWidth>")]
#[allow(non_snake_case)]
pub fn r_jellyfin_items_images_backdrop(
- _session: Session,
+ _session: A<Session>,
id: &str,
maxWidth: Option<usize>,
) -> Redirect {
- Redirect::permanent(rocket::uri!(r_item_backdrop(id, maxWidth)))
+ Redirect::permanent(u_node_slug_backdrop(id, maxWidth.unwrap_or(1024)))
}
#[get("/Items/<id>")]
#[allow(private_interfaces)]
pub fn r_jellyfin_items_item(
- session: Session,
+ session: A<Session>,
database: &State<Database>,
id: &str,
) -> MyResult<Json<JellyfinItem>> {
- let (n, ud) = database.get_node_with_userdata(NodeID::from_slug(id), &session)?;
+ let (n, ud) = database.get_node_with_userdata(NodeID::from_slug(id), &session.0)?;
Ok(Json(item_object(&n, &ud)))
}
#[get("/Users/<uid>/Items/<id>")]
#[allow(private_interfaces)]
pub fn r_jellyfin_users_items_item(
- session: Session,
+ session: A<Session>,
database: &State<Database>,
uid: &str,
id: &str,
@@ -228,7 +225,7 @@ struct JellyfinItemQuery {
#[get("/Users/<uid>/Items?<query..>")]
#[allow(private_interfaces)]
pub fn r_jellyfin_users_items(
- session: Session,
+ session: A<Session>,
database: &State<Database>,
uid: &str,
query: JellyfinItemQuery,
@@ -240,7 +237,7 @@ pub fn r_jellyfin_users_items(
#[get("/Artists?<query..>")]
#[allow(private_interfaces)]
pub fn r_jellyfin_artists(
- session: Session,
+ session: A<Session>,
database: &State<Database>,
mut query: JellyfinItemQuery,
) -> MyResult<Json<Value>> {
@@ -256,7 +253,7 @@ pub fn r_jellyfin_artists(
#[get("/Persons?<query..>")]
#[allow(private_interfaces)]
pub fn r_jellyfin_persons(
- session: Session,
+ session: A<Session>,
database: &State<Database>,
mut query: JellyfinItemQuery,
) -> MyResult<Json<Value>> {
@@ -272,7 +269,7 @@ pub fn r_jellyfin_persons(
#[get("/Items?<query..>")]
#[allow(private_interfaces)]
pub fn r_jellyfin_items(
- session: Session,
+ session: A<Session>,
database: &State<Database>,
query: JellyfinItemQuery,
) -> MyResult<Json<Value>> {
@@ -320,7 +317,7 @@ pub fn r_jellyfin_items(
let mut nodes = nodes
.into_iter()
- .map(|nid| database.get_node_with_userdata(nid, &session))
+ .map(|nid| database.get_node_with_userdata(nid, &session.0))
.collect::<Result<Vec<_>, anyhow::Error>>()?;
filter_and_sort_nodes(
@@ -352,7 +349,7 @@ pub fn r_jellyfin_items(
#[get("/UserViews?<userId>")]
#[allow(non_snake_case)]
pub fn r_jellyfin_users_views(
- session: Session,
+ session: A<Session>,
database: &State<Database>,
userId: &str,
) -> MyResult<Json<Value>> {
@@ -362,7 +359,7 @@ pub fn r_jellyfin_users_views(
.get_node_children(NodeID::from_slug("library"))
.context("root node missing")?
.into_iter()
- .map(|nid| database.get_node_with_userdata(nid, &session))
+ .map(|nid| database.get_node_with_userdata(nid, &session.0))
.collect::<Result<Vec<_>, anyhow::Error>>()?;
toplevel.sort_by_key(|(n, _)| n.index.unwrap_or(usize::MAX));
@@ -382,7 +379,7 @@ pub fn r_jellyfin_users_views(
}
#[get("/Items/<id>/Similar")]
-pub fn r_jellyfin_items_similar(_session: Session, id: &str) -> Json<Value> {
+pub fn r_jellyfin_items_similar(_session: A<Session>, id: &str) -> Json<Value> {
let _ = id;
Json(json!({
"Items": [],
@@ -392,7 +389,7 @@ pub fn r_jellyfin_items_similar(_session: Session, id: &str) -> Json<Value> {
}
#[get("/LiveTv/Programs/Recommended")]
-pub fn r_jellyfin_livetv_programs_recommended(_session: Session) -> Json<Value> {
+pub fn r_jellyfin_livetv_programs_recommended(_session: A<Session>) -> Json<Value> {
Json(json!({
"Items": [],
"TotalRecordCount": 0,
@@ -401,7 +398,7 @@ pub fn r_jellyfin_livetv_programs_recommended(_session: Session) -> Json<Value>
}
#[get("/Users/<uid>/Items/<id>/Intros")]
-pub fn r_jellyfin_items_intros(_session: Session, uid: &str, id: &str) -> Json<Value> {
+pub fn r_jellyfin_items_intros(_session: A<Session>, uid: &str, id: &str) -> Json<Value> {
let _ = (uid, id);
Json(json!({
"Items": [],
@@ -411,7 +408,7 @@ pub fn r_jellyfin_items_intros(_session: Session, uid: &str, id: &str) -> Json<V
}
#[get("/Shows/NextUp")]
-pub fn r_jellyfin_shows_nextup(_session: Session) -> Json<Value> {
+pub fn r_jellyfin_shows_nextup(_session: A<Session>) -> Json<Value> {
Json(json!({
"Items": [],
"TotalRecordCount": 0,
@@ -421,7 +418,7 @@ pub fn r_jellyfin_shows_nextup(_session: Session) -> Json<Value> {
#[post("/Items/<id>/PlaybackInfo")]
pub fn r_jellyfin_items_playbackinfo(
- _session: Session,
+ _session: A<Session>,
database: &State<Database>,
id: &str,
) -> MyResult<Json<Value>> {
@@ -438,7 +435,7 @@ pub fn r_jellyfin_items_playbackinfo(
#[get("/Videos/<id>/stream.webm")]
pub fn r_jellyfin_video_stream(
- _session: Session,
+ _session: A<Session>,
database: &State<Database>,
id: &str,
) -> MyResult<Redirect> {
@@ -463,14 +460,14 @@ struct JellyfinProgressData {
#[post("/Sessions/Playing/Progress", data = "<data>")]
#[allow(private_interfaces)]
pub fn r_jellyfin_sessions_playing_progress(
- session: Session,
+ session: A<Session>,
database: &State<Database>,
data: Json<JellyfinProgressData>,
) -> MyResult<()> {
let position = data.position_ticks / 10_000_000.;
database.update_node_udata(
NodeID::from_slug(&data.item_id),
- &session.user.name,
+ &session.0.user.name,
|udata| {
udata.watched = match udata.watched {
WatchedState::None | WatchedState::Pending | WatchedState::Progress(_) => {
@@ -485,16 +482,16 @@ pub fn r_jellyfin_sessions_playing_progress(
}
#[post("/Sessions/Playing")]
-pub fn r_jellyfin_sessions_playing(_session: Session) {}
+pub fn r_jellyfin_sessions_playing(_session: A<Session>) {}
#[get("/Playback/BitrateTest?<Size>")]
#[allow(non_snake_case)]
-pub fn r_jellyfin_playback_bitratetest(_session: Session, Size: usize) -> Vec<u8> {
+pub fn r_jellyfin_playback_bitratetest(_session: A<Session>, Size: usize) -> Vec<u8> {
vec![0; Size.min(1_000_000)]
}
#[post("/Sessions/Capabilities/Full")]
-pub fn r_jellyfin_sessions_capabilities_full(_session: Session) {}
+pub fn r_jellyfin_sessions_capabilities_full(_session: A<Session>) {}
#[derive(Deserialize)]
#[serde(rename_all = "PascalCase")]
diff --git a/server/src/compat/youtube.rs b/server/src/compat/youtube.rs
index 1df2751..67a34fc 100644
--- a/server/src/compat/youtube.rs
+++ b/server/src/compat/youtube.rs
@@ -3,21 +3,15 @@
which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
Copyright (C) 2025 metamuffin <metamuffin.org>
*/
-use crate::{
- logic::session::Session,
- ui::{
- error::MyResult,
- node::rocket_uri_macro_r_library_node,
- player::{rocket_uri_macro_r_player, PlayerConfig},
- },
-};
+use crate::{helper::A, ui::error::MyResult};
use anyhow::anyhow;
use jellybase::database::Database;
-use jellycommon::NodeID;
+use jellycommon::routes::{u_node_slug, u_node_slug_player};
+use jellylogic::session::Session;
use rocket::{get, response::Redirect, State};
#[get("/watch?<v>")]
-pub fn r_youtube_watch(_session: Session, db: &State<Database>, v: &str) -> MyResult<Redirect> {
+pub fn r_youtube_watch(_session: A<Session>, db: &State<Database>, v: &str) -> MyResult<Redirect> {
if v.len() != 11 {
Err(anyhow!("video id length incorrect"))?
}
@@ -25,14 +19,15 @@ pub fn r_youtube_watch(_session: Session, db: &State<Database>, v: &str) -> MyRe
Err(anyhow!("element not found"))?
};
let node = db.get_node(id)?.ok_or(anyhow!("node missing"))?;
- Ok(Redirect::to(rocket::uri!(r_player(
- &node.slug,
- PlayerConfig::default()
- ))))
+ Ok(Redirect::to(u_node_slug_player(&node.slug)))
}
#[get("/channel/<id>")]
-pub fn r_youtube_channel(_session: Session, db: &State<Database>, id: &str) -> MyResult<Redirect> {
+pub fn r_youtube_channel(
+ _session: A<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("@") {
@@ -43,11 +38,11 @@ pub fn r_youtube_channel(_session: Session, db: &State<Database>, id: &str) -> M
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))))
+ Ok(Redirect::to(u_node_slug(&node.slug)))
}
#[get("/embed/<v>")]
-pub fn r_youtube_embed(_session: Session, db: &State<Database>, v: &str) -> MyResult<Redirect> {
+pub fn r_youtube_embed(_session: A<Session>, db: &State<Database>, v: &str) -> MyResult<Redirect> {
if v.len() != 11 {
Err(anyhow!("video id length incorrect"))?
}
@@ -55,8 +50,5 @@ pub fn r_youtube_embed(_session: Session, db: &State<Database>, v: &str) -> MyRe
Err(anyhow!("element not found"))?
};
let node = db.get_node(id)?.ok_or(anyhow!("node missing"))?;
- Ok(Redirect::to(rocket::uri!(r_player(
- &node.slug,
- PlayerConfig::default()
- ))))
+ Ok(Redirect::to(u_node_slug_player(&node.slug)))
}