mirror of
https://github.com/timvisee/ffsend.git
synced 2025-10-03 09:39:15 +02:00
Improve file mime guessing
This commit is contained in:
parent
b2e63b9efc
commit
8ea1b5971c
1 changed files with 4 additions and 11 deletions
|
@ -3,7 +3,7 @@ use std::io::BufReader;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
use mime_guess::{get_mime_type, Mime};
|
use mime_guess::{guess_mime_type, Mime};
|
||||||
use openssl::symm::encrypt_aead;
|
use openssl::symm::encrypt_aead;
|
||||||
use reqwest::{
|
use reqwest::{
|
||||||
Client,
|
Client,
|
||||||
|
@ -284,21 +284,14 @@ impl<'a> FileData<'a> {
|
||||||
|
|
||||||
// Get the file name
|
// Get the file name
|
||||||
let name = match path.file_name() {
|
let name = match path.file_name() {
|
||||||
Some(name) => name.to_str().expect("failed to convert string"),
|
Some(name) => name.to_str().unwrap_or("file"),
|
||||||
None => return Err(UploadError::FileError),
|
None => "file",
|
||||||
};
|
|
||||||
|
|
||||||
// Get the file extention
|
|
||||||
// TODO: handle cases where the file doesn't have an extention
|
|
||||||
let ext = match path.extension() {
|
|
||||||
Some(ext) => ext.to_str().expect("failed to convert string"),
|
|
||||||
None => return Err(UploadError::FileError),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(
|
Ok(
|
||||||
Self {
|
Self {
|
||||||
name,
|
name,
|
||||||
mime: get_mime_type(ext),
|
mime: guess_mime_type(path),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue