X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;ds=sidebyside;f=lib%2Fpleroma%2Fuploaders%2Flocal.ex;h=0e1ba4b9078c60611641c4bdfa7e2e6552777e8e;hb=80ccdb56f623be21b3ec5b78fc55cee57bee1d2b;hp=fc533da23cd2fa0194d96c7185a3014869da7be1;hpb=e4dc3f71aea900e566c0d66ddffc5cd57e3920dd;p=akkoma
diff --git a/lib/pleroma/uploaders/local.ex b/lib/pleroma/uploaders/local.ex
index fc533da23..0e1ba4b90 100644
--- a/lib/pleroma/uploaders/local.ex
+++ b/lib/pleroma/uploaders/local.ex
@@ -1,17 +1,19 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors
+# Copyright © 2017-2021 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Uploaders.Local do
@behaviour Pleroma.Uploaders.Uploader
+ @impl true
def get_file(_) do
{:ok, {:static_dir, upload_path()}}
end
+ @impl true
def put_file(upload) do
{local_path, file} =
- case Enum.reverse(String.split(upload.path, "/", trim: true)) do
+ case Enum.reverse(Path.split(upload.path)) do
[file] ->
{upload_path(), file}
@@ -23,7 +25,7 @@ defmodule Pleroma.Uploaders.Local do
result_file = Path.join(local_path, file)
- unless File.exists?(result_file) do
+ if not File.exists?(result_file) do
File.cp!(upload.tempfile, result_file)
end
@@ -33,4 +35,15 @@ defmodule Pleroma.Uploaders.Local do
def upload_path do
Pleroma.Config.get!([__MODULE__, :uploads])
end
+
+ @impl true
+ def delete_file(path) do
+ upload_path()
+ |> Path.join(path)
+ |> File.rm()
+ |> case do
+ :ok -> :ok
+ {:error, posix_error} -> {:error, to_string(posix_error)}
+ end
+ end
end