projects
/
akkoma
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Move admin approval email logic into User.post_register_action/1
[akkoma]
/
lib
/
pleroma
/
uploaders
/
local.ex
diff --git
a/lib/pleroma/uploaders/local.ex
b/lib/pleroma/uploaders/local.ex
index b089c8f14d8ba706f98b29a4158a2746716c4e26..10b3069f4c91610aad0deab6607cfc6e005ea3d5 100644
(file)
--- a/
lib/pleroma/uploaders/local.ex
+++ b/
lib/pleroma/uploaders/local.ex
@@
-1,47
+1,49
@@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Uploaders.Local do
@behaviour Pleroma.Uploaders.Uploader
defmodule Pleroma.Uploaders.Local do
@behaviour Pleroma.Uploaders.Uploader
- alias Pleroma.Web
+ @impl true
+ def get_file(_) do
+ {:ok, {:static_dir, upload_path()}}
+ end
- def put_file(name, uuid, file, _content_type, should_dedupe) do
- upload_folder = get_upload_path(uuid, should_dedupe)
- url_path = get_url(name, uuid, should_dedupe)
+ @impl true
+ def put_file(upload) do
+ {local_path, file} =
+ case Enum.reverse(Path.split(upload.path)) do
+ [file] ->
+ {upload_path(), file}
- File.mkdir_p!(upload_folder)
+ [file | folders] ->
+ path = Path.join([upload_path()] ++ Enum.reverse(folders))
+ File.mkdir_p!(path)
+ {path, file}
+ end
- result_file = Path.join(
upload_folder, nam
e)
+ result_file = Path.join(
local_path, fil
e)
- if File.exists?(result_file) do
- File.rm!(file.path)
- else
- File.cp!(file.path, result_file)
+ if not File.exists?(result_file) do
+ File.cp!(upload.tempfile, result_file)
end
end
- url_path
+ :ok
end
def upload_path do
end
def upload_path do
- settings = Application.get_env(:pleroma, Pleroma.Uploaders.Local)
- Keyword.fetch!(settings, :uploads)
+ Pleroma.Config.get!([__MODULE__, :uploads])
end
end
- defp get_upload_path(uuid, should_dedupe) do
- if should_dedupe do
- upload_path()
- else
- Path.join(upload_path(), uuid)
+ @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
end
-
- defp get_url(name, uuid, should_dedupe) do
- if should_dedupe do
- url_for(:cow_uri.urlencode(name))
- else
- url_for(Path.join(uuid, :cow_uri.urlencode(name)))
- end
- end
-
- defp url_for(file) do
- "#{Web.base_url()}/media/#{file}"
- end
end
end