watchdogs/src/pages/watch.rs

54 lines
1.3 KiB
Rust
Raw Normal View History

2024-12-14 00:24:10 +01:00
use maud::html;
use rocket::{
get,
http::{ContentType, Status},
State,
};
use serde_json::json;
use crate::{
library::{self, Library},
pages::components::video_element,
};
use super::{
components::{render_page, HTMX},
vec_to_api,
};
#[get("/watch?<v>")]
pub async fn watch_page(
htmx: HTMX,
library: &State<Library>,
v: String,
) -> (Status, (ContentType, String)) {
let video = if let Some(video) = library.get_video_by_id(&v).await {
video
} else {
// TODO : Error handling
library.get_video_by_youtube_id(&v).await.unwrap()
};
let content = html!(
main class="container mx-auto mt-6 flex flex-col lg:flex-row gap-6" {
div class="lg:w-2/3 mt-10" {
div class="bg-black aspect-video rounded-lg overflow-hidden" {
video
controls
autoplay
class="w-full h-full" {
source src=(format!("/video/raw?v={}", video.id)) {
"Your browser does not support the video"
};
};
};
div class="p-4 bg-stone-900 rounded-lg shadow-lg mt-8" {
h2 class="text-2xl font-semibold" { (video.title) };
};
};
};
);
render_page(htmx, content, &format!("{} - WatchDogs", video.title))
}