Added the ability to upload background, logo, default user avatar, instance thumbnail...
[akkoma] / lib / pleroma / helpers / uri_helper.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Helpers.UriHelper do
6 def append_uri_params(uri, appended_params) do
7 uri = URI.parse(uri)
8 appended_params = for {k, v} <- appended_params, into: %{}, do: {to_string(k), v}
9 existing_params = URI.query_decoder(uri.query || "") |> Enum.into(%{})
10 updated_params_keys = Enum.uniq(Map.keys(existing_params) ++ Map.keys(appended_params))
11
12 updated_params =
13 for k <- updated_params_keys, do: {k, appended_params[k] || existing_params[k]}
14
15 uri
16 |> Map.put(:query, URI.encode_query(updated_params))
17 |> URI.to_string()
18 end
19
20 def append_param_if_present(%{} = params, param_name, param_value) do
21 if param_value do
22 Map.put(params, param_name, param_value)
23 else
24 params
25 end
26 end
27
28 def maybe_add_base("/" <> uri, base), do: Path.join([base, uri])
29 def maybe_add_base(uri, _base), do: uri
30 end