diff options
Diffstat (limited to 'server/src/logic')
-rw-r--r-- | server/src/logic/session.rs | 29 | ||||
-rw-r--r-- | server/src/logic/stream.rs | 2 | ||||
-rw-r--r-- | server/src/logic/userdata.rs | 12 |
3 files changed, 17 insertions, 26 deletions
diff --git a/server/src/logic/session.rs b/server/src/logic/session.rs index d77c4fc..105aa10 100644 --- a/server/src/logic/session.rs +++ b/server/src/logic/session.rs @@ -4,16 +4,9 @@ Copyright (C) 2025 metamuffin <metamuffin.org> */ use crate::ui::error::MyError; -use aes_gcm_siv::{ - aead::{generic_array::GenericArray, Aead}, - KeyInit, -}; use anyhow::anyhow; -use base64::Engine; -use chrono::{DateTime, Duration, Utc}; -use jellybase::{database::Database, SECRETS}; -use jellycommon::user::{PermissionSet, User}; -use jellylogic::session::validate; +use jellybase::database::Database; +use jellylogic::session::{validate, AdminSession, Session}; use log::warn; use rocket::{ async_trait, @@ -22,11 +15,11 @@ use rocket::{ request::{self, FromRequest}, Request, State, }; -use serde::{Deserialize, Serialize}; -use std::sync::LazyLock; -impl Session { - pub async fn from_request_ut(req: &Request<'_>) -> Result<Self, MyError> { +pub struct A<T>(pub T); + +impl A<Session> { + async fn from_request_ut(req: &Request<'_>) -> Result<Self, MyError> { let username; #[cfg(not(feature = "bypass-auth"))] @@ -59,7 +52,7 @@ impl Session { let user = db.get_user(&username)?.ok_or(anyhow!("user not found"))?; - Ok(Session { user }) + Ok(A(Session { user })) } } @@ -75,7 +68,7 @@ fn parse_jellyfin_auth(h: &str) -> Option<&str> { } #[async_trait] -impl<'r> FromRequest<'r> for Session { +impl<'r> FromRequest<'r> for A<Session> { type Error = MyError; async fn from_request<'life0>( request: &'r Request<'life0>, @@ -91,15 +84,15 @@ impl<'r> FromRequest<'r> for Session { } #[async_trait] -impl<'r> FromRequest<'r> for AdminSession { +impl<'r> FromRequest<'r> for A<AdminSession> { type Error = MyError; async fn from_request<'life0>( request: &'r Request<'life0>, ) -> request::Outcome<Self, Self::Error> { - match Session::from_request_ut(request).await { + match A::<Session>::from_request_ut(request).await { Ok(x) => { if x.user.admin { - Outcome::Success(AdminSession(x)) + Outcome::Success(A(AdminSession(x.0))) } else { Outcome::Error(( Status::Unauthorized, diff --git a/server/src/logic/stream.rs b/server/src/logic/stream.rs index 5bba9c2..f9cdb41 100644 --- a/server/src/logic/stream.rs +++ b/server/src/logic/stream.rs @@ -3,11 +3,11 @@ which is licensed under the GNU Affero General Public License (version 3); see /COPYING. Copyright (C) 2025 metamuffin <metamuffin.org> */ -use super::session::Session; use crate::{database::Database, ui::error::MyError}; use anyhow::{anyhow, Result}; use jellybase::{assetfed::AssetInner, federation::Federation}; use jellycommon::{stream::StreamSpec, TrackSource}; +use jellylogic::session::Session; use jellystream::SMediaInfo; use log::{info, warn}; use rocket::{ diff --git a/server/src/logic/userdata.rs b/server/src/logic/userdata.rs index 64a136f..8da6be9 100644 --- a/server/src/logic/userdata.rs +++ b/server/src/logic/userdata.rs @@ -3,19 +3,17 @@ which is licensed under the GNU Affero General Public License (version 3); see /COPYING. Copyright (C) 2025 metamuffin <metamuffin.org> */ -use crate::{ui::error::MyResult, ui::node::rocket_uri_macro_r_library_node}; +use crate::ui::error::MyResult; use jellybase::database::Database; use jellycommon::{ - user::{NodeUserData, WatchedState}, - NodeID, + routes::u_node_id, user::{NodeUserData, WatchedState}, NodeID }; +use jellylogic::session::Session; use rocket::{ form::Form, get, post, response::Redirect, serde::json::Json, FromForm, FromFormField, State, UriDisplayQuery, }; -use super::session::Session; - #[derive(Debug, FromFormField, UriDisplayQuery)] pub enum UrlWatchedState { None, @@ -51,7 +49,7 @@ pub async fn r_node_userdata_watched( }; Ok(()) })?; - Ok(Redirect::found(rocket::uri!(r_library_node(id)))) + Ok(Redirect::found(u_node_id(id))) } #[derive(FromForm)] @@ -72,7 +70,7 @@ pub async fn r_node_userdata_rating( udata.rating = form.rating; Ok(()) })?; - Ok(Redirect::found(rocket::uri!(r_library_node(id)))) + Ok(Redirect::found(u_node_id(id))) } #[post("/n/<id>/progress?<t>")] |