projects
/
akkoma
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'fix/license-attribution' into 'develop'
[akkoma]
/
lib
/
mix
/
tasks
/
pleroma
/
uploads.ex
diff --git
a/lib/mix/tasks/pleroma/uploads.ex
b/lib/mix/tasks/pleroma/uploads.ex
index 0742ab378bfc7689bdeeee73f64a865dcc2d1d3e..be45383eea59e96ad7f6000a697e02e779b8dd22 100644
(file)
--- a/
lib/mix/tasks/pleroma/uploads.ex
+++ b/
lib/mix/tasks/pleroma/uploads.ex
@@
-1,21
+1,30
@@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Mix.Tasks.Pleroma.Uploads do
use Mix.Task
defmodule Mix.Tasks.Pleroma.Uploads do
use Mix.Task
- import Mix.
Ecto
- alias Pleroma.
{Upload, Uploaders.Local, Uploaders.S3}
- alias
Mix.Tasks.Pleroma.Common
+ import Mix.
Pleroma
+ alias Pleroma.
Upload
+ alias
Pleroma.Uploaders.Local
require Logger
@log_every 50
require Logger
@log_every 50
- @shortdoc "Migrate uploads from local to remote storage"
- @longdoc """
+
+ @shortdoc "Migrates uploads from local to remote storage"
+ @moduledoc """
Manages uploads
Manages uploads
+
## Migrate uploads from local to remote storage
## Migrate uploads from local to remote storage
+ mix pleroma.uploads migrate_local TARGET_UPLOADER [OPTIONS...]
+ Options:
+ - `--delete` - delete local uploads after migrating them to the target uploader
+ A list of available uploaders can be seen in config.exs
"""
"""
-
def run(["migrate_local", target_uploader | args]) do
delete? = Enum.member?(args, "--delete")
def run(["migrate_local", target_uploader | args]) do
delete? = Enum.member?(args, "--delete")
-
Common.
start_pleroma()
+ start_pleroma()
local_path = Pleroma.Config.get!([Local, :uploads])
uploader = Module.concat(Pleroma.Uploaders, target_uploader)
local_path = Pleroma.Config.get!([Local, :uploads])
uploader = Module.concat(Pleroma.Uploaders, target_uploader)
@@
-29,10
+38,10
@@
defmodule Mix.Tasks.Pleroma.Uploads do
Pleroma.Config.put([Upload, :uploader], uploader)
end
Pleroma.Config.put([Upload, :uploader], uploader)
end
-
Mix.shell().
info("Migrating files from local #{local_path} to #{to_string(uploader)}")
+
shell_
info("Migrating files from local #{local_path} to #{to_string(uploader)}")
if delete? do
if delete? do
-
Mix.shell().
info(
+
shell_
info(
"Attention: uploaded files will be deleted, hope you have backups! (--delete ; cancel with ^C)"
)
"Attention: uploaded files will be deleted, hope you have backups! (--delete ; cancel with ^C)"
)
@@
-59,7
+68,7
@@
defmodule Mix.Tasks.Pleroma.Uploads do
File.exists?(root_path) ->
file = Path.basename(id)
File.exists?(root_path) ->
file = Path.basename(id)
-
[hash, ext] = String.split(id, "."
)
+
hash = Path.rootname(id
)
{%Pleroma.Upload{id: hash, name: file, path: file, tempfile: root_path}, root_path}
true ->
{%Pleroma.Upload{id: hash, name: file, path: file, tempfile: root_path}, root_path}
true ->
@@
-69,7
+78,7
@@
defmodule Mix.Tasks.Pleroma.Uploads do
|> Enum.filter(& &1)
total_count = length(uploads)
|> Enum.filter(& &1)
total_count = length(uploads)
-
Mix.shell().
info("Found #{total_count} uploads")
+
shell_
info("Found #{total_count} uploads")
uploads
|> Task.async_stream(
uploads
|> Task.async_stream(
@@
-81,18
+90,19
@@
defmodule Mix.Tasks.Pleroma.Uploads do
:ok
error ->
:ok
error ->
-
Mix.shell().
error("failed to upload #{inspect(upload.path)}: #{inspect(error)}")
+
shell_
error("failed to upload #{inspect(upload.path)}: #{inspect(error)}")
end
end,
timeout: 150_000
)
|> Stream.chunk_every(@log_every)
end
end,
timeout: 150_000
)
|> Stream.chunk_every(@log_every)
+ # credo:disable-for-next-line Credo.Check.Warning.UnusedEnumOperation
|> Enum.reduce(0, fn done, count ->
count = count + length(done)
|> Enum.reduce(0, fn done, count ->
count = count + length(done)
-
Mix.shell().
info("Uploaded #{count}/#{total_count} files")
+
shell_
info("Uploaded #{count}/#{total_count} files")
count
end)
count
end)
-
Mix.shell().
info("Done!")
+
shell_
info("Done!")
end
end
end
end