# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.MIME do
@default "application/octet-stream"
@read_bytes 35
- @spec file_mime_type(String.t()) ::
+ @spec file_mime_type(String.t(), String.t()) ::
{:ok, content_type :: String.t(), filename :: String.t()} | {:error, any()} | :error
def file_mime_type(path, filename) do
with {:ok, content_type} <- file_mime_type(path),
"audio/ogg"
end
- defp check_mime_type(<<0x52, 0x49, 0x46, 0x46, _::binary>>) do
+ defp check_mime_type(<<"RIFF", _::binary-size(4), "WAVE", _::binary>>) do
"audio/wav"
end
+ defp check_mime_type(<<"RIFF", _::binary-size(4), "WEBP", _::binary>>) do
+ "image/webp"
+ end
+
+ defp check_mime_type(<<"RIFF", _::binary-size(4), "AVI.", _::binary>>) do
+ "video/avi"
+ end
+
defp check_mime_type(_) do
@default
end