static files
This commit is contained in:
parent
a0e7c5d3c1
commit
6c1f2bb84b
3 changed files with 15 additions and 23 deletions
|
@ -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
Add a link
Reference in a new issue