add channel and category queries

This commit is contained in:
Inhji 2023-07-24 22:31:00 +02:00
parent c7483d658c
commit dcdbebbdfc
3 changed files with 32 additions and 14 deletions

View file

@ -44,7 +44,7 @@ defmodule ChiyaWeb.Indie.MicropubHandler do
def handle_update(url, replace, add, delete, access_token) do
with :ok <- Micropub.verify_token(access_token),
{:ok, note} <- Micropub.find_note(url),
{:ok, note} <- Micropub.update_note(note, replace, add, delete) do
{:ok, _note} <- Micropub.update_note(note, replace, add, delete) do
:ok
else
error -> error
@ -98,19 +98,11 @@ defmodule ChiyaWeb.Indie.MicropubHandler do
def handle_config_query(access_token) do
case Micropub.verify_token(access_token) do
:ok ->
channels = Chiya.Channels.list_channels()
config = %{
"media-endpoint" => url(~p"/indie/micropub/media"),
"destination" => [],
"post-types" => @post_types,
"channels" =>
Enum.map(channels, fn c ->
%{
"uid" => c.slug,
"name" => c.name
}
end)
"channels" => get_channels()
}
{:ok, config}
@ -132,11 +124,37 @@ defmodule ChiyaWeb.Indie.MicropubHandler do
def handle_category_query(access_token) do
case Micropub.verify_token(access_token) do
:ok ->
tags = Enum.map(Chiya.Tags.list_tags(), fn t -> t.name end)
{:ok, %{"categories" => tags}}
{:ok, %{"categories" => get_categories()}}
_ ->
{:error, :insufficient_scope}
end
end
@impl true
def handle_channel_query(access_token) do
case Micropub.verify_token(access_token) do
:ok ->
{:ok, %{"channels" => get_channels()}}
_ ->
{:error, :insufficient_scope}
end
end
defp get_channels() do
channels = Chiya.Channels.list_channels()
Enum.map(channels, fn c ->
%{
"uid" => c.slug,
"name" => c.name
}
end)
end
defp get_categories() do
tags = Chiya.Tags.list_tags()
Enum.map(tags, fn t -> t.name end)
end
end

View file

@ -50,7 +50,7 @@ defmodule Chiya.MixProject do
{:phoenix_live_reload, "~> 1.2", only: :dev},
{:phoenix_live_view, "~> 0.19"},
{:plug_cowboy, "~> 2.5"},
{:plug_micropub, git: "https://git.inhji.de/inhji/plug_micropub.git", branch: "main"},
{:plug_micropub, git: "https://git.inhji.de/inhji/plug_micropub.git", branch: "chiya"},
{:postgrex, ">= 0.0.0"},
{:swoosh, "~> 1.11"},
{:tailwind, "~> 0.2.0", runtime: Mix.env() == :dev},

View file

@ -44,7 +44,7 @@
"plug": {:hex, :plug, "1.14.2", "cff7d4ec45b4ae176a227acd94a7ab536d9b37b942c8e8fa6dfc0fff98ff4d80", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "842fc50187e13cf4ac3b253d47d9474ed6c296a8732752835ce4a86acdf68d13"},
"plug_cowboy": {:hex, :plug_cowboy, "2.6.1", "9a3bbfceeb65eff5f39dab529e5cd79137ac36e913c02067dba3963a26efe9b2", [:mix], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:cowboy_telemetry, "~> 0.3", [hex: :cowboy_telemetry, repo: "hexpm", optional: false]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "de36e1a21f451a18b790f37765db198075c25875c64834bcc82d90b309eb6613"},
"plug_crypto": {:hex, :plug_crypto, "1.2.5", "918772575e48e81e455818229bf719d4ab4181fcbf7f85b68a35620f78d89ced", [:mix], [], "hexpm", "26549a1d6345e2172eb1c233866756ae44a9609bd33ee6f99147ab3fd87fd842"},
"plug_micropub": {:git, "https://git.inhji.de/inhji/plug_micropub.git", "c06eacc1252442626cfb3da7333668a1e68460c3", [branch: "main"]},
"plug_micropub": {:git, "https://git.inhji.de/inhji/plug_micropub.git", "1845a4067703fc656fec34b8732b9544967893c0", [branch: "chiya"]},
"poison": {:hex, :poison, "4.0.1", "bcb755a16fac91cad79bfe9fc3585bb07b9331e50cfe3420a24bcc2d735709ae", [:mix], [], "hexpm", "ba8836feea4b394bb718a161fc59a288fe0109b5006d6bdf97b6badfcf6f0f25"},
"postgrex": {:hex, :postgrex, "0.17.1", "01c29fd1205940ee55f7addb8f1dc25618ca63a8817e56fac4f6846fc2cddcbe", [:mix], [{:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "14b057b488e73be2beee508fb1955d8db90d6485c6466428fe9ccf1d6692a555"},
"ranch": {:hex, :ranch, "1.8.0", "8c7a100a139fd57f17327b6413e4167ac559fbc04ca7448e9be9057311597a1d", [:make, :rebar3], [], "hexpm", "49fbcfd3682fab1f5d109351b61257676da1a2fdbe295904176d5e521a2ddfe5"},