+ 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()
}

View File

@ -0,0 +1,30 @@
<!DOCTYPE html>
<html lang="en"><head>
<meta name="generator" content="Hugo 0.88.1" />
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="/static/css/style.css">
<link rel="stylesheet" href="https://unpkg.com/purecss@1.0.0/build/pure-min.css" integrity="sha384-nn4HPE8lTHyVtfCBi5yW9d20FjT8BJwUXyWZT9InLYax14RDjBj46LmSztkmNP9w" crossorigin="anonymous">
<title>Shockrah&#39;s Clips</title>
<link rel="shortcut icon" type="image/png" href="/static/favicon.png"/>
<meta property="og:title" content="{{title}}">
<meta property="og:site_name" content="Clippable">
<meta property="og:url" content="{{url}}">
<meta property="og:description" content="{{desc}}">
<meta property="og:type" content="website">
{# Image tag requires a default in case of disk memery #}
<meta property="og:image" content="/static/favicon.png">
{% if script %}
<script src="/static/js/{{script_src}}"></script>
{% endif %}
</head>
<body>
<div id="layout">
<div class="content">
<h1></h1>
<div class="video-gallery" id="main-container">
</div>
</div>
</div>
</body>
</html>