ipfs: revert to String.replace for cid placeholder
ipfs: fix lint
This commit is contained in:
parent
43dfa58ebd
commit
44659ecd65
|
@ -147,8 +147,8 @@
|
||||||
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/"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
%{
|
%{
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -235,8 +235,8 @@ defp url_from_spec(%__MODULE__{name: name}, base_url, {:file, path}) 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()
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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 @@ test "it returns path to ipfs file with cid as subdomain" 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") == {
|
||||||
|
|
Loading…
Reference in New Issue