fix: unknown mime-type of inode/x-empty (#36)

This commit is contained in:
三咲雅 · Misaki Masa 2023-08-08 15:47:27 +08:00 committed by GitHub
parent d9624cf42f
commit e123137823
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 0 deletions

View File

@ -59,6 +59,7 @@ impl Preview {
self.handle = Some(tokio::spawn(async move { self.handle = Some(tokio::spawn(async move {
let result = match kind { let result = match kind {
MimeKind::Empty => Ok(PreviewData::None),
MimeKind::Archive => Self::archive(&path).await.map(PreviewData::Text), MimeKind::Archive => Self::archive(&path).await.map(PreviewData::Text),
MimeKind::Dir => Self::folder(&path).await, MimeKind::Dir => Self::folder(&path).await,
MimeKind::Image => Self::image(&path).await, MimeKind::Image => Self::image(&path).await,

View File

@ -2,6 +2,8 @@ pub const MIME_DIR: &str = "inode/directory";
#[derive(Clone, Copy, PartialEq, Eq)] #[derive(Clone, Copy, PartialEq, Eq)]
pub enum MimeKind { pub enum MimeKind {
Empty,
Archive, Archive,
Dir, Dir,
@ -17,6 +19,10 @@ pub enum MimeKind {
impl MimeKind { impl MimeKind {
pub fn valid(s: &str) -> bool { pub fn valid(s: &str) -> bool {
if s == "inode/x-empty" {
return true;
}
let parts = s.split('/').collect::<Vec<_>>(); let parts = s.split('/').collect::<Vec<_>>();
if parts.len() != 2 { if parts.len() != 2 {
return false; return false;
@ -47,6 +53,8 @@ impl MimeKind {
Self::Image Self::Image
} else if s.starts_with("video/") { } else if s.starts_with("video/") {
Self::Video Self::Video
} else if s == "inode/x-empty" {
Self::Empty
} else if s == "application/json" { } else if s == "application/json" {
Self::JSON Self::JSON
} else if s == "application/pdf" { } else if s == "application/pdf" {