Skip to content

Commit b582500

Browse files
committed
start path validation
1 parent 8d6d7bb commit b582500

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

src/utils.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use reqwest::header::{HeaderMap, ACCEPT, USER_AGENT};
22
use serde_json::Value;
3+
use std::path::{Path, PathBuf};
34

45
pub fn request(url: String) -> Result<Value, Box<dyn std::error::Error>> {
56
let headers = construct_header();
@@ -23,3 +24,15 @@ pub fn pretty_dates(date: &str) -> String {
2324
let date = date[0].split('-').collect::<Vec<&str>>();
2425
format!("{}-{}-{}", date[2], date[1], date[0])
2526
}
27+
28+
pub fn validate_path(path: String) -> Result<PathBuf, String> {
29+
let real_path = Path::new(&path);
30+
31+
if !real_path.exists() {
32+
return Err(format!("Failed to find path \"{}\"", path));
33+
}
34+
35+
36+
37+
Ok(real_path.to_owned())
38+
}

0 commit comments

Comments
 (0)