X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=lib%2Fmix%2Ftasks%2Fpleroma%2Fuploads.ex;h=c47b7531ef6b59e87a3e69fb080536742b6f88df;hb=83cef257942c42ae602308f5ce1a9d3d004791fc;hp=45bfd254cff53db4143822ae2aab7e697d214318;hpb=074fa790ba6282772cd8b2d40926032228d17c81;p=akkoma diff --git a/lib/mix/tasks/pleroma/uploads.ex b/lib/mix/tasks/pleroma/uploads.ex index 45bfd254c..c47b7531e 100644 --- a/lib/mix/tasks/pleroma/uploads.ex +++ b/lib/mix/tasks/pleroma/uploads.ex @@ -1,19 +1,22 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2020 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Mix.Tasks.Pleroma.Uploads do use Mix.Task - alias Pleroma.{Upload, Uploaders.Local} - alias Mix.Tasks.Pleroma.Common + import Mix.Pleroma + alias Pleroma.Upload + alias Pleroma.Uploaders.Local require Logger @log_every 50 - @shortdoc "Migrate uploads from local to remote storage" - @doc """ - Manages uploads - ## Migrate uploads from local to remote storage - """ + @shortdoc "Migrates uploads from local to remote storage" + @moduledoc File.read!("docs/administration/CLI_tasks/uploads.md") + 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) @@ -27,10 +30,10 @@ defmodule Mix.Tasks.Pleroma.Uploads do 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 - Mix.shell().info( + shell_info( "Attention: uploaded files will be deleted, hope you have backups! (--delete ; cancel with ^C)" ) @@ -57,7 +60,7 @@ defmodule Mix.Tasks.Pleroma.Uploads do 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 -> @@ -67,7 +70,7 @@ defmodule Mix.Tasks.Pleroma.Uploads do |> Enum.filter(& &1) total_count = length(uploads) - Mix.shell().info("Found #{total_count} uploads") + shell_info("Found #{total_count} uploads") uploads |> Task.async_stream( @@ -79,18 +82,19 @@ defmodule Mix.Tasks.Pleroma.Uploads do :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) + # 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") + shell_info("Uploaded #{count}/#{total_count} files") count end) - Mix.shell().info("Done!") + shell_info("Done!") end end