Various typespec and compilation improvements

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2021-09-10 11:27:59 +02:00
parent 029a4ea194
commit de047c8939
125 changed files with 790 additions and 357 deletions

View File

@@ -19,12 +19,13 @@ defmodule Mobilizon.Web.Plugs.HTTPSecurityPlug do
if Config.get([:http_security, :enabled]) do
conn
|> merge_resp_headers(headers(options))
|> maybe_send_sts_header(Config.get([:http_security, :sts]))
|> maybe_send_sts_header(Config.get([:http_security, :sts], false))
else
conn
end
end
@spec headers(Keyword.t()) :: list({String.t(), String.t()})
defp headers(options) do
referrer_policy =
Keyword.get(options, :referrer_policy, Config.get([:http_security, :referrer_policy]))
@@ -55,6 +56,7 @@ defmodule Mobilizon.Web.Plugs.HTTPSecurityPlug do
@style_src "style-src 'self' "
@font_src "font-src 'self' "
@spec csp_string(Keyword.t()) :: String.t()
defp csp_string(options) do
scheme = Keyword.get(options, :scheme, Config.get([Pleroma.Web.Endpoint, :url])[:scheme])
static_url = Mobilizon.Web.Endpoint.static_url()
@@ -115,10 +117,11 @@ defmodule Mobilizon.Web.Plugs.HTTPSecurityPlug do
|> to_string()
end
@spec add_csp_param(list(), list(String.t()) | String.t() | nil) :: list()
defp add_csp_param(csp_iodata, nil), do: csp_iodata
defp add_csp_param(csp_iodata, param), do: [[param, ?;] | csp_iodata]
@spec maybe_send_sts_header(Plug.Conn.t(), boolean()) :: Plug.Conn.t()
defp maybe_send_sts_header(conn, true) do
max_age_sts = Config.get([:http_security, :sts_max_age])
@@ -127,8 +130,9 @@ defmodule Mobilizon.Web.Plugs.HTTPSecurityPlug do
])
end
defp maybe_send_sts_header(conn, _), do: conn
defp maybe_send_sts_header(conn, false), do: conn
@spec get_csp_config(atom(), Keyword.t()) :: String.t()
defp get_csp_config(type, options) do
options
|> Keyword.get(type, Config.get([:http_security, :csp_policy, type]))

View File

@@ -16,6 +16,7 @@ defmodule Mobilizon.Web.Plugs.HTTPSignatures do
options
end
@spec call(Plug.Conn.t(), any) :: Plug.Conn.t()
def call(%{assigns: %{valid_signature: true}} = conn, _opts) do
conn
end

View File

@@ -45,11 +45,13 @@ defmodule Mobilizon.Web.Plugs.UploadedMedia do
config = Config.get([Upload])
with uploader <- Keyword.fetch!(config, :uploader),
proxy_remote = Keyword.get(config, :proxy_remote, false),
{:ok, get_method} <- uploader.get_file(file) do
get_media(conn, get_method, proxy_remote, opts)
else
uploader = Keyword.fetch!(config, :uploader)
proxy_remote = Keyword.get(config, :proxy_remote, false)
case uploader.get_file(file) do
{:ok, get_method} ->
get_media(conn, get_method, proxy_remote, opts)
_ ->
conn
|> send_resp(500, "Failed")
@@ -59,6 +61,12 @@ defmodule Mobilizon.Web.Plugs.UploadedMedia do
def call(conn, _opts), do: conn
@spec get_media(
Plug.Conn.t(),
{:static_dir, String.t()} | {:url, String.t()} | any(),
boolean,
any()
) :: Plug.Conn.t()
defp get_media(conn, {:static_dir, directory}, _, opts) do
static_opts =
opts