From 77c54e215c2e6ef3f00207ef2be89bbcccefd6e5 Mon Sep 17 00:00:00 2001 From: JMARyA Date: Wed, 18 Dec 2024 20:09:07 +0100 Subject: [PATCH] fix --- Cargo.lock | 40 ++++++++++++++++++++-------------------- src/pages/index.rs | 18 +++++++----------- src/pages/mod.rs | 3 ++- src/pages/user.rs | 23 +++++++---------------- src/pages/watch.rs | 18 +++++++++--------- 5 files changed, 45 insertions(+), 57 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1ec01eb..7d0ff1f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -152,7 +152,7 @@ checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" [[package]] name = "based" version = "0.1.0" -source = "git+https://git.hydrar.de/jmarya/based#98048ce522db134fe3e863538db6793068085b80" +source = "git+https://git.hydrar.de/jmarya/based#86c97cb9770e2290cf47f432c92f87352dc19e1b" dependencies = [ "bcrypt", "chrono", @@ -250,9 +250,9 @@ checksum = "325918d6fe32f23b19878fe4b34794ae41fc19ddbe53b10571a4874d44ffd39b" [[package]] name = "cc" -version = "1.2.3" +version = "1.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27f657647bcff5394bf56c7317665bbf790a137a50eaaa5c6bfbb9e27a518f2d" +checksum = "9157bbaa6b165880c27a4293a474c91cdcf265cc68cc829bf10be0964a391caf" dependencies = [ "shlex", ] @@ -356,9 +356,9 @@ checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5" [[package]] name = "crossbeam-deque" -version = "0.8.5" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d" +checksum = "9dd111b7b7f7d55b72c0a6ae361660ee5853c9af73f70c3c2ef6858b950e2e51" dependencies = [ "crossbeam-epoch", "crossbeam-utils", @@ -375,18 +375,18 @@ dependencies = [ [[package]] name = "crossbeam-queue" -version = "0.3.11" +version = "0.3.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df0346b5d5e76ac2fe4e327c5fd1118d6be7c51dfb18f9b7922923f287471e35" +checksum = "0f58bbc28f91df819d0aa2a2c00cd19754769c2fad90579b3592b1c9ba7a3115" dependencies = [ "crossbeam-utils", ] [[package]] name = "crossbeam-utils" -version = "0.8.20" +version = "0.8.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" +checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" [[package]] name = "crypto-common" @@ -864,11 +864,11 @@ dependencies = [ [[package]] name = "home" -version = "0.5.9" +version = "0.5.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" +checksum = "589533453244b0995c858700322199b2becb13b627df2851f64a2775d024abcf" dependencies = [ - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -924,9 +924,9 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "hyper" -version = "0.14.31" +version = "0.14.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c08302e8fa335b151b788c775ff56e7a03ae64ff85c548ee820fecb70356e85" +checksum = "41dfc780fdec9373c01bae43289ea34c972e40ee3c9f6b3c8801a35f35586ce7" dependencies = [ "bytes", "futures-channel", @@ -1297,9 +1297,9 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] name = "miniz_oxide" -version = "0.8.0" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2d80299ef12ff69b16a84bb182e3b9df68b5a91574d3d4fa6e41b65deec4df1" +checksum = "4ffbe83022cedc1d264172192511ae958937694cd57ce297164951b8b3568394" dependencies = [ "adler2", ] @@ -2013,9 +2013,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.12.1" +version = "2.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa39c7303dc58b5543c94d22c1766b0d31f2ee58306363ea622b10bbc075eaa2" +checksum = "1863fd3768cd83c56a7f60faa4dc0d403f1b6df0a38c3c25f44b7894e45370d5" dependencies = [ "core-foundation-sys", "libc", @@ -2771,9 +2771,9 @@ dependencies = [ [[package]] name = "unicode-bidi" -version = "0.3.17" +version = "0.3.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ab17db44d7388991a428b2ee655ce0c212e862eff1768a455c58f9aad6e7893" +checksum = "5c1cb5db39152898a79168971543b1cb5020dff7fe43c8dc468b0885f5e29df5" [[package]] name = "unicode-ident" diff --git a/src/pages/index.rs b/src/pages/index.rs index 29a98b0..273bc1b 100644 --- a/src/pages/index.rs +++ b/src/pages/index.rs @@ -1,14 +1,10 @@ use based::{ - auth::User, + auth::MaybeUser, page::htmx_link, request::{api::vec_to_api, RequestContext, StringResponse}, }; use maud::html; -use rocket::{ - get, - http::{ContentType, Status}, - State, -}; +use rocket::{get, State}; use serde_json::json; use crate::{library::Library, pages::components::video_element}; @@ -39,7 +35,7 @@ pub async fn channel_page( ctx: RequestContext, dir: &str, library: &State, - user: User, + user: MaybeUser, ) -> StringResponse { if dir.ends_with(".json") { let dir_videos = library @@ -59,15 +55,15 @@ pub async fn channel_page( }; ); - render_page(ctx, content, dir, Some(user)).await + render_page(ctx, content, dir, user.into()).await } #[get("/")] pub async fn index_page( ctx: RequestContext, library: &State, - user: User, -) -> (Status, (ContentType, String)) { + user: MaybeUser, +) -> StringResponse { let content = html!( h1 class="text-center text-4xl font-extrabold leading-tight mt-4" { "Random Videos" }; div class="lg:grid grid-cols-3 gap-6 p-6" { @@ -84,5 +80,5 @@ pub async fn index_page( }; ); - render_page(ctx, content, "WatchDogs", Some(user)).await + render_page(ctx, content, "WatchDogs", user.into()).await } diff --git a/src/pages/mod.rs b/src/pages/mod.rs index 35a0658..4ebf644 100644 --- a/src/pages/mod.rs +++ b/src/pages/mod.rs @@ -1,3 +1,4 @@ +use based::request::StringResponse; use rocket::http::{ContentType, Status}; pub mod assets; @@ -7,7 +8,7 @@ pub mod user; pub mod watch; pub mod yt; -pub fn api_response(json: &serde_json::Value) -> (Status, (ContentType, String)) { +pub fn api_response(json: &serde_json::Value) -> StringResponse { ( Status::Ok, (ContentType::JSON, serde_json::to_string(json).unwrap()), diff --git a/src/pages/user.rs b/src/pages/user.rs index e0a17f9..ffb2967 100644 --- a/src/pages/user.rs +++ b/src/pages/user.rs @@ -1,19 +1,14 @@ -use based::{auth::User, request::RequestContext}; +use based::auth::User; +use based::request::StringResponse; +use based::{auth::MaybeUser, request::RequestContext}; use maud::html; use rocket::http::CookieJar; -use rocket::{ - form::Form, - get, - http::{ContentType, Cookie, Status}, - post, - response::Redirect, - FromForm, -}; +use rocket::{form::Form, get, http::Cookie, post, response::Redirect, FromForm}; use super::components::render_page; #[get("/login")] -pub async fn login(ctx: RequestContext, user: User) -> (Status, (ContentType, String)) { +pub async fn login(ctx: RequestContext, user: MaybeUser) -> StringResponse { let content = html!( h2 { "Login" }; form action="/login" method="POST" { @@ -23,7 +18,7 @@ pub async fn login(ctx: RequestContext, user: User) -> (Status, (ContentType, St } ); - render_page(ctx, content, "Login", Some(user)).await + render_page(ctx, content, "Login", user.into()).await } #[derive(FromForm)] @@ -33,11 +28,7 @@ pub struct LoginForm { } #[post("/login", data = "")] -pub async fn login_post( - login_form: Form, - user: User, - cookies: &CookieJar<'_>, -) -> Option { +pub async fn login_post(login_form: Form, cookies: &CookieJar<'_>) -> Option { let login_data = login_form.into_inner(); let (session, _) = User::login(&login_data.username, &login_data.password).await?; diff --git a/src/pages/watch.rs b/src/pages/watch.rs index 7d48e67..e5fcd24 100644 --- a/src/pages/watch.rs +++ b/src/pages/watch.rs @@ -1,10 +1,10 @@ -use based::{auth::User, format::format_date, request::RequestContext}; -use maud::html; -use rocket::{ - get, - http::{ContentType, Status}, - State, +use based::{ + auth::MaybeUser, + format::format_date, + request::{RequestContext, StringResponse}, }; +use maud::html; +use rocket::{get, State}; use crate::{library::Library, pages::components::video_element_wide}; @@ -15,8 +15,8 @@ pub async fn watch_page( ctx: RequestContext, library: &State, v: String, - user: User, -) -> (Status, (ContentType, String)) { + user: MaybeUser, +) -> StringResponse { let video = if let Some(video) = library.get_video_by_id(&v).await { video } else { @@ -66,7 +66,7 @@ pub async fn watch_page( ctx, content, &format!("{} - WatchDogs", video.title), - Some(user), + user.into(), ) .await }