From 9abcbed29912a6d842cc085ea4f7430dc071f0a4 Mon Sep 17 00:00:00 2001 From: Romain Calascibetta Date: Fri, 24 Jun 2022 17:42:03 +0200 Subject: [PATCH] Use conan instead of magic-mime package --- builder-web.opam | 2 ++ lib/builder_web.ml | 8 ++++++-- lib/dune | 2 ++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/builder-web.opam b/builder-web.opam index 5dfd9a0..7cb1b27 100644 --- a/builder-web.opam +++ b/builder-web.opam @@ -53,6 +53,8 @@ depends: [ "alcotest" {with-test} "ppx_deriving" {with-test} "ppx_deriving_yojson" {with-test} + "conan-unix" {>= "0.0.2"} + "conan-database" {>= "0.0.2"} ] synopsis: "Web interface for builder" diff --git a/lib/builder_web.ml b/lib/builder_web.ml index 5ed367b..4b3c359 100644 --- a/lib/builder_web.ml +++ b/lib/builder_web.ml @@ -60,12 +60,16 @@ let mime_lookup path = (match Fpath.to_string path with | "build-environment" | "opam-switch" | "system-packages" -> "text/plain" - | _ -> + | filename -> if Fpath.has_ext "build-hashes" path then "text/plain" else if Fpath.is_prefix Fpath.(v "bin/") path then "application/octet-stream" - else Magic_mime.lookup (Fpath.to_string path)) + else match Option.bind + (Result.to_option (Conan_unix.run_with_tree Conan_magic_database.tree filename)) + Conan.Metadata.mime with + | Some mime_type -> mime_type + | None -> "application/octet-stream" (* default *)) let string_of_html = Format.asprintf "%a" (Tyxml.Html.pp ()) diff --git a/lib/dune b/lib/dune index c0fab85..9f1e659 100644 --- a/lib/dune +++ b/lib/dune @@ -18,4 +18,6 @@ decompress.de decompress.gz uri + conan-unix + conan-database ))