parent
58a661d0ed
commit
77c54e215c
5 changed files with 45 additions and 57 deletions
|
@ -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<Library>,
|
||||
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<Library>,
|
||||
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
|
||||
}
|
||||
|
|
|
@ -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()),
|
||||
|
|
|
@ -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 = "<login_form>")]
|
||||
pub async fn login_post(
|
||||
login_form: Form<LoginForm>,
|
||||
user: User,
|
||||
cookies: &CookieJar<'_>,
|
||||
) -> Option<Redirect> {
|
||||
pub async fn login_post(login_form: Form<LoginForm>, cookies: &CookieJar<'_>) -> Option<Redirect> {
|
||||
let login_data = login_form.into_inner();
|
||||
|
||||
let (session, _) = User::login(&login_data.username, &login_data.password).await?;
|
||||
|
|
|
@ -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<Library>,
|
||||
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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue