implement path method

This commit is contained in:
yggverse 2025-09-08 23:22:40 +03:00
parent 8485e323f6
commit 91d37e2810

View file

@ -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<String> {
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<PathBuf> {
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(