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,
|
||||
description: "GET Gateway URL",
|
||||
suggestions: [
|
||||
"https://ipfs.mydomain.com/<%= cid %>",
|
||||
"https://<%= cid %>.ipfs.mydomain.com/"
|
||||
"https://ipfs.mydomain.com/{CID}",
|
||||
"https://{CID}.ipfs.mydomain.com/"
|
||||
]
|
||||
},
|
||||
%{
|
||||
|
|
|
@ -624,7 +624,7 @@ Example:
|
|||
```elixir
|
||||
config :pleroma, Pleroma.Uploaders.IPFS,
|
||||
post_gateway_url: "http://localhost:5001",
|
||||
get_gateway_url: "http://<%= cid %>.ipfs.mydomain.com"
|
||||
get_gateway_url: "http://{CID}.ipfs.mydomain.com"
|
||||
```
|
||||
|
||||
### Upload filters
|
||||
|
|
|
@ -235,8 +235,8 @@ defp url_from_spec(%__MODULE__{name: name}, base_url, {:file, path}) do
|
|||
""
|
||||
end
|
||||
|
||||
if String.contains?(base_url, "<%= cid %>") do
|
||||
EEx.eval_string(base_url, cid: path)
|
||||
if String.contains?(base_url, Pleroma.Uploaders.IPFS.placeholder()) do
|
||||
String.replace(base_url, Pleroma.Uploaders.IPFS.placeholder(), path)
|
||||
else
|
||||
[base_url, path]
|
||||
|> Path.join()
|
||||
|
|
|
@ -9,12 +9,15 @@ defmodule Pleroma.Uploaders.IPFS do
|
|||
alias Pleroma.Config
|
||||
alias Tesla.Multipart
|
||||
|
||||
@placeholder "{CID}"
|
||||
def placeholder, do: @placeholder
|
||||
|
||||
@impl true
|
||||
def get_file(file) do
|
||||
b_url = Pleroma.Upload.base_url()
|
||||
|
||||
if String.contains?(b_url, "<%= cid %>") do
|
||||
{:ok, {:url, EEx.eval_string(b_url, cid: URI.decode(file))}}
|
||||
if String.contains?(b_url, @placeholder) do
|
||||
{:ok, {:url, String.replace(b_url, @placeholder, URI.decode(file))}}
|
||||
else
|
||||
{:error, "IPFS Get URL doesn't contain 'cid' placeholder"}
|
||||
end
|
||||
|
|
|
@ -17,7 +17,7 @@ defmodule Pleroma.Uploaders.IPFSTest do
|
|||
|
||||
clear_config(
|
||||
[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")
|
||||
|
@ -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
|
||||
clear_config(
|
||||
[Pleroma.Uploaders.IPFS, :get_gateway_url],
|
||||
"https://ipfs.mydomain.com/ipfs/<%= cid %>"
|
||||
"https://ipfs.mydomain.com/ipfs/{CID}"
|
||||
)
|
||||
|
||||
assert IPFS.get_file("testcid") == {
|
||||
|
|
Loading…
Reference in New Issue