From 91d37e2810e74b6df038c9f086ca40299aab4df1 Mon Sep 17 00:00:00 2001 From: yggverse Date: Mon, 8 Sep 2025 23:22:40 +0300 Subject: [PATCH] implement path method --- src/public.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/public.rs b/src/public.rs index 862123c..6ba1fb8 100644 --- a/src/public.rs +++ b/src/public.rs @@ -74,6 +74,9 @@ impl Public { Ok((t, b)) } + /// Build URI for given `path` + /// + /// * result requires URL encode pub fn href(&self, info_hash: &str, path: &str) -> Option { let mut relative = PathBuf::from(info_hash); relative.push(path); @@ -89,6 +92,21 @@ impl Public { } } + /// Return canonical absolute path + /// + /// * `None` if the given URI does not exist or has denied location + pub fn path(&self, relative: &str) -> Option { + let mut p = PathBuf::from(&self.root); + p.push(&relative); + + let path = p.canonicalize().ok()?; + if path.starts_with(&self.root) && c.exists() { + Some(path) + } else { + None + } + } + // Helpers fn files(