Check upload name to make sure its an image or video
All checks were successful
Core Repos/ImageApi/pipeline/head This commit looks good
All checks were successful
Core Repos/ImageApi/pipeline/head This commit looks good
The upload code should be additionally refactored to probably do a more comprehensive check of if the file is an image or video.
This commit is contained in:
11
src/files.rs
11
src/files.rs
@@ -1,4 +1,3 @@
|
||||
use std::ffi::OsStr;
|
||||
use std::fs::read_dir;
|
||||
use std::io;
|
||||
use std::io::Error;
|
||||
@@ -22,13 +21,11 @@ pub fn list_files(dir: PathBuf) -> io::Result<Vec<PathBuf>> {
|
||||
Ok(files)
|
||||
}
|
||||
|
||||
fn is_image_or_video(path: &Path) -> bool {
|
||||
let extension = &path
|
||||
pub fn is_image_or_video(path: &Path) -> bool {
|
||||
let extension = path
|
||||
.extension()
|
||||
.unwrap_or_else(|| OsStr::new(""))
|
||||
.to_str()
|
||||
.unwrap_or("")
|
||||
.to_lowercase();
|
||||
.and_then(|p| p.to_str())
|
||||
.map_or(String::from(""), |p| p.to_lowercase());
|
||||
|
||||
extension == "png"
|
||||
|| extension == "jpg"
|
||||
|
||||
Reference in New Issue
Block a user