2019-10-17 12:26:59 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2020-03-03 22:44:49 +00:00
|
|
|
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
2019-10-17 12:26:59 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.MastodonAPI.MarkerController do
|
|
|
|
use Pleroma.Web, :controller
|
2020-06-24 06:57:27 +00:00
|
|
|
alias Pleroma.Web.Plugs.OAuthScopesPlug
|
2019-10-17 12:26:59 +00:00
|
|
|
|
2020-05-05 12:45:34 +00:00
|
|
|
plug(Pleroma.Web.ApiSpec.CastAndValidate)
|
|
|
|
|
2019-10-17 12:26:59 +00:00
|
|
|
plug(
|
|
|
|
OAuthScopesPlug,
|
|
|
|
%{scopes: ["read:statuses"]}
|
|
|
|
when action == :index
|
|
|
|
)
|
|
|
|
|
|
|
|
plug(OAuthScopesPlug, %{scopes: ["write:statuses"]} when action == :upsert)
|
2020-04-21 13:29:19 +00:00
|
|
|
|
2019-10-17 12:26:59 +00:00
|
|
|
action_fallback(Pleroma.Web.MastodonAPI.FallbackController)
|
2020-04-14 18:50:29 +00:00
|
|
|
|
|
|
|
defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.MarkerOperation
|
2019-10-17 12:26:59 +00:00
|
|
|
|
|
|
|
# GET /api/v1/markers
|
|
|
|
def index(%{assigns: %{user: user}} = conn, params) do
|
2020-04-14 18:50:29 +00:00
|
|
|
markers = Pleroma.Marker.get_markers(user, params[:timeline])
|
2019-10-17 12:26:59 +00:00
|
|
|
render(conn, "markers.json", %{markers: markers})
|
|
|
|
end
|
|
|
|
|
|
|
|
# POST /api/v1/markers
|
2020-04-14 18:50:29 +00:00
|
|
|
def upsert(%{assigns: %{user: user}, body_params: params} = conn, _) do
|
2020-05-05 12:45:34 +00:00
|
|
|
params = Map.new(params, fn {key, value} -> {to_string(key), value} end)
|
2020-04-14 18:50:29 +00:00
|
|
|
|
2019-10-17 12:26:59 +00:00
|
|
|
with {:ok, result} <- Pleroma.Marker.upsert(user, params),
|
|
|
|
markers <- Map.values(result) do
|
|
|
|
render(conn, "markers.json", %{markers: markers})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|