Merge branch 'improve-local-upload' into 'master'
Improve local uploader See merge request framasoft/mobilizon!653
This commit is contained in:
commit
6678e8f9eb
@ -11,6 +11,7 @@ defmodule Mobilizon.Web.Upload.Uploader.Local do
|
|||||||
@behaviour Mobilizon.Web.Upload.Uploader
|
@behaviour Mobilizon.Web.Upload.Uploader
|
||||||
|
|
||||||
alias Mobilizon.Config
|
alias Mobilizon.Config
|
||||||
|
alias Mobilizon.Web.Upload
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def get_file(_) do
|
def get_file(_) do
|
||||||
@ -18,15 +19,21 @@ defmodule Mobilizon.Web.Upload.Uploader.Local do
|
|||||||
end
|
end
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def put_file(upload) do
|
def put_file(%Upload{path: path, tempfile: tempfile}) do
|
||||||
{path, file} = local_path(upload.path)
|
{path, file} = local_path(path)
|
||||||
result_file = Path.join(path, file)
|
result_file = Path.join(path, file)
|
||||||
|
|
||||||
unless File.exists?(result_file) do
|
with {:result_exists, false} <- {:result_exists, File.exists?(result_file)},
|
||||||
File.cp!(upload.tempfile, result_file)
|
{:temp_file_exists, true} <- {:temp_file_exists, File.exists?(tempfile)} do
|
||||||
end
|
File.cp!(tempfile, result_file)
|
||||||
|
else
|
||||||
|
{:result_exists, _} ->
|
||||||
|
# If the resulting file already exists, it's because of the Dedupe filter
|
||||||
|
:ok
|
||||||
|
|
||||||
:ok
|
{:temp_file_exists, _} ->
|
||||||
|
{:error, "Temporary file no longer exists"}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
|
Loading…
Reference in New Issue
Block a user