Merge branch 'master' of gitlab.com:shockrah/clippable

This commit is contained in:
shockrah 2021-10-26 09:57:21 -07:00
commit 57181ee75e
4 changed files with 33 additions and 4 deletions

2
.gitignore vendored
View File

@ -24,3 +24,5 @@ aws/infra/.terraform/providers/registry.terraform.io/hashicorp/aws/3.63.0/linux_
aws/infra/plan
aws/infra/terraform.tfvars
aws/playbooks/hosts
tmp/
keys/

View File

@ -2,6 +2,7 @@ use rocket_dyn_templates::Template;
use rocket::fs::NamedFile;
use std::path::{Path, PathBuf};
use std::collections::HashMap;
use crate::common::get_clips_dir;
use std::env;
// TODO: try... literally try to reduce the number of clones that happen here
@ -52,12 +53,38 @@ pub async fn category(cat: PathBuf) -> Template {
return Template::render("list", &h);
}
fn map_base_vfile(category: &PathBuf, base: &PathBuf) -> String {
// This takes a category and base filename and basically looks for the file
// that maps to those parameters
// This basically aims to get rid of the extension in the URL so that social
// media sites will bother to fetch open graph tags
let basename = base.to_string_lossy();
let dirname = format!("{}/{}/", get_clips_dir(), category.to_string_lossy());
let dir = Path::new(&dirname);
let file = dir.read_dir().ok().unwrap().find(|item| {
if let Ok(item) = item {
let name = item.file_name().into_string().unwrap();
println!("Checking name {:?}", name);
name.starts_with(basename.as_ref())
} else {
false
}
});
match file {
Some(ent) => ent.unwrap().file_name().into_string().unwrap(),
None => "/static/cantfindshit.jpg".to_string()
}
}
#[get("/clip/<cat>/<file_base>")]
pub async fn video(cat: PathBuf, file_base: PathBuf) -> Template {
pub fn video(cat: PathBuf, file_base: PathBuf) -> Template {
let mut h: HashMap<&'static str, &str> = HashMap::new();
// Look for the file_base + [extension]
let file = map_base_vfile(&cat, &file_base);
let cat = cat.to_string_lossy();
let file = file_base.to_string_lossy();
// First we have to try and find the file
let mut file_pretty = file.to_string();
for c in ["-", "_", ".mp4", ".mkv", ".webm"] {

View File

@ -66,6 +66,5 @@ pub fn list(cat: PathBuf) -> Option<Json<Vec<VideoPreview>>> {
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

@ -15,7 +15,8 @@ class VideoMeta {
let link = document.createElement('a')
if(this.name) {
link.href = `/clip/${this.category}/${this.name}`
const file_name = this.name.slice(0, this.name.lastIndexOf('.'))
link.href = `/clip/${this.category}/${file_name}`
link.text = this.name
for(const chars of ['.', '-', '_', 'mp4', 'mkv', 'webm']) {
link.text = link.text.replace(chars, ' ')