Commit 9b5d84f37036a726c4a4366ed243757a53407ae1

Thomas de Grivel 2022-01-07T11:28:08

default_mime

diff --git a/lib/kmxgit_web/controllers/repository_controller.ex b/lib/kmxgit_web/controllers/repository_controller.ex
index b2d0c1b..6dbf92c 100644
--- a/lib/kmxgit_web/controllers/repository_controller.ex
+++ b/lib/kmxgit_web/controllers/repository_controller.ex
@@ -235,13 +235,21 @@ defmodule KmxgitWeb.RepositoryController do
     git
   end
 
+  defp default_mime(content) do
+    if String.valid?(content) do
+      "text/plain"
+    else
+      "application/octet-stream"
+    end
+  end
+
   defp git_put_content(git = %{files: [%{name: name, sha1: sha1, type: "blob"}], valid: true}, repo, path) do
     if (path == name) do
       case GitManager.content(Repository.full_slug(repo), sha1) do
         {:ok, content} ->
           type = case Regex.run(~r/[.]([^.]+)$/, path) do
-                   [_, ext] -> MIME.type(ext) || "application/octet-stream"
-                   _ -> if String.valid?(content), do: "text/plain", else: "application/octet-stream"
+                   [_, ext] -> MIME.type(ext) || default_mime(content)
+                   _ -> default_mime(content)
                  end
           %{git | content: content, content_type: type, filename: name}
         {:error, error} -> %{git | status: error}