diff options
Diffstat (limited to 'server/src/logic/session.rs')
-rw-r--r-- | server/src/logic/session.rs | 29 |
1 files changed, 11 insertions, 18 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, |