-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
68 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
defmodule Bonfire.Files.MimeTypes do | ||
# NOTE: this file is here just as a fallback and is intended to get overridden by bonfire_files extension | ||
|
||
def supported_media, | ||
do: | ||
Map.merge(image_media(), video_media()) | ||
|> Map.merge(extra_media()) | ||
|
||
# TODO: how can we make these editable or at least extensible with ENV vars? | ||
|
||
# NOTE: first extension will be considered canonical | ||
|
||
def image_media, | ||
do: %{ | ||
"image/png" => ["png"] | ||
} | ||
|
||
def video_media, do: %{} | ||
|
||
def extra_media, | ||
do: %{ | ||
"application/json" => ["json"], | ||
"application/activity+json" => ["activity+json"], | ||
"application/ld+json" => ["ld+json"], | ||
"application/jrd+json" => ["jrd+json"] | ||
} | ||
|
||
# define which is preferred when more than one | ||
def unique_extension_for_mime do | ||
supported_media() | ||
|> Enum.flat_map(fn {mime, extensions} -> | ||
extensions | ||
|> Enum.reverse() | ||
|> Enum.map(fn ext -> {ext, mime} end) | ||
end) | ||
# |> Enum.uniq_by(fn {x, _} -> x end) | ||
|> Map.new() | ||
end | ||
end |