diff --git a/src/main.rs b/src/main.rs index b6baa3f..f8a3b28 100644 --- a/src/main.rs +++ b/src/main.rs @@ -139,7 +139,18 @@ fn handle(argument: Arc, peer: SocketAddr, stream: &mut TlsStream match tmp.commit() { Ok(pmt) => send( &response::redirect::Permanent { - target: pmt.path.to_str().unwrap().to_owned(), + target: match argument.redirect { + Some(ref target) => format!( + "{}/{}", + target.trim_end_matches("/"), + pmt.to_uri(&argument.directory) + ), + None => format!( + "gemini://{}/{}", + argument.bind, + pmt.to_uri(&argument.directory) + ) + }, } .into_bytes(), stream, diff --git a/src/storage.rs b/src/storage.rs index c89d6a7..fffe68d 100644 --- a/src/storage.rs +++ b/src/storage.rs @@ -89,6 +89,14 @@ impl Item { // Getters + pub fn to_uri(&self, directory: &str) -> String { + self.path + .to_str() + .unwrap() + .replace(directory, "") + .replace("/", "") + } + /* @TODO implement short links handle without slash pub fn alias(&self, relative: &str) -> String {} */ }