logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://anongit.hacktivis.me/git/pleroma.git/

uri_helper.ex (877B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Helpers.UriHelper do
  5. def modify_uri_params(uri, overridden_params, deleted_params \\ []) do
  6. uri = URI.parse(uri)
  7. existing_params = URI.query_decoder(uri.query || "") |> Map.new()
  8. overridden_params = Map.new(overridden_params, fn {k, v} -> {to_string(k), v} end)
  9. deleted_params = Enum.map(deleted_params, &to_string/1)
  10. updated_params =
  11. existing_params
  12. |> Map.merge(overridden_params)
  13. |> Map.drop(deleted_params)
  14. uri
  15. |> Map.put(:query, URI.encode_query(updated_params))
  16. |> URI.to_string()
  17. |> String.replace_suffix("?", "")
  18. end
  19. def maybe_add_base("/" <> uri, base), do: Path.join([base, uri])
  20. def maybe_add_base(uri, _base), do: uri
  21. end