added tests for ipfs uploader. adapted changelog.md accordingly. improved ipfs uploader with external suggestions
fix lint description.exs
This commit is contained in:
parent
fa2a6d5d6b
commit
43dfa58ebd
7 changed files with 116 additions and 15 deletions
|
|
@ -235,10 +235,8 @@ defmodule Pleroma.Upload do
|
|||
""
|
||||
end
|
||||
|
||||
uploader = Config.get([Pleroma.Upload, :uploader])
|
||||
|
||||
if uploader == Pleroma.Uploaders.IPFS && String.contains?(base_url, "{CID}") do
|
||||
String.replace(base_url, "{CID}", path)
|
||||
if String.contains?(base_url, "<%= cid %>") do
|
||||
EEx.eval_string(base_url, cid: path)
|
||||
else
|
||||
[base_url, path]
|
||||
|> Path.join()
|
||||
|
|
|
|||
|
|
@ -13,10 +13,10 @@ defmodule Pleroma.Uploaders.IPFS do
|
|||
def get_file(file) do
|
||||
b_url = Pleroma.Upload.base_url()
|
||||
|
||||
if String.contains?(b_url, "{CID}") do
|
||||
{:ok, {:url, String.replace(b_url, "{CID}", URI.decode(file))}}
|
||||
if String.contains?(b_url, "<%= cid %>") do
|
||||
{:ok, {:url, EEx.eval_string(b_url, cid: URI.decode(file))}}
|
||||
else
|
||||
{:error, "IPFS Get URL doesn't contain '{CID}' placeholder"}
|
||||
{:error, "IPFS Get URL doesn't contain 'cid' placeholder"}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -36,7 +36,11 @@ defmodule Pleroma.Uploaders.IPFS do
|
|||
{:ok, ret} ->
|
||||
case Jason.decode(ret.body) do
|
||||
{:ok, ret} ->
|
||||
{:ok, {:file, ret["Hash"]}}
|
||||
if Map.has_key?(ret, "Hash") do
|
||||
{:ok, {:file, ret["Hash"]}}
|
||||
else
|
||||
{:error, "JSON doesn't contain Hash value"}
|
||||
end
|
||||
|
||||
error ->
|
||||
Logger.error("#{__MODULE__}: #{inspect(error)}")
|
||||
|
|
@ -45,7 +49,7 @@ defmodule Pleroma.Uploaders.IPFS do
|
|||
|
||||
error ->
|
||||
Logger.error("#{__MODULE__}: #{inspect(error)}")
|
||||
{:error, "IPFS Gateway Upload failed"}
|
||||
{:error, "IPFS Gateway upload failed"}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue