mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 21:47:59 +01:00
workaround for inconsistent PutObjectCopy on R2
This commit is contained in:
parent
419ebdfe83
commit
464cc26a85
1 changed files with 22 additions and 10 deletions
|
@ -3,19 +3,25 @@ defmodule Philomena.Objects do
|
||||||
Replication wrapper for object storage backends.
|
Replication wrapper for object storage backends.
|
||||||
"""
|
"""
|
||||||
alias Philomena.Mime
|
alias Philomena.Mime
|
||||||
|
require Logger
|
||||||
|
|
||||||
#
|
#
|
||||||
# Fetch a key from the primary storage backend and
|
# Fetch a key from the storage backend and
|
||||||
# write it into the destination file.
|
# write it into the destination file.
|
||||||
#
|
#
|
||||||
# sobelow_skip ["Traversal.FileModule"]
|
# sobelow_skip ["Traversal.FileModule"]
|
||||||
@spec download_file(String.t(), String.t()) :: any()
|
@spec download_file(String.t(), String.t()) :: any()
|
||||||
def download_file(key, file_path) do
|
def download_file(key, file_path) do
|
||||||
[opts] = primary_opts()
|
|
||||||
|
|
||||||
contents =
|
contents =
|
||||||
|
backends()
|
||||||
|
|> Enum.find_value(fn opts ->
|
||||||
ExAws.S3.get_object(opts[:bucket], key)
|
ExAws.S3.get_object(opts[:bucket], key)
|
||||||
|> ExAws.request!(opts[:config_overrides])
|
|> ExAws.request(opts[:config_overrides])
|
||||||
|
|> case do
|
||||||
|
{:ok, result} -> result
|
||||||
|
_ -> nil
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
File.write!(file_path, contents.body)
|
File.write!(file_path, contents.body)
|
||||||
end
|
end
|
||||||
|
@ -58,10 +64,16 @@ defmodule Philomena.Objects do
|
||||||
#
|
#
|
||||||
@spec copy(String.t(), String.t()) :: any()
|
@spec copy(String.t(), String.t()) :: any()
|
||||||
def copy(source_key, dest_key) do
|
def copy(source_key, dest_key) do
|
||||||
run_all(fn opts ->
|
# Potential workaround for inconsistent PutObjectCopy on R2
|
||||||
ExAws.S3.put_object_copy(opts[:bucket], dest_key, opts[:bucket], source_key)
|
#
|
||||||
|> ExAws.request!(opts[:config_overrides])
|
# run_all(fn opts->
|
||||||
end)
|
# ExAws.S3.put_object_copy(opts[:bucket], dest_key, opts[:bucket], source_key)
|
||||||
|
# |> ExAws.request!(opts[:config_overrides])
|
||||||
|
# end)
|
||||||
|
|
||||||
|
file_path = Briefly.create!()
|
||||||
|
download_file(source_key, file_path)
|
||||||
|
upload(dest_key, file_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -101,7 +113,7 @@ defmodule Philomena.Objects do
|
||||||
|> Enum.any?(fn {_, v} -> v == :error end)
|
|> Enum.any?(fn {_, v} -> v == :error end)
|
||||||
|> case do
|
|> case do
|
||||||
true ->
|
true ->
|
||||||
raise "Failed to operate on all backends"
|
Logger.warn("Failed to operate on all backends")
|
||||||
|
|
||||||
_ ->
|
_ ->
|
||||||
:ok
|
:ok
|
||||||
|
|
Loading…
Reference in a new issue