use std::path::Path;
use crate::models::{FileInfo, FileType};
pub(crate) fn file(path: &str) -> FileInfo {
FileInfo::new(
Path::new(path)
.file_name()
.and_then(|n| n.to_str())
.unwrap_or_default()
.to_string(),
Path::new(path)
.file_stem()
.and_then(|n| n.to_str())
.unwrap_or_default()
.to_string(),
Path::new(path)
.extension()
.and_then(|n| n.to_str())
.map(|ext| format!(".{ext}"))
.unwrap_or_default(),
path.to_string(),
FileType::File,
None,
1,
None,
None,
None,
None,
None,
Vec::new(),
None,
Vec::new(),
Vec::new(),
Vec::new(),
Vec::new(),
Vec::new(),
Vec::new(),
Vec::new(),
Vec::new(),
Vec::new(),
)
}
pub(crate) fn dir(path: &str) -> FileInfo {
FileInfo::new(
Path::new(path)
.file_name()
.and_then(|n| n.to_str())
.unwrap_or_default()
.to_string(),
Path::new(path)
.file_name()
.and_then(|n| n.to_str())
.unwrap_or_default()
.to_string(),
String::new(),
path.to_string(),
FileType::Directory,
None,
0,
None,
None,
None,
None,
None,
Vec::new(),
None,
Vec::new(),
Vec::new(),
Vec::new(),
Vec::new(),
Vec::new(),
Vec::new(),
Vec::new(),
Vec::new(),
Vec::new(),
)
}
pub(crate) fn json_file(path: &str, file_type: crate::models::FileType) -> FileInfo {
FileInfo::new(
Path::new(path)
.file_name()
.and_then(|name| name.to_str())
.unwrap_or_default()
.to_string(),
Path::new(path)
.file_stem()
.and_then(|name| name.to_str())
.unwrap_or_default()
.to_string(),
Path::new(path)
.extension()
.and_then(|name| name.to_str())
.map(|ext| format!(".{ext}"))
.unwrap_or_default(),
path.to_string(),
file_type,
None,
0,
None,
None,
None,
None,
None,
Vec::new(),
None,
Vec::new(),
Vec::new(),
Vec::new(),
Vec::new(),
Vec::new(),
Vec::new(),
Vec::new(),
Vec::new(),
Vec::new(),
)
}