Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/Invalidations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
steps:
- uses: julia-actions/setup-julia@v2
with:
version: '1'
version: 'lts'
- uses: actions/checkout@v4
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-invalidations@v1
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name = "MIMEs"
uuid = "6c6e2e6c-3030-632d-7369-2d6c69616d65"
license = "MIT"
authors = ["Fons van der Plas <[email protected]>", "Takafumi Arakaki <[email protected]>", "Thibaut Lienart <[email protected]>"]
version = "0.1.4"
version = "1.0.0"

[compat]
julia = "1.3"
Expand Down
1 change: 1 addition & 0 deletions mimedb/Project.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[deps]
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
2 changes: 1 addition & 1 deletion mimedb/mimedb.jlon

Large diffs are not rendered by default.

28 changes: 20 additions & 8 deletions mimedb/update.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,21 @@ Pkg.instantiate()

import JSON
import Downloads: download
import OrderedCollections: OrderedDict

version = v"1.52.0"
version = v"1.53.0"

mdb = joinpath(@__DIR__, "mimedb.jlon")

_source_preference = ("nginx", "apache", nothing, "iana")



unorder(d::AbstractDict) = Dict(k => unorder(v) for (k, v) in d)
unorder(d::AbstractVector) = map(unorder, d)
unorder(x::Any) = x


# Check if there's a new version and alert the user, don't automatically take
# it as the format of the JSON may change
begin
Expand All @@ -35,11 +43,8 @@ end
begin
@info "📩 downloading the DB..."
url = "https://cdn.jsdelivr.net/gh/jshttp/mime-db@$(version)/db.json"
d = JSON.parse(read(download(url), String))
d = JSON.parse(read(download(url), String); dicttype=OrderedDict)
_mimedb = let
# https://github.com/jshttp/mime-db/issues/194
d["text/javascript"], d["application/javascript"] = d["application/javascript"], d["text/javascript"]

d["text/julia"] = Dict{String,Any}(
"charset" => "UTF-8",
"compressible" => true,
Expand All @@ -57,17 +62,19 @@ begin
# Ported straight from https://github.com/jshttp/mime-types/blob/2.1.35/index.js#L154
for (mime_str, val) in _mimedb
mime = mime_str
@assert mime isa String

exts = get(val, "extensions", nothing)
if exts === nothing
continue
end
@assert exts isa Vector
_mime2ext[mime] = exts

src = get(val, "source", nothing)
for ex in exts
if haskey(_ext2mime, ex)
other_src = get(_mimedb[identity(_ext2mime[ex])], "source", nothing)
other_src = get(_mimedb[_ext2mime[ex]], "source", nothing)

from = findfirst(isequal(other_src), _source_preference)
to = findfirst(isequal(src), _source_preference)
Expand All @@ -76,7 +83,7 @@ begin
!(_ext2mime[ex] isa MIME"application/octet-stream") &&
(
from > to ||
(from == to && startswith(identity(_ext2mime[ex]), "application/")
(from == to && startswith(_ext2mime[ex], "application/")
)
)
)
Expand All @@ -87,11 +94,16 @@ begin
_ext2mime[ex] = mime
end
end

# Changing the default mime for the .mp4 extension to video/mp4
# this is the more common and expected type, and makes the assumption that the file contains video
# The RFC https://www.rfc-editor.org/rfc/rfc4337.txt does not specify a **default** mime type for mp4 files, it should depend on content. application/mp4 should be used for mp4 files without video/audio content, so it is not necessarily a better default than video/mp4.
_ext2mime["mp4"] = "video/mp4"

@info "✏ writing to file $mdb..."
open(mdb, "w") do f
write(f, string(
(_mimedb, _ext2mime, _mime2ext)
(unorder(_mimedb), _ext2mime, _mime2ext)
)
)
end
Expand Down
4 changes: 3 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ const mdn = Dict(
".mjs" => "text/javascript",
".mp3" => "audio/mpeg",
".mp4" => "video/mp4",
".mp4s" => "application/mp4",
".mpeg" => "video/mpeg",
".ogx" => "application/ogg", ".otf" => "font/otf",
".ogx" => "application/ogg",
".otf" => "font/otf",
".png" => "image/png",
".pdf" => "application/pdf",
".rtf" => "application/rtf",
Expand Down
Loading