1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Helpers.UriHelper do
6 def append_uri_params(uri, appended_params) do
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))
13 for k <- updated_params_keys, do: {k, appended_params[k] || existing_params[k]}
16 |> Map.put(:query, URI.encode_query(updated_params))
20 def append_param_if_present(%{} = params, param_name, param_value) do
22 Map.put(params, param_name, param_value)