feat(paste): guess the extension if it is not present

This commit is contained in:
orhun 2021-07-24 15:09:11 +03:00
parent 12c204bf03
commit ef57b48868
No known key found for this signature in database
GPG key ID: F83424824B3E4B90
3 changed files with 16 additions and 1 deletions

7
Cargo.lock generated
View file

@ -926,6 +926,12 @@ dependencies = [
"hashbrown",
]
[[package]]
name = "infer"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea70330449622910e0edebab230734569516269fb32342fb0a8956340fa48c6c"
[[package]]
name = "instant"
version = "0.1.10"
@ -1241,6 +1247,7 @@ dependencies = [
"dotenv",
"env_logger",
"futures-util",
"infer",
"log",
"petname",
"rand 0.8.4",

View file

@ -22,6 +22,10 @@ dotenv = "0.15.0"
version = "4.0.12"
features = ["serde"]
[dependencies.infer]
version = "0.5.0"
default-features = false
[dev-dependencies]
actix-rt = "2.2.0"

View file

@ -52,7 +52,11 @@ pub fn save(mut file_name: &str, bytes: &[u8], config: &Config) -> IoResult<Stri
.collect::<String>(),
);
}
path.set_extension(&config.paste.default_extension);
path.set_extension(
infer::get(bytes)
.map(|t| t.extension())
.unwrap_or(&config.paste.default_extension),
);
}
}
let mut buffer = File::create(&path)?;