static files
This commit is contained in:
parent
a0e7c5d3c1
commit
6c1f2bb84b
3 changed files with 15 additions and 23 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -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",
|
||||
|
|
|
@ -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"] }
|
||||
|
|
|
@ -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?<v>")]
|
||||
pub async fn video_file(
|
||||
v: &str,
|
||||
library: &State<Library>,
|
||||
) -> Option<(Status, (ContentType, Vec<u8>))> {
|
||||
pub async fn video_file(v: &str, library: &State<Library>) -> Option<DataResponse> {
|
||||
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?<v>")]
|
||||
pub async fn video_thumbnail(
|
||||
v: &str,
|
||||
library: &State<Library>,
|
||||
) -> Option<(Status, (ContentType, Vec<u8>))> {
|
||||
pub async fn video_thumbnail(v: &str, library: &State<Library>) -> Option<DataResponse> {
|
||||
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),
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue