diff --git a/confetti-box/Cargo.toml b/confetti-box/Cargo.toml index 2c1ad32..d97b754 100644 --- a/confetti-box/Cargo.toml +++ b/confetti-box/Cargo.toml @@ -10,6 +10,9 @@ build = "build.rs" [lints] workspace = true +[features] +git_tag = ["vergen-gix"] + [dependencies] blake3 = { version = "1.5", features = ["mmap", "rayon", "serde"] } chrono = { version = "0.4", features = ["serde"] } @@ -29,4 +32,4 @@ uuid = { version = "1.11", features = ["serde", "v4"] } [build-dependencies] -vergen-gix = { version = "1.0", features = ["build", "cargo", "rustc", "si"] } +vergen-gix = { version = "1.0", features = ["build", "cargo", "rustc", "si"], optional = true } diff --git a/confetti-box/build.rs b/confetti-box/build.rs index f0b4e51..138417c 100644 --- a/confetti-box/build.rs +++ b/confetti-box/build.rs @@ -1,23 +1,24 @@ -use vergen_gix::{BuildBuilder, CargoBuilder, Emitter, GixBuilder, RustcBuilder, SysinfoBuilder}; - fn main() { - let build = BuildBuilder::all_build().unwrap(); - let cargo = CargoBuilder::all_cargo().unwrap(); - let gitcl = GixBuilder::all_git().unwrap(); - let rustc = RustcBuilder::all_rustc().unwrap(); - let si = SysinfoBuilder::all_sysinfo().unwrap(); + #[cfg(feature = "git_tag")] + { + let build = vergen_gix::BuildBuilder::all_build().unwrap(); + let cargo = vergen_gix::CargoBuilder::all_cargo().unwrap(); + let gitcl = vergen_gix::GixBuilder::all_git().unwrap(); + let rustc = vergen_gix::RustcBuilder::all_rustc().unwrap(); + let si = vergen_gix::SysinfoBuilder::all_sysinfo().unwrap(); - Emitter::default() - .add_instructions(&build) - .unwrap() - .add_instructions(&cargo) - .unwrap() - .add_instructions(&gitcl) - .unwrap() - .add_instructions(&rustc) - .unwrap() - .add_instructions(&si) - .unwrap() - .emit() - .unwrap(); + vergen_gix::Emitter::default() + .add_instructions(&build) + .unwrap() + .add_instructions(&cargo) + .unwrap() + .add_instructions(&gitcl) + .unwrap() + .add_instructions(&rustc) + .unwrap() + .add_instructions(&si) + .unwrap() + .emit() + .unwrap(); + } } diff --git a/confetti-box/src/endpoints.rs b/confetti-box/src/endpoints.rs index 479aecc..70edec1 100644 --- a/confetti-box/src/endpoints.rs +++ b/confetti-box/src/endpoints.rs @@ -60,6 +60,11 @@ pub async fn file_info_opengraph( let title = entry.name().clone() + " - " + &size + " - " + &expiry; + let url = uri!(lookup_mmid_name( + mmid.to_string(), + entry.name() + )).to_string(); + Some(html! { (DOCTYPE) meta charset="UTF-8"; @@ -68,6 +73,12 @@ pub async fn file_info_opengraph( meta property="og:title" content=(title); meta property="twitter:title" content=(title); meta property="og:description" content={"Size: " (size) ", expires in " (expiry)}; + + body { + script { + "window.location.href = '" (url) "';" + } + } }) } diff --git a/confetti-box/src/pages.rs b/confetti-box/src/pages.rs index 11e39aa..d85c590 100644 --- a/confetti-box/src/pages.rs +++ b/confetti-box/src/pages.rs @@ -17,13 +17,10 @@ pub fn head(page_title: &str) -> Markup { } pub fn footer() -> Markup { - let hash = match option_env!("VERGEN_GIT_SHA") { - Some(hash) => &hash[0..7], - None => "", - }; + let hash = option_env!("VERGEN_GIT_SHA").map(|h| &h[0..7]); let pkg_version = env!("CARGO_PKG_VERSION"); - let hash_link = "https://github.com/Dangoware/confetti-box/commit/".to_string() + hash; + let build_date = option_env!("VERGEN_BUILD_DATE").unwrap_or_default(); html! { footer { @@ -36,8 +33,8 @@ pub fn footer() -> Markup { } p.version { "Running Confetti-Box v" (pkg_version) " " } - @if !hash.is_empty() { - p.version style="font-size: 0.8em" { "(" a style="font-family:'Fira Code'" href=(hash_link) {(hash)} " - " (env!("VERGEN_BUILD_DATE")) ")" } + @if let Some(h) = hash { + p.version style="font-size: 0.8em" { "(" a style="font-family:'Fira Code'" href={"https://github.com/Dangoware/confetti-box/commit/" (h)} {(h)} " - " (build_date) ")" } } } }