1 defmodule Pleroma.Web.AkkomaAPI.FrontendSettingsController do
2 use Pleroma.Web, :controller
4 alias Pleroma.Web.Plugs.OAuthScopesPlug
5 alias Pleroma.Akkoma.FrontendSettingsProfile
7 @unauthenticated_access %{fallback: :proceed_unauthenticated, scopes: []}
10 %{@unauthenticated_access | scopes: ["read:accounts"]}
19 %{@unauthenticated_access | scopes: ["write:accounts"]}
26 plug(Pleroma.Web.ApiSpec.CastAndValidate)
27 defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.FrontendSettingsOperation
29 action_fallback(Pleroma.Web.MastodonAPI.FallbackController)
31 @doc "GET /api/v1/akkoma/frontend_settings/:frontend_name/:profile_name"
32 def get_profile(conn, %{frontend_name: frontend_name, profile_name: profile_name}) do
33 with %FrontendSettingsProfile{} = profile <-
34 FrontendSettingsProfile.get_by_user_and_frontend_name_and_profile_name(
41 settings: profile.settings,
42 version: profile.version
45 nil -> {:error, :not_found}
49 @doc "GET /api/v1/akkoma/frontend_settings/:frontend_name"
50 def list_profiles(conn, %{frontend_name: frontend_name}) do
52 FrontendSettingsProfile.get_all_by_user_and_frontend_name(
57 Enum.map(profiles, fn profile ->
58 %{name: profile.profile_name, version: profile.version}
64 @doc "DELETE /api/v1/akkoma/frontend_settings/:frontend_name/:profile_name"
65 def delete_profile(conn, %{frontend_name: frontend_name, profile_name: profile_name}) do
66 with %FrontendSettingsProfile{} = profile <-
67 FrontendSettingsProfile.get_by_user_and_frontend_name_and_profile_name(
72 {:ok, _} <- FrontendSettingsProfile.delete_profile(profile) do
73 json(conn, %{deleted: "ok"})
75 nil -> {:error, :not_found}
79 @doc "PUT /api/v1/akkoma/frontend_settings/:frontend_name/:profile_name"
80 def update_profile(%{body_params: %{settings: settings, version: version}} = conn, %{
81 frontend_name: frontend_name,
82 profile_name: profile_name
84 with {:ok, profile} <-
85 FrontendSettingsProfile.create_or_update(
93 |> json(profile.settings)