honkoma/lib/pleroma/uploaders/local.ex

37 lines
855 B
Elixir
Raw Normal View History

# Pleroma: A lightweight social networking server
2018-12-31 15:41:47 +00:00
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
2018-08-28 01:20:54 +00:00
defmodule Pleroma.Uploaders.Local do
@behaviour Pleroma.Uploaders.Uploader
2018-08-28 01:20:54 +00:00
2018-11-23 16:40:45 +00:00
def get_file(_) do
{:ok, {:static_dir, upload_path()}}
end
2018-11-29 20:11:45 +00:00
def put_file(upload) do
{local_path, file} =
2019-08-10 18:46:26 +00:00
case Enum.reverse(Path.split(upload.path)) do
2018-11-29 20:11:45 +00:00
[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)
2019-08-10 18:46:26 +00:00
if not File.exists?(result_file) do
2018-11-29 20:11:45 +00:00
File.cp!(upload.tempfile, result_file)
2018-08-28 01:20:54 +00:00
end
2018-11-29 20:11:45 +00:00
:ok
2018-08-28 01:20:54 +00:00
end
def upload_path do
2018-11-23 16:40:45 +00:00
Pleroma.Config.get!([__MODULE__, :uploads])
2018-08-28 01:20:54 +00:00
end
end