build short uri

This commit is contained in:
yggverse 2025-02-22 01:48:06 +02:00
parent 2532b3e11c
commit a5e345eaa8
2 changed files with 20 additions and 1 deletions

View file

@ -139,7 +139,18 @@ fn handle(argument: Arc<Argument>, peer: SocketAddr, stream: &mut TlsStream<TcpS
Ok(_) => 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,

View file

@ -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 {} */
}