From 00153af6e1b1f48cf5486721b0563b339eba6005 Mon Sep 17 00:00:00 2001 From: Toyam Cox Date: Thu, 5 Dec 2024 17:43:02 -0500 Subject: [PATCH] feat(server): allow named url shortening (#40) --- src/paste.rs | 5 ++++- src/server.rs | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/paste.rs b/src/paste.rs index 0b6261d3..ec9bcfda 100644 --- a/src/paste.rs +++ b/src/paste.rs @@ -254,7 +254,7 @@ impl Paste { /// /// [`random_url.enabled`]: crate::random::RandomURLConfig::enabled #[allow(deprecated)] - pub fn store_url(&self, expiry_date: Option, config: &Config) -> IoResult { + pub fn store_url(&self, expiry_date: Option, header_filename: Option, config: &Config) -> IoResult { let data = str::from_utf8(&self.data) .map_err(|e| IoError::new(IoErrorKind::Other, e.to_string()))?; let url = Url::parse(data).map_err(|e| IoError::new(IoErrorKind::Other, e.to_string()))?; @@ -264,6 +264,9 @@ impl Paste { file_name = random_text; } } + if let Some(header_filename) = header_filename { + file_name = header_filename; + } let mut path = util::safe_path_join(self.type_.get_path(&config.server.upload_path)?, &file_name)?; if let Some(timestamp) = expiry_date { diff --git a/src/server.rs b/src/server.rs index 7e1173d3..2f963c7c 100644 --- a/src/server.rs +++ b/src/server.rs @@ -296,7 +296,7 @@ async fn upload( let config = config .read() .map_err(|_| error::ErrorInternalServerError("cannot acquire config"))?; - paste.store_url(expiry_date, &config)? + paste.store_url(expiry_date, header_filename, &config)? } }; info!(