forked from AkkomaGang/akkoma
Zip exported files
This commit is contained in:
parent
257e059e61
commit
9d564ffc29
1 changed files with 12 additions and 10 deletions
|
@ -12,15 +12,17 @@ defmodule Pleroma.Export do
|
||||||
|
|
||||||
import Ecto.Query
|
import Ecto.Query
|
||||||
|
|
||||||
|
@files ['actor.json', 'outbox.json', 'likes.json', 'bookmarks.json']
|
||||||
|
|
||||||
def run(user) do
|
def run(user) do
|
||||||
with {:ok, dir} <- create_dir(),
|
with {:ok, path} <- create_dir(user),
|
||||||
:ok <- actor(dir, user),
|
:ok <- actor(path, user),
|
||||||
:ok <- statuses(dir, user),
|
:ok <- statuses(path, user),
|
||||||
:ok <- likes(dir, user),
|
:ok <- likes(path, user),
|
||||||
:ok <- bookmarks(dir, user) do
|
:ok <- bookmarks(path, user),
|
||||||
IO.inspect({"DONE", dir})
|
{:ok, zip_path} <- :zip.create('#{path}.zip', @files, cwd: path),
|
||||||
else
|
{:ok, _} <- File.rm_rf(path) do
|
||||||
err -> IO.inspect({"export error", err})
|
{:ok, zip_path}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -33,9 +35,9 @@ def actor(dir, user) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp create_dir do
|
defp create_dir(user) do
|
||||||
datetime = Calendar.NaiveDateTime.Format.iso8601_basic(NaiveDateTime.utc_now())
|
datetime = Calendar.NaiveDateTime.Format.iso8601_basic(NaiveDateTime.utc_now())
|
||||||
dir = Path.join(System.tmp_dir!(), "archive-" <> datetime)
|
dir = Path.join(System.tmp_dir!(), "archive-#{user.id}-#{datetime}")
|
||||||
|
|
||||||
with :ok <- File.mkdir(dir), do: {:ok, dir}
|
with :ok <- File.mkdir(dir), do: {:ok, dir}
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue