This commit is contained in:
parent
0d0265ab14
commit
764bef6457
5 changed files with 113 additions and 11 deletions
|
@ -36,23 +36,18 @@ pub async fn video_file(
|
|||
}
|
||||
|
||||
#[get("/video/thumbnail?<v>")]
|
||||
pub async fn video_thumbnail(v: &str, library: &State<Library>) -> Option<NamedFile> {
|
||||
pub async fn video_thumbnail(
|
||||
v: &str,
|
||||
library: &State<Library>,
|
||||
) -> Option<(Status, (ContentType, Vec<u8>))> {
|
||||
let video = if let Some(video) = library.get_video_by_id(v).await {
|
||||
video
|
||||
} else {
|
||||
library.get_video_by_youtube_id(v).await.unwrap()
|
||||
};
|
||||
|
||||
let path = std::path::Path::new(&video.path);
|
||||
let parent = path.parent().unwrap();
|
||||
let thumbnail_path = path.file_stem().unwrap().to_str().unwrap();
|
||||
let thumbnail_path = parent.join(thumbnail_path);
|
||||
let thumbnail_path = thumbnail_path.to_str().unwrap();
|
||||
|
||||
for ext in ["jpg", "jpeg", "png", "avif"] {
|
||||
if let Ok(file) = NamedFile::open(format!("{thumbnail_path}.{ext}")).await {
|
||||
return Some(file);
|
||||
}
|
||||
if let Some(data) = library.get_thumbnail(&video).await {
|
||||
return Some((Status::Ok, (ContentType::PNG, data)));
|
||||
}
|
||||
|
||||
None
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue