add category query

This commit is contained in:
Inhji 2023-07-24 20:36:17 +02:00
parent a63d32c00b
commit 1845a40677
2 changed files with 14 additions and 1 deletions

View File

@ -122,7 +122,7 @@ defmodule PlugMicropub do
defp get_query(conn) do
case Map.fetch(conn.query_params, "q") do
{:ok, query} when query in ["config", "source", "syndicate-to", "channel"] ->
{:ok, query} when query in ["config", "source", "syndicate-to", "channel", "category"] ->
{:ok, String.to_existing_atom(query)}
_ ->
@ -200,6 +200,15 @@ defmodule PlugMicropub do
end
end
defp handle_query(:category, access_token, conn) do
handler = conn.private[:plug_micropub][:handler]
case handler.handle_category_query(access_token) do
{:ok, content} -> send_content(conn, content)
error -> send_error(conn, error)
end
end
defp handle_query(:source, access_token, conn) do
with {:ok, url} <- Map.fetch(conn.query_params, "url"),
do: do_source_query(conn, access_token, url),

View File

@ -56,6 +56,10 @@ defmodule PlugMicropub.HandlerBehaviour do
{:ok, map}
| handler_error
@callback handle_category_query(access_token) ::
{:ok, map}
| handler_error
@callback handle_media(file :: Plug.Upload.t(), access_token) ::
{:ok, url :: String.t()} | handler_error
end