defmodule Mix.Tasks.Pleroma.Uploads do
use Mix.Task
- alias Pleroma.{Upload, Uploaders.Local}
alias Mix.Tasks.Pleroma.Common
+ alias Pleroma.Upload
+ alias Pleroma.Uploaders.Local
require Logger
@log_every 50
Options:
- `--delete` - delete local uploads after migrating them to the target uploader
-
- A list of avalible uploaders can be seen in config.exs
+ A list of available uploaders can be seen in config.exs
"""
def run(["migrate_local", target_uploader | args]) do
delete? = Enum.member?(args, "--delete")
Pleroma.Config.put([Upload, :uploader], uploader)
end
- Mix.shell().info("Migrating files from local #{local_path} to #{to_string(uploader)}")
+ Common.shell_info("Migrating files from local #{local_path} to #{to_string(uploader)}")
if delete? do
- Mix.shell().info(
+ Common.shell_info(
"Attention: uploaded files will be deleted, hope you have backups! (--delete ; cancel with ^C)"
)
|> Enum.filter(& &1)
total_count = length(uploads)
- Mix.shell().info("Found #{total_count} uploads")
+ Common.shell_info("Found #{total_count} uploads")
uploads
|> Task.async_stream(
:ok
error ->
- Mix.shell().error("failed to upload #{inspect(upload.path)}: #{inspect(error)}")
+ Common.shell_error("failed to upload #{inspect(upload.path)}: #{inspect(error)}")
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)
- Mix.shell().info("Uploaded #{count}/#{total_count} files")
+ Common.shell_info("Uploaded #{count}/#{total_count} files")
count
end)
- Mix.shell().info("Done!")
+ Common.shell_info("Done!")
end
end