feat: todo's, add image cache control

This commit is contained in:
2026-03-20 21:47:48 +01:00
parent 12388a9908
commit 0dbc9dcbc1
8 changed files with 143 additions and 38 deletions

39
src/utils.rs Normal file
View File

@@ -0,0 +1,39 @@
pub mod web {
/// Macro shenanigans to format a str at compile time
pub macro make_static_cache_header($max_age:expr, $stale_revalidate:expr) {{
// type guards lmfao
const _: ::std::time::Duration = $max_age;
const _: ::std::time::Duration = $stale_revalidate;
// hopefully ident encapsulation will save my ass here
const MAX_AGE: u64 = $max_age.as_secs();
const STALE_REVALIDATE: u64 = $stale_revalidate.as_secs();
const_str::format!(
"public, max-age={}, stale-while-revalidate={}",
MAX_AGE,
STALE_REVALIDATE
)
}}
#[cfg(test)]
mod test {
use std::time::Duration;
#[test]
fn const_concat_worked() {
const MA: Duration = Duration::from_mins(15);
const SR: Duration = Duration::from_hours(1);
const NAME: &str = super::make_static_cache_header!(MA, SR);
assert_eq!(
NAME,
format!(
"public, max-age={}, stale-while-revalidate={}",
MA.as_secs(),
SR.as_secs()
)
);
}
}
}