mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-12-17 22:47:59 +01:00
add parameter recoder
This commit is contained in:
parent
5f9fe0cb98
commit
caaeb3ad2e
3 changed files with 20 additions and 0 deletions
|
@ -3,6 +3,7 @@ defmodule PhilomenaWeb.Api.Json.TagController do
|
||||||
|
|
||||||
alias Philomena.Tags.Tag
|
alias Philomena.Tags.Tag
|
||||||
|
|
||||||
|
plug PhilomenaWeb.RecodeParameterPlug, [name: "id"] when action in [:show]
|
||||||
plug :load_resource, model: Tag, id_field: "slug", persisted: true, preload: [:aliased_tag, :aliases, :implied_tags, :implied_by_tags, :dnp_entries]
|
plug :load_resource, model: Tag, id_field: "slug", persisted: true, preload: [:aliased_tag, :aliases, :implied_tags, :implied_by_tags, :dnp_entries]
|
||||||
|
|
||||||
def show(conn, _params) do
|
def show(conn, _params) do
|
||||||
|
|
|
@ -8,6 +8,8 @@ defmodule PhilomenaWeb.TagController do
|
||||||
alias Philomena.Repo
|
alias Philomena.Repo
|
||||||
import Ecto.Query
|
import Ecto.Query
|
||||||
|
|
||||||
|
plug PhilomenaWeb.RecodeParameterPlug, [name: "id"] when action in [:show]
|
||||||
|
|
||||||
def index(conn, params) do
|
def index(conn, params) do
|
||||||
query_string = params["tq"] || "*"
|
query_string = params["tq"] || "*"
|
||||||
|
|
||||||
|
|
17
lib/philomena_web/plugs/recode_parameter_plug.ex
Normal file
17
lib/philomena_web/plugs/recode_parameter_plug.ex
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
defmodule PhilomenaWeb.RecodeParameterPlug do
|
||||||
|
def init(opts), do: opts
|
||||||
|
|
||||||
|
def call(conn, [name: name]) do
|
||||||
|
fixed_value =
|
||||||
|
conn
|
||||||
|
|> Map.get(:params)
|
||||||
|
|> Map.get(name)
|
||||||
|
|> to_string()
|
||||||
|
|> URI.encode_www_form()
|
||||||
|
|> String.replace("%2B", "+")
|
||||||
|
|
||||||
|
params = Map.put(conn.params, name, fixed_value)
|
||||||
|
|
||||||
|
%{conn | params: params}
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue