Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

56 linhas
1.6KB

  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Web.Metadata.Utils do
  5. alias Pleroma.Activity
  6. alias Pleroma.Emoji
  7. alias Pleroma.Formatter
  8. alias Pleroma.HTML
  9. def scrub_html_and_truncate(%{data: %{"content" => content}} = object) do
  10. content
  11. # html content comes from DB already encoded, decode first and scrub after
  12. |> HtmlEntities.decode()
  13. |> String.replace(~r/<br\s?\/?>/, " ")
  14. |> Activity.HTML.get_cached_stripped_html_for_activity(object, "metadata")
  15. |> Emoji.Formatter.demojify()
  16. |> HtmlEntities.decode()
  17. |> Formatter.truncate()
  18. end
  19. def scrub_html_and_truncate(content, max_length \\ 200) when is_binary(content) do
  20. content
  21. |> scrub_html
  22. |> Emoji.Formatter.demojify()
  23. |> HtmlEntities.decode()
  24. |> Formatter.truncate(max_length)
  25. end
  26. def scrub_html(content) when is_binary(content) do
  27. content
  28. # html content comes from DB already encoded, decode first and scrub after
  29. |> HtmlEntities.decode()
  30. |> String.replace(~r/<br\s?\/?>/, " ")
  31. |> HTML.strip_tags()
  32. end
  33. def scrub_html(content), do: content
  34. def user_name_string(user) do
  35. "#{user.name} " <>
  36. if user.local do
  37. "(@#{user.nickname}@#{Pleroma.Web.Endpoint.host()})"
  38. else
  39. "(@#{user.nickname})"
  40. end
  41. end
  42. @spec fetch_media_type(list(String.t()), String.t()) :: String.t() | nil
  43. def fetch_media_type(supported_types, media_type) do
  44. Enum.find(supported_types, fn support_type ->
  45. String.starts_with?(media_type, support_type)
  46. end)
  47. end
  48. end