logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

local.ex (1090B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Uploaders.Local do
  5. @behaviour Pleroma.Uploaders.Uploader
  6. @impl true
  7. def get_file(_) do
  8. {:ok, {:static_dir, upload_path()}}
  9. end
  10. @impl true
  11. def put_file(upload) do
  12. {local_path, file} =
  13. case Enum.reverse(Path.split(upload.path)) do
  14. [file] ->
  15. {upload_path(), file}
  16. [file | folders] ->
  17. path = Path.join([upload_path()] ++ Enum.reverse(folders))
  18. File.mkdir_p!(path)
  19. {path, file}
  20. end
  21. result_file = Path.join(local_path, file)
  22. if not File.exists?(result_file) do
  23. File.cp!(upload.tempfile, result_file)
  24. end
  25. :ok
  26. end
  27. def upload_path do
  28. Pleroma.Config.get!([__MODULE__, :uploads])
  29. end
  30. @impl true
  31. def delete_file(path) do
  32. upload_path()
  33. |> Path.join(path)
  34. |> File.rm()
  35. |> case do
  36. :ok -> :ok
  37. {:error, posix_error} -> {:error, to_string(posix_error)}
  38. end
  39. end
  40. end