* /api/categories/<cat> fully working and cleaned up
This commit is contained in:
parent
7725ff5e1d
commit
69dfa488d9
2
.gitignore
vendored
2
.gitignore
vendored
@ -10,4 +10,4 @@ frontend/themes/clippable/static/js/index.js
|
|||||||
frontend/public/
|
frontend/public/
|
||||||
frontend/themes/clippable/static/js/category.js
|
frontend/themes/clippable/static/js/category.js
|
||||||
frontend/themes/clippable/static/js/collection.js
|
frontend/themes/clippable/static/js/collection.js
|
||||||
api/static/js/index.js
|
api/static/js/
|
||||||
|
@ -26,7 +26,7 @@ fn vid_file_entries(path: &str) -> std::io::Result<Vec<DirEntry>> {
|
|||||||
return Ok(entries);
|
return Ok(entries);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_thumbnail(clips_dir: &str, vid_file: &str) -> std::io::Result<Option<String>> {
|
pub fn get_video_preview(clips_dir: &str, vid_file: &str) -> std::io::Result<VideoPreview> {
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
// Contruct the full path to the video file itself
|
// Contruct the full path to the video file itself
|
||||||
// NOTE: thumbnail file names are basically file.mkv.jpg
|
// NOTE: thumbnail file names are basically file.mkv.jpg
|
||||||
@ -41,20 +41,25 @@ pub fn get_thumbnail(clips_dir: &str, vid_file: &str) -> std::io::Result<Option<
|
|||||||
|
|
||||||
if !path.is_file() {
|
if !path.is_file() {
|
||||||
println!("File {:?} not found", path);
|
println!("File {:?} not found", path);
|
||||||
return Ok(None)
|
let e = std::io::Error::new(std::io::ErrorKind::NotFound, "Thumbnail file not found");
|
||||||
|
return Err(e);
|
||||||
}
|
}
|
||||||
println!("Found file {:?}", path);
|
|
||||||
|
|
||||||
// Read into a vec so that base64 can deal with it
|
// Read into a vec so that base64 can deal with it
|
||||||
let mut buf = Vec::new();
|
let mut buf = Vec::new();
|
||||||
let mut file = std::fs::File::open(path)?;
|
let mut file = std::fs::File::open(path)?;
|
||||||
file.read_to_end(&mut buf)?;
|
file.read_to_end(&mut buf)?;
|
||||||
|
|
||||||
let nail = base64::encode(buf).to_string();
|
let thumbnail = base64::encode(buf).to_string();
|
||||||
return match nail.len() {
|
let thumbnail = match thumbnail.len() {
|
||||||
0 => Ok(None),
|
0 => None,
|
||||||
_ => Ok(Some(nail))
|
_ => Some(thumbnail)
|
||||||
};
|
};
|
||||||
|
let name = match path.file_name() {
|
||||||
|
Some(val) => val.to_string_lossy().to_string(),
|
||||||
|
None => String::new()
|
||||||
|
};
|
||||||
|
Ok(VideoPreview { name, thumbnail })
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/category/<cat>")]
|
#[get("/category/<cat>")]
|
||||||
@ -77,11 +82,10 @@ pub fn list(cat: String) -> Json<Vec<VideoPreview>> {
|
|||||||
for vf in vid_files {
|
for vf in vid_files {
|
||||||
// jfc this is rarted
|
// jfc this is rarted
|
||||||
let name = vf.file_name().to_string_lossy().to_string();
|
let name = vf.file_name().to_string_lossy().to_string();
|
||||||
let thumbnail = match get_thumbnail(&thumbs_dir, &name) {
|
match get_video_preview(&thumbs_dir, &name) {
|
||||||
Ok(val) => val,
|
Ok(val) => json.push(val),
|
||||||
_ => None
|
_ => continue
|
||||||
};
|
};
|
||||||
json.push(VideoPreview { name, thumbnail })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Json(json)
|
return Json(json)
|
||||||
|
Loading…
Reference in New Issue
Block a user