Make mime type for importing files optional

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/4/head
trivernis 3 years ago
parent 52aa9d4f20
commit 70ef6246a1

@ -175,9 +175,7 @@ async fn resolve_subdir(entry: DirEntry) -> PluginResult<Vec<DirEntry>> {
/// metadata for it /// metadata for it
#[tracing::instrument(level = "trace")] #[tracing::instrument(level = "trace")]
async fn retrieve_file_information(path: PathBuf) -> PluginResult<FileOSMetadata> { async fn retrieve_file_information(path: PathBuf) -> PluginResult<FileOSMetadata> {
let mime = mime_guess::from_path(&path) let mime = mime_guess::from_path(&path).first();
.first()
.ok_or_else(|| format!("Could not guess mime for file {:?}", path))?;
let metadata = fs::metadata(&path).await?; let metadata = fs::metadata(&path).await?;
let creation_time = metadata.created()?; let creation_time = metadata.created()?;
let change_time = metadata.modified()?; let change_time = metadata.modified()?;
@ -188,7 +186,7 @@ async fn retrieve_file_information(path: PathBuf) -> PluginResult<FileOSMetadata
let os_metadata = FileOSMetadata { let os_metadata = FileOSMetadata {
path: path.to_string_lossy().to_string(), path: path.to_string_lossy().to_string(),
name: name.to_string_lossy().to_string(), name: name.to_string_lossy().to_string(),
mime_type: mime.to_string(), mime_type: mime.map(|m| m.to_string()),
creation_time: system_time_to_naive_date_time(creation_time), creation_time: system_time_to_naive_date_time(creation_time),
change_time: system_time_to_naive_date_time(change_time), change_time: system_time_to_naive_date_time(change_time),
}; };

@ -89,7 +89,7 @@ pub struct FileMetadataResponse {
pub struct FileOSMetadata { pub struct FileOSMetadata {
pub path: String, pub path: String,
pub name: String, pub name: String,
pub mime_type: String, pub mime_type: Option<String>,
pub creation_time: NaiveDateTime, pub creation_time: NaiveDateTime,
pub change_time: NaiveDateTime, pub change_time: NaiveDateTime,
} }

Loading…
Cancel
Save