T.P.MIME, extensionFromMimeType: add a few special cases.
When we do a reverse lookup in the MIME table, we just get the last match, so when the same mime type is associated with several different extensions, we sometimes got weird results, e.g. `.vs` for `text/plain`. These special cases help us get the most standard extensions for mime types like `text/plain`.
This commit is contained in:
parent
c7dd33d5aa
commit
aa79b3035c
1 changed files with 10 additions and 0 deletions
|
@ -43,6 +43,16 @@ getMimeTypeDef :: FilePath -> MimeType
|
|||
getMimeTypeDef = fromMaybe "application/octet-stream" . getMimeType
|
||||
|
||||
extensionFromMimeType :: MimeType -> Maybe T.Text
|
||||
-- few special cases, where there are multiple options:
|
||||
extensionFromMimeType "text/plain" = Just "txt"
|
||||
extensionFromMimeType "video/quicktime" = Just "mov"
|
||||
extensionFromMimeType "video/mpeg" = Just "mpeg"
|
||||
extensionFromMimeType "video/dv" = Just "dv"
|
||||
extensionFromMimeType "image/vnd.djvu" = Just "djvu"
|
||||
extensionFromMimeType "image/tiff" = Just "tiff"
|
||||
extensionFromMimeType "image/jpeg" = Just "jpg"
|
||||
extensionFromMimeType "application/xml" = Just "xml"
|
||||
extensionFromMimeType "application/ogg" = Just "ogg"
|
||||
extensionFromMimeType mimetype =
|
||||
M.lookup (T.takeWhile (/=';') mimetype) reverseMimeTypes
|
||||
-- note: we just look up the basic mime type, dropping the content-encoding etc.
|
||||
|
|
Loading…
Add table
Reference in a new issue