Skip to content

Commit

Permalink
feat(server): allow named url shortening (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vaelatern committed Dec 5, 2024
1 parent db3ceec commit 00153af
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/paste.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ impl Paste {
///
/// [`random_url.enabled`]: crate::random::RandomURLConfig::enabled
#[allow(deprecated)]
pub fn store_url(&self, expiry_date: Option<u128>, config: &Config) -> IoResult<String> {
pub fn store_url(&self, expiry_date: Option<u128>, header_filename: Option<String>, config: &Config) -> IoResult<String> {
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()))?;
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down

0 comments on commit 00153af

Please sign in to comment.