logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

marker_controller.ex (1214B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Web.MastodonAPI.MarkerController do
  5. use Pleroma.Web, :controller
  6. alias Pleroma.Web.Plugs.OAuthScopesPlug
  7. plug(Pleroma.Web.ApiSpec.CastAndValidate)
  8. plug(
  9. OAuthScopesPlug,
  10. %{scopes: ["read:statuses"]}
  11. when action == :index
  12. )
  13. plug(OAuthScopesPlug, %{scopes: ["write:statuses"]} when action == :upsert)
  14. action_fallback(Pleroma.Web.MastodonAPI.FallbackController)
  15. defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.MarkerOperation
  16. # GET /api/v1/markers
  17. def index(%{assigns: %{user: user}} = conn, params) do
  18. markers = Pleroma.Marker.get_markers(user, params[:timeline])
  19. render(conn, "markers.json", %{markers: markers})
  20. end
  21. # POST /api/v1/markers
  22. def upsert(%{assigns: %{user: user}, body_params: params} = conn, _) do
  23. params = Map.new(params, fn {key, value} -> {to_string(key), value} end)
  24. with {:ok, result} <- Pleroma.Marker.upsert(user, params),
  25. markers <- Map.values(result) do
  26. render(conn, "markers.json", %{markers: markers})
  27. end
  28. end
  29. end