mirror of
https://github.com/amigan/rustypaste-pretty.git
synced 2024-11-21 20:09:48 -05:00
parent
60c25e2fbc
commit
315585db36
1 changed files with 11 additions and 4 deletions
15
src/file.rs
15
src/file.rs
|
@ -1,6 +1,7 @@
|
|||
use crate::config::Config;
|
||||
use std::fs::File;
|
||||
use std::io::{Result as IoResult, Write};
|
||||
use std::path::PathBuf;
|
||||
|
||||
/// Writes the bytes to a file in upload directory.
|
||||
///
|
||||
|
@ -10,10 +11,16 @@ use std::io::{Result as IoResult, Write};
|
|||
///
|
||||
/// [`default_extension`]: crate::config::PasteConfig::default_extension
|
||||
/// [`random_url.enabled`]: crate::random::RandomURLConfig::enabled
|
||||
pub fn save(mut file_name: &str, bytes: &[u8], config: &Config) -> IoResult<String> {
|
||||
if file_name == "-" {
|
||||
file_name = "stdin";
|
||||
}
|
||||
pub fn save(file_name: &str, bytes: &[u8], config: &Config) -> IoResult<String> {
|
||||
let file_name = match PathBuf::from(file_name)
|
||||
.file_name()
|
||||
.map(|v| v.to_str())
|
||||
.flatten()
|
||||
{
|
||||
Some("-") => String::from("stdin"),
|
||||
Some(v) => v.to_string(),
|
||||
None => String::from("file"),
|
||||
};
|
||||
let mut path = config.server.upload_path.join(file_name);
|
||||
match path.clone().extension() {
|
||||
Some(extension) => {
|
||||
|
|
Loading…
Reference in a new issue