From f62c7f2a8cc143454779dc99334ca9fc80ddabd5 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Tue, 29 Apr 2025 11:10:21 +0200 Subject: still just moving code around --- server/src/logic/session.rs | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) (limited to 'server/src/logic/session.rs') 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 */ 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 { +pub struct A(pub T); + +impl A { + async fn from_request_ut(req: &Request<'_>) -> Result { 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 { 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 { type Error = MyError; async fn from_request<'life0>( request: &'r Request<'life0>, ) -> request::Outcome { - match Session::from_request_ut(request).await { + match A::::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, -- cgit v1.2.3-70-g09d2