ipfs: revert to String.replace for cid placeholder

ipfs: fix lint
This commit is contained in:
Claudio Maradonna 2022-04-16 09:38:49 +02:00
parent 43dfa58ebd
commit 44659ecd65
No known key found for this signature in database
GPG Key ID: 0CBA58694C5680D9
5 changed files with 12 additions and 9 deletions

View File

@ -147,8 +147,8 @@ config :pleroma, :config_description, [
type: :string, type: :string,
description: "GET Gateway URL", description: "GET Gateway URL",
suggestions: [ suggestions: [
"https://ipfs.mydomain.com/<%= cid %>", "https://ipfs.mydomain.com/{CID}",
"https://<%= cid %>.ipfs.mydomain.com/" "https://{CID}.ipfs.mydomain.com/"
] ]
}, },
%{ %{

View File

@ -624,7 +624,7 @@ Example:
```elixir ```elixir
config :pleroma, Pleroma.Uploaders.IPFS, config :pleroma, Pleroma.Uploaders.IPFS,
post_gateway_url: "http://localhost:5001", post_gateway_url: "http://localhost:5001",
get_gateway_url: "http://<%= cid %>.ipfs.mydomain.com" get_gateway_url: "http://{CID}.ipfs.mydomain.com"
``` ```
### Upload filters ### Upload filters

View File

@ -235,8 +235,8 @@ defmodule Pleroma.Upload do
"" ""
end end
if String.contains?(base_url, "<%= cid %>") do if String.contains?(base_url, Pleroma.Uploaders.IPFS.placeholder()) do
EEx.eval_string(base_url, cid: path) String.replace(base_url, Pleroma.Uploaders.IPFS.placeholder(), path)
else else
[base_url, path] [base_url, path]
|> Path.join() |> Path.join()

View File

@ -9,12 +9,15 @@ defmodule Pleroma.Uploaders.IPFS do
alias Pleroma.Config alias Pleroma.Config
alias Tesla.Multipart alias Tesla.Multipart
@placeholder "{CID}"
def placeholder, do: @placeholder
@impl true @impl true
def get_file(file) do def get_file(file) do
b_url = Pleroma.Upload.base_url() b_url = Pleroma.Upload.base_url()
if String.contains?(b_url, "<%= cid %>") do if String.contains?(b_url, @placeholder) do
{:ok, {:url, EEx.eval_string(b_url, cid: URI.decode(file))}} {:ok, {:url, String.replace(b_url, @placeholder, URI.decode(file))}}
else else
{:error, "IPFS Get URL doesn't contain 'cid' placeholder"} {:error, "IPFS Get URL doesn't contain 'cid' placeholder"}
end end

View File

@ -17,7 +17,7 @@ defmodule Pleroma.Uploaders.IPFSTest do
clear_config( clear_config(
[Pleroma.Uploaders.IPFS, :get_gateway_url], [Pleroma.Uploaders.IPFS, :get_gateway_url],
"https://<%= cid %>.ipfs.mydomain.com" "https://{CID}.ipfs.mydomain.com"
) )
clear_config([Pleroma.Uploaders.IPFS, :post_gateway_url], "http://localhost:5001") clear_config([Pleroma.Uploaders.IPFS, :post_gateway_url], "http://localhost:5001")
@ -34,7 +34,7 @@ defmodule Pleroma.Uploaders.IPFSTest do
test "it returns path to ipfs file with cid as path" do test "it returns path to ipfs file with cid as path" do
clear_config( clear_config(
[Pleroma.Uploaders.IPFS, :get_gateway_url], [Pleroma.Uploaders.IPFS, :get_gateway_url],
"https://ipfs.mydomain.com/ipfs/<%= cid %>" "https://ipfs.mydomain.com/ipfs/{CID}"
) )
assert IPFS.get_file("testcid") == { assert IPFS.get_file("testcid") == {