aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEgor Kislitsyn <egor@kislitsyn.com>2020-08-24 20:59:57 +0400
committerEgor Kislitsyn <egor@kislitsyn.com>2020-10-07 18:34:27 +0400
commit9d564ffc2988f145bc9cf26477eea93b1bf01cb0 (patch)
tree017275a737a68ddb7dcc288bb24944e0c814625e
parent257e059e61b89752bcde9544cb5ae645b167c96b (diff)
downloadpleroma-9d564ffc2988f145bc9cf26477eea93b1bf01cb0.tar.gz
Zip exported files
-rw-r--r--lib/pleroma/export.ex22
1 files changed, 12 insertions, 10 deletions
diff --git a/lib/pleroma/export.ex b/lib/pleroma/export.ex
index 82a4b7ace..f0f1ef093 100644
--- a/lib/pleroma/export.ex
+++ b/lib/pleroma/export.ex
@@ -12,15 +12,17 @@ defmodule Pleroma.Export do
import Ecto.Query
+ @files ['actor.json', 'outbox.json', 'likes.json', 'bookmarks.json']
+
def run(user) do
- with {:ok, dir} <- create_dir(),
- :ok <- actor(dir, user),
- :ok <- statuses(dir, user),
- :ok <- likes(dir, user),
- :ok <- bookmarks(dir, user) do
- IO.inspect({"DONE", dir})
- else
- err -> IO.inspect({"export error", err})
+ with {:ok, path} <- create_dir(user),
+ :ok <- actor(path, user),
+ :ok <- statuses(path, user),
+ :ok <- likes(path, user),
+ :ok <- bookmarks(path, user),
+ {:ok, zip_path} <- :zip.create('#{path}.zip', @files, cwd: path),
+ {:ok, _} <- File.rm_rf(path) do
+ {:ok, zip_path}
end
end
@@ -33,9 +35,9 @@ defmodule Pleroma.Export do
end
end
- defp create_dir do
+ defp create_dir(user) do
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}
end