forked from YokaiRick/akkoma
Add backup upload
This commit is contained in:
parent
c82f912959
commit
be42ab70dc
2 changed files with 35 additions and 2 deletions
|
@ -22,7 +22,25 @@ def run(user) do
|
||||||
:ok <- bookmarks(path, user),
|
:ok <- bookmarks(path, user),
|
||||||
{:ok, zip_path} <- :zip.create('#{path}.zip', @files, cwd: path),
|
{:ok, zip_path} <- :zip.create('#{path}.zip', @files, cwd: path),
|
||||||
{:ok, _} <- File.rm_rf(path) do
|
{:ok, _} <- File.rm_rf(path) do
|
||||||
{:ok, zip_path}
|
{:ok, :binary.list_to_bin(zip_path)}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def upload(zip_path) do
|
||||||
|
uploader = Pleroma.Config.get([Pleroma.Upload, :uploader])
|
||||||
|
file_name = zip_path |> String.split("/") |> List.last()
|
||||||
|
id = Ecto.UUID.generate()
|
||||||
|
|
||||||
|
upload = %Pleroma.Upload{
|
||||||
|
id: id,
|
||||||
|
name: file_name,
|
||||||
|
tempfile: zip_path,
|
||||||
|
content_type: "application/zip",
|
||||||
|
path: id <> "/" <> file_name
|
||||||
|
}
|
||||||
|
|
||||||
|
with :ok <- uploader.put_file(upload), :ok <- File.rm(zip_path) do
|
||||||
|
{:ok, upload}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ test "it exports user data" do
|
||||||
Bookmark.create(user.id, status3.id)
|
Bookmark.create(user.id, status3.id)
|
||||||
|
|
||||||
assert {:ok, path} = Pleroma.Export.run(user)
|
assert {:ok, path} = Pleroma.Export.run(user)
|
||||||
assert {:ok, zipfile} = :zip.zip_open(path, [:memory])
|
assert {:ok, zipfile} = :zip.zip_open(String.to_charlist(path), [:memory])
|
||||||
assert {:ok, {'actor.json', json}} = :zip.zip_get('actor.json', zipfile)
|
assert {:ok, {'actor.json', json}} = :zip.zip_get('actor.json', zipfile)
|
||||||
|
|
||||||
assert %{
|
assert %{
|
||||||
|
@ -108,4 +108,19 @@ test "it exports user data" do
|
||||||
:zip.zip_close(zipfile)
|
:zip.zip_close(zipfile)
|
||||||
File.rm!(path)
|
File.rm!(path)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "it uploads an exported backup archive" do
|
||||||
|
user = insert(:user, %{nickname: "cofe", name: "Cofe", ap_id: "http://cofe.io/users/cofe"})
|
||||||
|
|
||||||
|
{:ok, status1} = CommonAPI.post(user, %{status: "status1"})
|
||||||
|
{:ok, status2} = CommonAPI.post(user, %{status: "status2"})
|
||||||
|
{:ok, status3} = CommonAPI.post(user, %{status: "status3"})
|
||||||
|
CommonAPI.favorite(user, status1.id)
|
||||||
|
CommonAPI.favorite(user, status2.id)
|
||||||
|
Bookmark.create(user.id, status2.id)
|
||||||
|
Bookmark.create(user.id, status3.id)
|
||||||
|
|
||||||
|
assert {:ok, path} = Pleroma.Export.run(user)
|
||||||
|
assert {:ok, %Pleroma.Upload{}} = Pleroma.Export.upload(path)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue