Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .githooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions native/philomena/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions native/philomena/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion native/philomena/mediaproc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
4 changes: 2 additions & 2 deletions native/philomena/mediaproc/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -18,7 +18,7 @@ struct CallParameters {
}

/// List of file extensions which can be forwarded.
static FORWARDED_EXTS: Lazy<HashSet<OsString>> = Lazy::new(|| {
static FORWARDED_EXTS: LazyLock<HashSet<OsString>> = LazyLock::new(|| {
vec![
"gif", "jpg", "jpeg", "png", "svg", "webm", "webp", "mp4", "icc",
]
Expand Down
4 changes: 2 additions & 2 deletions native/philomena/mediaproc/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -32,7 +32,7 @@ pub enum ExecuteCommandError {
}

/// Enumeration of permitted program names.
pub static PERMITTED_PROGRAMS: Lazy<HashSet<&'static str>> = Lazy::new(|| {
pub static PERMITTED_PROGRAMS: LazyLock<HashSet<&'static str>> = LazyLock::new(|| {
vec![
"ffprobe",
"ffmpeg",
Expand Down
4 changes: 2 additions & 2 deletions native/philomena/src/asyncnif.rs
Original file line number Diff line number Diff line change
@@ -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<Runtime> = Lazy::new(|| Runtime::new().unwrap());
static RUNTIME: LazyLock<Runtime> = LazyLock::new(|| Runtime::new().unwrap());

pub fn call_async<F, T, W>(caller_env: Env, fut: F, w: W) -> Atom
where
Expand Down
6 changes: 3 additions & 3 deletions native/philomena/src/camo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn untrusted_host(url: Url, camo_host: &str, camo_key: &str) -> Option<String> {
Some(camo_uri.to_string())
}

pub fn image_url(uri: &str) -> Option<String> {
pub fn try_image_url(uri: &str) -> Option<String> {
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());
Expand All @@ -45,6 +45,6 @@ pub fn image_url(uri: &str) -> Option<String> {
}
}

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())
}
10 changes: 5 additions & 5 deletions native/philomena/src/domains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>;

static DOMAINS: Lazy<Option<DomainSet>> = Lazy::new(|| {
static DOMAINS: LazyLock<Option<DomainSet>> = LazyLock::new(|| {
if let Ok(domains) = env::var("SITE_DOMAINS") {
return Some(domains.split(',').map(|s| s.to_string()).collect());
}
Expand All @@ -19,7 +19,7 @@ pub fn get() -> &'static Option<DomainSet> {
&DOMAINS
}

pub fn relativize(domains: &DomainSet, url: &str) -> Option<String> {
pub fn try_relativize(domains: &DomainSet, url: &str) -> Option<String> {
let uri = url.parse::<Uri>().ok()?;

if let Some(a) = uri.authority() {
Expand All @@ -33,6 +33,6 @@ pub fn relativize(domains: &DomainSet, url: &str) -> Option<String> {
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())
}
2 changes: 1 addition & 1 deletion native/philomena/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fn markdown_to_html_unsafe(input: &str, reps: HashMap<String, String>) -> String

#[rustler::nif]
fn camo_image_url(input: &str) -> String {
camo::image_url_careful(input)
camo::image_url(input)
}

// Remote NIF wrappers.
Expand Down
7 changes: 3 additions & 4 deletions native/philomena/src/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion native/philomena/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down
Loading