diff --git a/Cargo.lock b/Cargo.lock index 3a7b8f0..96a24b7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -158,7 +158,7 @@ checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" [[package]] name = "based" version = "0.1.0" -source = "git+https://git.hydrar.de/jmarya/based#a89c5661208585b2a9f09d5ee337ad1c60ea9a49" +source = "git+https://git.hydrar.de/jmarya/based#cd10c64a1f96703894de9e40a95fd81cc50d244a" dependencies = [ "bcrypt", "chrono", diff --git a/Cargo.toml b/Cargo.toml index c3cfbbd..0f163c3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,4 +24,4 @@ maud = "0.26.0" rand = "0.8.5" data-encoding = "2.6.0" bcrypt = "0.16.0" -based = { git = "https://git.hydrar.de/jmarya/based", features = ["cache"] } +based = { git = "https://git.hydrar.de/jmarya/based", features = ["cache", "htmx"] } diff --git a/src/pages/assets.rs b/src/pages/assets.rs index f6d355d..199b582 100644 --- a/src/pages/assets.rs +++ b/src/pages/assets.rs @@ -1,18 +1,12 @@ -use rocket::{ - get, - http::{ContentType, Status}, - State, -}; +use based::request::assets::DataResponse; +use rocket::{get, State}; use tokio::{fs::File, io::AsyncReadExt}; use crate::library::Library; #[get("/video/raw?")] -pub async fn video_file( - v: &str, - library: &State, -) -> Option<(Status, (ContentType, Vec))> { +pub async fn video_file(v: &str, library: &State) -> Option { let video = if let Some(video) = library.get_video_by_id(v).await { video } else { @@ -23,22 +17,19 @@ pub async fn video_file( let mut buf = Vec::with_capacity(51200); file.read_to_end(&mut buf).await.ok()?; let content_type = if video.path.ends_with("mp4") { - ContentType::new("video", "mp4") + "video/mp4" } else { - ContentType::new("video", "webm") + "video/webm" }; - return Some((Status::Ok, (content_type, buf))); + return Some(DataResponse::new(buf, content_type, Some(60 * 60 * 24 * 3))); } None } #[get("/video/thumbnail?")] -pub async fn video_thumbnail( - v: &str, - library: &State, -) -> Option<(Status, (ContentType, Vec))> { +pub async fn video_thumbnail(v: &str, library: &State) -> Option { let video = if let Some(video) = library.get_video_by_id(v).await { video } else { @@ -46,16 +37,17 @@ pub async fn video_thumbnail( }; if let Some(data) = library.get_thumbnail(&video).await { - return Some((Status::Ok, (ContentType::PNG, data))); + return Some(DataResponse::new(data, "image/png", Some(60 * 60 * 24 * 3))); } None } #[get("/favicon")] -pub async fn fav_icon() -> (Status, (ContentType, &'static [u8])) { - ( - Status::Ok, - (ContentType::PNG, include_bytes!("../../src/icon.png")), +pub async fn fav_icon() -> DataResponse { + DataResponse::new( + include_bytes!("../../src/icon.png").to_vec(), + "image/png", + Some(60 * 60 * 24 * 30), ) }