mirror of
https://github.com/YGGverse/btracker-fs.git
synced 2026-03-31 17:15:28 +00:00
implement path method
This commit is contained in:
parent
8485e323f6
commit
91d37e2810
1 changed files with 18 additions and 0 deletions
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue