diff --git a/lib/lsg_web/controllers/gpt_controller.ex b/lib/lsg_web/controllers/gpt_controller.ex new file mode 100644 index 0000000..acf9b27 --- /dev/null +++ b/lib/lsg_web/controllers/gpt_controller.ex @@ -0,0 +1,33 @@ +defmodule LSGWeb.GptController do + use LSGWeb, :controller + require Logger + + plug LSGWeb.ContextPlug + + def result(conn, params = %{"id" => result_id}) do + case LSG.IRC.GptPlugin.get_result(result_id) do + {:ok, result} -> + network = Map.get(params, "network") + channel = if c = Map.get(params, "chan"), do: LSGWeb.reformat_chan(c) + render(conn, "result.html", network: network, channel: channel, result: result) + {:error, :not_found} -> + conn + |> put_status(404) + |> text("Page not found") + end + end + + def prompt(conn, params = %{"id" => prompt_id}) do + case LSG.IRC.GptPlugin.get_prompt(prompt_id) do + {:ok, prompt} -> + network = Map.get(params, "network") + channel = if c = Map.get(params, "chan"), do: LSGWeb.reformat_chan(c) + render(conn, "prompt.html", network: network, channel: channel, prompt: prompt) + {:error, :not_found} -> + conn + |> put_status(404) + |> text("Page not found") + end + end + +end diff --git a/lib/lsg_web/router.ex b/lib/lsg_web/router.ex index eba71dc..5cc0d4a 100644 --- a/lib/lsg_web/router.ex +++ b/lib/lsg_web/router.ex @@ -1,81 +1,85 @@ defmodule LSGWeb.Router do use LSGWeb, :router pipeline :browser do plug :accepts, ["html", "txt"] plug :fetch_session plug :fetch_flash plug :fetch_live_flash plug :protect_from_forgery plug :put_secure_browser_headers plug :put_root_layout, {LSGWeb.LayoutView, :root} end pipeline :api do plug :accepts, ["json", "sse"] end pipeline :matrix_app_service do plug :accepts, ["json"] plug LSG.Matrix.Plug.Auth plug LSG.Matrix.Plug.SetConfig end scope "/api", LSGWeb do pipe_through :api get "/irc-auth.sse", IrcAuthSseController, :sse post "/sms/callback/Ovh", SmsController, :ovh_callback, as: :sms end scope "/", LSGWeb do pipe_through :browser get "/", PageController, :index get "/login/irc/:token", PageController, :token, as: :login get "/login/oidc", OpenIdController, :login get "/login/oidc/callback", OpenIdController, :callback get "/api/untappd/callback", UntappdController, :callback, as: :untappd_callback get "/-", IrcController, :index get "/-/txt", IrcController, :txt get "/-/txt/:name", IrcController, :txt + get "/-/gpt/prompt/:id", GptController, :task + get "/-/gpt/result/:id", GptController, :result get "/-/alcoolog", AlcoologController, :index get "/-/alcoolog/~/:account_name", AlcoologController, :index get "/:network", NetworkController, :index get "/:network/~:nick/alcoolog", AlcoologController, :nick get "/:network/~:nick/alcoolog/log.json", AlcoologController, :nick_log_json get "/:network/~:nick/alcoolog/gls.json", AlcoologController, :nick_gls_json get "/:network/~:nick/alcoolog/volumes.json", AlcoologController, :nick_volumes_json get "/:network/~:nick/alcoolog/history.json", AlcoologController, :nick_history_json get "/:network/~:nick/alcoolog/stats.json", AlcoologController, :nick_stats_json get "/:network/:chan/alcoolog", AlcoologController, :index get "/:network/:chan/alcoolog/gls.json", AlcoologController, :index_gls_json + get "/:network/:chan/gpt/prompt/:id", GptController, :task + get "/:network/:chan/gpt/result/:id", GptController, :result put "/api/alcoolog/minisync/:user_id/meta/:key", AlcoologController, :minisync_put_meta get "/:network/:chan", IrcController, :index live "/:network/:chan/live", ChatLive get "/:network/:chan/txt", IrcController, :txt get "/:network/:chan/txt/:name", IrcController, :txt get "/:network/:channel/preums", IrcController, :preums get "/:network/:chan/alcoolog/t/:token", AlcoologController, :token end scope "/_matrix/:appservice", MatrixAppServiceWeb.V1, as: :matrix do pipe_through :matrix_app_service put "/transactions/:txn_id", TransactionController, :push get "/users/:user_id", UserController, :query get "/rooms/*room_alias", RoomController, :query get "/thirdparty/protocol/:protocol", ThirdPartyController, :query_protocol get "/thirdparty/user/:protocol", ThirdPartyController, :query_users get "/thirdparty/location/:protocol", ThirdPartyController, :query_locations get "/thirdparty/location", ThirdPartyController, :query_location_by_alias get "/thirdparty/user", ThirdPartyController, :query_user_by_id end end