diff --git a/.githooks/pre-commit b/.githooks/pre-commit index c56b19ca7..5bfa4332f 100755 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -40,7 +40,7 @@ fi rust_files=$(echo "$files" | { grep -E '\.rs$' || true; }) if [[ -n "$rust_files" ]]; then if command -v cargo &> /dev/null; then - echo "$rust_files" | step xargs cargo fmt --manifest-path native/Cargo.toml -- + echo "$rust_files" | step xargs cargo fmt --manifest-path native/philomena/Cargo.toml -- else info "Skipping rustfmt, cargo not found" fi diff --git a/native/philomena/Cargo.lock b/native/philomena/Cargo.lock index 9cab0d36d..d40119f5e 100644 --- a/native/philomena/Cargo.lock +++ b/native/philomena/Cargo.lock @@ -782,7 +782,6 @@ checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" name = "mediaproc" version = "0.1.0" dependencies = [ - "once_cell", "serde", "tarpc", "tokio", @@ -964,7 +963,6 @@ dependencies = [ "http", "jemallocator", "mediaproc", - "once_cell", "regex", "ring", "rustler", diff --git a/native/philomena/Cargo.toml b/native/philomena/Cargo.toml index e624be8ed..6a29d1f7a 100644 --- a/native/philomena/Cargo.toml +++ b/native/philomena/Cargo.toml @@ -23,14 +23,9 @@ comrak = { git = "https://github.com/philomena-dev/comrak", branch = "philomena- http = "1.3" jemallocator = { version = "0.5.0", features = ["disable_initial_exec_tls"] } mediaproc = { path = "./mediaproc" } -once_cell = "1.21" regex = "1" ring = "0.17" rustler = "0.37" tokio = { version = "1.0", features = ["full"] } url = "2.5" zip = { version = "5.1.1", features = ["deflate"], default-features = false } - -[profile.release] -opt-level = 3 -lto = true diff --git a/native/philomena/mediaproc/Cargo.toml b/native/philomena/mediaproc/Cargo.toml index 246b707b3..6898802c4 100644 --- a/native/philomena/mediaproc/Cargo.toml +++ b/native/philomena/mediaproc/Cargo.toml @@ -4,7 +4,6 @@ version = "0.1.0" edition = "2024" [dependencies] -once_cell = "1.20" serde = { version = "1.0", features = ["derive"] } tarpc = { version = "0.35", features = ["full"] } tokio = { version = "1.0", features = ["full"] } diff --git a/native/philomena/mediaproc/src/client.rs b/native/philomena/mediaproc/src/client.rs index f76ef6d5e..8b4704f9a 100644 --- a/native/philomena/mediaproc/src/client.rs +++ b/native/philomena/mediaproc/src/client.rs @@ -4,7 +4,7 @@ use std::path::Path; use std::time::{Duration, Instant}; use crate::{CommandReply, ExecuteCommandError, FileMap, MediaProcessorClient}; -use once_cell::sync::Lazy; +use std::sync::LazyLock; use tarpc::context::Context; #[derive(Default)] @@ -18,7 +18,7 @@ struct CallParameters { } /// List of file extensions which can be forwarded. -static FORWARDED_EXTS: Lazy> = Lazy::new(|| { +static FORWARDED_EXTS: LazyLock> = LazyLock::new(|| { vec![ "gif", "jpg", "jpeg", "png", "svg", "webm", "webp", "mp4", "icc", ] diff --git a/native/philomena/mediaproc/src/lib.rs b/native/philomena/mediaproc/src/lib.rs index a53520ba4..a46bd2648 100644 --- a/native/philomena/mediaproc/src/lib.rs +++ b/native/philomena/mediaproc/src/lib.rs @@ -1,6 +1,6 @@ -use once_cell::sync::Lazy; use serde::{Deserialize, Serialize}; use std::collections::{HashMap, HashSet}; +use std::sync::LazyLock; pub mod client; @@ -32,7 +32,7 @@ pub enum ExecuteCommandError { } /// Enumeration of permitted program names. -pub static PERMITTED_PROGRAMS: Lazy> = Lazy::new(|| { +pub static PERMITTED_PROGRAMS: LazyLock> = LazyLock::new(|| { vec![ "ffprobe", "ffmpeg", diff --git a/native/philomena/src/asyncnif.rs b/native/philomena/src/asyncnif.rs index faf845844..017684eb8 100644 --- a/native/philomena/src/asyncnif.rs +++ b/native/philomena/src/asyncnif.rs @@ -1,10 +1,10 @@ -use once_cell::sync::Lazy; use rustler::{Atom, Env, OwnedEnv, Term}; use std::future::Future; use std::marker::Send; +use std::sync::LazyLock; use tokio::runtime::Runtime; -static RUNTIME: Lazy = Lazy::new(|| Runtime::new().unwrap()); +static RUNTIME: LazyLock = LazyLock::new(|| Runtime::new().unwrap()); pub fn call_async(caller_env: Env, fut: F, w: W) -> Atom where diff --git a/native/philomena/src/camo.rs b/native/philomena/src/camo.rs index 7068daafb..9c8fcca88 100644 --- a/native/philomena/src/camo.rs +++ b/native/philomena/src/camo.rs @@ -27,7 +27,7 @@ fn untrusted_host(url: Url, camo_host: &str, camo_key: &str) -> Option { Some(camo_uri.to_string()) } -pub fn image_url(uri: &str) -> Option { +pub fn try_image_url(uri: &str) -> Option { let cdn_host = env::var("CDN_HOST").ok()?; let camo_host = env::var("CAMO_HOST").unwrap_or_else(|_| "".into()); let camo_key = env::var("CAMO_KEY").unwrap_or_else(|_| "".into()); @@ -45,6 +45,6 @@ pub fn image_url(uri: &str) -> Option { } } -pub fn image_url_careful(uri: &str) -> String { - image_url(uri).unwrap_or_else(|| "".into()) +pub fn image_url(uri: &str) -> String { + try_image_url(uri).unwrap_or_else(|| "".into()) } diff --git a/native/philomena/src/domains.rs b/native/philomena/src/domains.rs index 9bcacfc98..3e82e9789 100644 --- a/native/philomena/src/domains.rs +++ b/native/philomena/src/domains.rs @@ -2,12 +2,12 @@ use std::collections::BTreeSet; use std::env; use http::Uri; -use once_cell::sync::Lazy; use regex::Regex; +use std::sync::LazyLock; pub type DomainSet = BTreeSet; -static DOMAINS: Lazy> = Lazy::new(|| { +static DOMAINS: LazyLock> = LazyLock::new(|| { if let Ok(domains) = env::var("SITE_DOMAINS") { return Some(domains.split(',').map(|s| s.to_string()).collect()); } @@ -19,7 +19,7 @@ pub fn get() -> &'static Option { &DOMAINS } -pub fn relativize(domains: &DomainSet, url: &str) -> Option { +pub fn try_relativize(domains: &DomainSet, url: &str) -> Option { let uri = url.parse::().ok()?; if let Some(a) = uri.authority() { @@ -33,6 +33,6 @@ pub fn relativize(domains: &DomainSet, url: &str) -> Option { Some(url.into()) } -pub fn relativize_careful(domains: &DomainSet, url: &str) -> String { - relativize(domains, url).unwrap_or_else(|| url.into()) +pub fn relativize(domains: &DomainSet, url: &str) -> String { + try_relativize(domains, url).unwrap_or_else(|| url.into()) } diff --git a/native/philomena/src/lib.rs b/native/philomena/src/lib.rs index f2f5893ea..eec279585 100644 --- a/native/philomena/src/lib.rs +++ b/native/philomena/src/lib.rs @@ -34,7 +34,7 @@ fn markdown_to_html_unsafe(input: &str, reps: HashMap) -> String #[rustler::nif] fn camo_image_url(input: &str) -> String { - camo::image_url_careful(input) + camo::image_url(input) } // Remote NIF wrappers. diff --git a/native/philomena/src/markdown.rs b/native/philomena/src/markdown.rs index 0606a2826..539a67888 100644 --- a/native/philomena/src/markdown.rs +++ b/native/philomena/src/markdown.rs @@ -26,12 +26,11 @@ pub fn common_options() -> Options<'static> { options.extension.philomena = true; options.render.ignore_empty_links = true; - options.extension.image_url_rewriter = Some(Arc::new(|url: &str| camo::image_url_careful(url))); + options.extension.image_url_rewriter = Some(Arc::new(|url: &str| camo::image_url(url))); if let Some(domains) = domains::get() { - options.extension.link_url_rewriter = Some(Arc::new(|url: &str| { - domains::relativize_careful(domains, url) - })); + options.extension.link_url_rewriter = + Some(Arc::new(|url: &str| domains::relativize(domains, url))); } options diff --git a/native/philomena/src/tests.rs b/native/philomena/src/tests.rs index 6a2cddef5..5bafbed5d 100644 --- a/native/philomena/src/tests.rs +++ b/native/philomena/src/tests.rs @@ -237,7 +237,7 @@ fn image_mention_line_start() { #[test] fn auto_relative_links() { let domains = Arc::new(vec!["example.com".into()].into_iter().collect()); - let f = Arc::new(move |url: &str| domains::relativize_careful(&*domains, url)); + let f = Arc::new(move |url: &str| domains::relativize(&*domains, url)); html_opts_i( "[some link text](https://example.com/some/path)",