Use content instead of source and scrub it

This commit is contained in:
Ekaterina Vaartis 2021-08-17 00:57:53 +03:00
parent 9beaebd97e
commit 00c48a33ac
2 changed files with 5 additions and 9 deletions

View File

@ -37,7 +37,7 @@ def run(["index"]) do
# Only index public posts which are notes and have some text # Only index public posts which are notes and have some text
where: where:
fragment("data->>'type' = 'Note'") and fragment("data->>'type' = 'Note'") and
fragment("LENGTH(data->>'source') > 0") and fragment("LENGTH(data->>'content') > 0") and
fragment("data->'to' \\? ?", ^Pleroma.Constants.as_public()), fragment("data->'to' \\? ?", ^Pleroma.Constants.as_public()),
order_by: [desc: fragment("data->'published'")] order_by: [desc: fragment("data->'published'")]
), ),
@ -56,10 +56,11 @@ def run(["index"]) do
data = object.data data = object.data
{:ok, published, _} = DateTime.from_iso8601(data["published"]) {:ok, published, _} = DateTime.from_iso8601(data["published"])
{:ok, content} = FastSanitize.strip_tags(data["content"])
%{ %{
id: object.id, id: object.id,
source: data["source"], content: content,
ap: data["id"], ap: data["id"],
published: published |> DateTime.to_unix() published: published |> DateTime.to_unix()
} }
@ -87,11 +88,6 @@ def run(["clear"]) do
endpoint = Pleroma.Config.get([Pleroma.Search.Meilisearch, :url]) endpoint = Pleroma.Config.get([Pleroma.Search.Meilisearch, :url])
{:ok, result} = {:ok, _} = Pleroma.HTTP.request(:delete, "#{endpoint}/indexes/objects", "", [], [])
Pleroma.HTTP.request(:delete, "#{endpoint}/indexes/objects/documents", "", [], [])
if not Map.has_key?(Jason.decode!(result.body), "updateId") do
IO.puts("Failed to clear: #{result}")
end
end end
end end

View File

@ -56,7 +56,7 @@ def add_to_index(activity) do
Jason.encode!([ Jason.encode!([
%{ %{
id: object.id, id: object.id,
source: data["source"], content: data["content"] |> Pleroma.HTML.filter_tags(),
ap: data["id"], ap: data["id"],
published: published |> DateTime.to_unix() published: published |> DateTime.to_unix()
} }