Use Jason.encode/1 for likes and bookmarks

This commit is contained in:
Egor Kislitsyn 2020-09-26 21:24:35 +04:00
parent 6d5f02a1da
commit d7a5291b4f
No known key found for this signature in database
GPG Key ID: 1B49CB15B71E7805

View File

@ -194,7 +194,8 @@ defmodule Pleroma.Backup do
query query
|> Pleroma.Repo.chunk_stream(100) |> Pleroma.Repo.chunk_stream(100)
|> Enum.reduce(0, fn i, acc -> |> Enum.reduce(0, fn i, acc ->
with {:ok, str} <- fun.(i), with {:ok, data} <- fun.(i),
{:ok, str} <- Jason.encode(data),
:ok <- IO.write(file, str <> ",\n") do :ok <- IO.write(file, str <> ",\n") do
acc + 1 acc + 1
else else
@ -213,7 +214,7 @@ defmodule Pleroma.Backup do
|> where(user_id: ^user_id) |> where(user_id: ^user_id)
|> join(:inner, [b], activity in assoc(b, :activity)) |> join(:inner, [b], activity in assoc(b, :activity))
|> select([b, a], %{id: b.id, object: fragment("(?)->>'object'", a.data)}) |> select([b, a], %{id: b.id, object: fragment("(?)->>'object'", a.data)})
|> write(dir, "bookmarks", fn a -> {:ok, "\"#{a.object}\""} end) |> write(dir, "bookmarks", fn a -> {:ok, a.object} end)
end end
defp likes(dir, user) do defp likes(dir, user) do
@ -221,7 +222,7 @@ defmodule Pleroma.Backup do
|> Activity.Queries.by_actor() |> Activity.Queries.by_actor()
|> Activity.Queries.by_type("Like") |> Activity.Queries.by_type("Like")
|> select([like], %{id: like.id, object: fragment("(?)->>'object'", like.data)}) |> select([like], %{id: like.id, object: fragment("(?)->>'object'", like.data)})
|> write(dir, "likes", fn a -> {:ok, "\"#{a.object}\""} end) |> write(dir, "likes", fn a -> {:ok, a.object} end)
end end
defp statuses(dir, user) do defp statuses(dir, user) do
@ -239,7 +240,7 @@ defmodule Pleroma.Backup do
|> ActivityPub.fetch_activities_query(opts) |> ActivityPub.fetch_activities_query(opts)
|> write(dir, "outbox", fn a -> |> write(dir, "outbox", fn a ->
with {:ok, activity} <- Transmogrifier.prepare_outgoing(a.data) do with {:ok, activity} <- Transmogrifier.prepare_outgoing(a.data) do
activity |> Map.delete("@context") |> Jason.encode() {:ok, Map.delete(activity, "@context")}
end end
end) end)
end end