From 54b2b55fcb7578401cd5f284f2a0de1137a3e437 Mon Sep 17 00:00:00 2001 From: shockrah Date: Mon, 25 Oct 2021 22:01:21 -0700 Subject: [PATCH 1/3] + More stuff to ignore for windows env --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 39677f8..1befca5 100644 --- a/.gitignore +++ b/.gitignore @@ -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/ From 6bb44e5d05a3ff16b90eaf283db52b0b8f32fe2c Mon Sep 17 00:00:00 2001 From: shockrah Date: Mon, 25 Oct 2021 23:31:18 -0700 Subject: [PATCH 2/3] + Added support on /clips// to ignore the file extension With this the frontend can produce opengraph fetch-friendly url's --- api/src/page.rs | 31 +++++++++++++++++++++++++++++-- api/src/video.rs | 1 - 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/api/src/page.rs b/api/src/page.rs index a99379d..f0fa79e 100644 --- a/api/src/page.rs +++ b/api/src/page.rs @@ -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//")] -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"] { diff --git a/api/src/video.rs b/api/src/video.rs index 1c7d11f..b21ef4b 100644 --- a/api/src/video.rs +++ b/api/src/video.rs @@ -66,6 +66,5 @@ pub fn list(cat: PathBuf) -> Option>> { pub async fn get_video(cat: PathBuf, file: PathBuf) -> Option { 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() } From 3b0249e58af59c91da11a9b0f16dd5f6233d300a Mon Sep 17 00:00:00 2001 From: shockrah Date: Mon, 25 Oct 2021 23:35:51 -0700 Subject: [PATCH 3/3] - Removed file extensions from frontend --- ts/category.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ts/category.ts b/ts/category.ts index e9c7f52..b21ba00 100644 --- a/ts/category.ts +++ b/ts/category.ts @@ -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, ' ')