From 6d540163e071d0cf658b8fd16cd1b6af3b494830 Mon Sep 17 00:00:00 2001 From: Jordan Bracco Date: Tue, 20 Dec 2022 19:29:21 +0100 Subject: feat(couch): convert slashes to %2F in paths, allowing to use database or docs with slashes in their ids --- lib/couch.ex | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'lib/couch.ex') diff --git a/lib/couch.ex b/lib/couch.ex index 71f86a3..e33c045 100644 --- a/lib/couch.ex +++ b/lib/couch.ex @@ -73,9 +73,17 @@ defmodule Couch do config = Application.get_env(:lsg, :couch) base_url = Keyword.get(config, :url, "http://localhost:5984") - url = URI.merge(base_url, Path.join(path)) |> to_string() - headers = headers ++ [{"accept", "application/json"}, {"user-agent", "beautte"}] + path = path + |> Enum.filter(& &1) + |> Enum.map(fn(url) -> String.replace("/", "%2F") end) + |> Path.join() + + url = base_url + |> URI.merge(path) + |> to_string() + + headers = headers ++ [{"accept", "application/json"}, {"user-agent", "#{Nola.brand(:name)} v#{Nola.version()}"}] params = Enum.map(params, fn({k, v}) -> {to_string(k), v} end) client_options = Keyword.get(config, :client_options, []) -- cgit v1.2.3