+ Video clip endpoint

Let's users actually request videos
+ Meta data handling for video clip pages
+ Template for video pages
This commit is contained in:
shockrah
2021-10-13 00:21:27 -07:00
parent 2f6719081a
commit d6b076970f
4 changed files with 71 additions and 9 deletions

View File

@@ -17,11 +17,13 @@ async fn main() {
* Some of the target vars that we look for
* CLIP_DIR
*/
// Comments denote what kind of data each sub uri actually returns
let _ = rocket::build()
.mount("/", routes![page::home, page::category, page::video])
.mount("/static", routes![page::files])
.mount("/api", routes![category::list, video::list])
.mount("/thumbnail", routes![thumbnail::get])
.mount("/", routes![page::home, page::category, page::video]) // html
.mount("/static", routes![page::files]) // files
.mount("/api", routes![category::list, video::list]) // json
.mount("/thumbnail", routes![thumbnail::get]) // images
.mount("/video", routes![video::get_video]) // videos
.attach(Template::fairing())
.launch().await;
}

View File

@@ -35,10 +35,31 @@ pub async fn category(cat: PathBuf) -> Template {
return Template::render("list", &h);
}
#[get("/clip/<id>")]
pub async fn video(id: String) -> Template {
println!("id: {}", id);
return Template::render("video", &{})
#[get("/clip/<cat>/<file_base>")]
pub async fn video(cat: PathBuf, file_base: PathBuf) -> Template {
// NOTE: the "file name" does not include the
println!("{:?}, {:?}", cat, file_base);
let mut h: HashMap<&'static str, &str> = HashMap::new();
let cat = cat.to_string_lossy();
let file = file_base.to_string_lossy();
let mut file_pretty = file.to_string();
for c in ["-", "_", ".mp4", ".mkv", ".webm"] {
file_pretty = file_pretty.replace(c, " ");
}
h.insert("title", &file_pretty);
let url = format!("/clip/{}/{}", &cat, &file);
h.insert("url", &url);
h.insert("desc", &file_pretty);
let thumbnail = format!("/thumbnail/{}/{}", cat, file);
h.insert("ogimg", &thumbnail);
return Template::render("video", &h);
}
#[get("/<file..>")]

View File

@@ -1,8 +1,9 @@
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use std::fs::DirEntry;
use std::ffi::OsStr;
use serde::Serialize;
use rocket::serde::json::Json;
use rocket::fs::NamedFile;
use crate::common::get_clips_dir;
#[derive(Serialize)]
@@ -60,3 +61,11 @@ pub fn list(cat: PathBuf) -> Option<Json<Vec<VideoPreview>>> {
return None;
}
#[get("/clip/<cat>/<file>")]
pub async fn get_video(cat: PathBuf, file: PathBuf) -> Option<NamedFile> {
let clips_dir = get_clips_dir();
let path = Path::new(&clips_dir).join(cat).join(file);
println!("path to grab from : {:?}", path);
NamedFile::open(path).await.ok()
}