2018-08-28 03:20:54 +02:00
|
|
|
defmodule Pleroma.Uploaders.Local do
|
2018-08-28 14:57:41 +02:00
|
|
|
@behaviour Pleroma.Uploaders.Uploader
|
2018-08-28 03:20:54 +02:00
|
|
|
|
2018-11-23 17:40:45 +01:00
|
|
|
def get_file(_) do
|
|
|
|
{:ok, {:static_dir, upload_path()}}
|
|
|
|
end
|
|
|
|
|
2018-11-29 21:11:45 +01:00
|
|
|
def put_file(upload) do
|
|
|
|
{local_path, file} =
|
|
|
|
case Enum.reverse(String.split(upload.path, "/", trim: true)) do
|
|
|
|
[file] ->
|
|
|
|
{upload_path(), file}
|
|
|
|
|
|
|
|
[file | folders] ->
|
|
|
|
path = Path.join([upload_path()] ++ Enum.reverse(folders))
|
|
|
|
File.mkdir_p!(path)
|
|
|
|
{path, file}
|
|
|
|
end
|
|
|
|
|
|
|
|
result_file = Path.join(local_path, file)
|
|
|
|
|
|
|
|
unless File.exists?(result_file) do
|
|
|
|
File.cp!(upload.tempfile, result_file)
|
2018-08-28 03:20:54 +02:00
|
|
|
end
|
|
|
|
|
2018-11-29 21:11:45 +01:00
|
|
|
:ok
|
2018-08-28 03:20:54 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def upload_path do
|
2018-11-23 17:40:45 +01:00
|
|
|
Pleroma.Config.get!([__MODULE__, :uploads])
|
2018-08-28 03:20:54 +02:00
|
|
|
end
|
|
|
|
end
|