Change scrobble external link param name to use snake case

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak 2024-09-01 11:26:01 +02:00
parent 62856ab18f
commit e35e84228d
7 changed files with 48 additions and 12 deletions

View file

@ -0,0 +1 @@
Change scrobble external link param name to use snake case

View file

@ -671,6 +671,7 @@ Audio scrobbling in Pleroma is **deprecated**.
"artist": "Some Artist",
"album": "Some Album",
"length": 180000,
"external_link": "https://www.last.fm/music/Some+Artist/_/Some+Title",
"created_at": "2019-09-28T12:40:45.000Z"
}
]

View file

@ -59,11 +59,15 @@ defp create_request do
album: %Schema{type: :string, description: "The album of the media playing"},
artist: %Schema{type: :string, description: "The artist of the media playing"},
length: %Schema{type: :integer, description: "The length of the media playing"},
externalLink: %Schema{type: :string, description: "A URL referencing the media playing"},
external_link: %Schema{type: :string, description: "A URL referencing the media playing"},
visibility: %Schema{
allOf: [VisibilityScope],
default: "public",
description: "Scrobble visibility"
},
externalLink: %Schema{
type: :string,
description: "Deprecated, use `external_link` instead"
}
},
example: %{
@ -71,7 +75,7 @@ defp create_request do
"artist" => "Some Artist",
"album" => "Some Album",
"length" => 180_000,
"externalLink" => "https://www.last.fm/music/Some+Artist/_/Some+Title"
"external_link" => "https://www.last.fm/music/Some+Artist/_/Some+Title"
}
}
end
@ -85,7 +89,7 @@ defp scrobble do
title: %Schema{type: :string, description: "The title of the media playing"},
album: %Schema{type: :string, description: "The album of the media playing"},
artist: %Schema{type: :string, description: "The artist of the media playing"},
externalLink: %Schema{type: :string, description: "A URL referencing the media playing"},
external_link: %Schema{type: :string, description: "A URL referencing the media playing"},
length: %Schema{
type: :integer,
description: "The length of the media playing",
@ -100,7 +104,7 @@ defp scrobble do
"artist" => "Some Artist",
"album" => "Some Album",
"length" => 180_000,
"externalLink" => "https://www.last.fm/music/Some+Artist/_/Some+Title",
"external_link" => "https://www.last.fm/music/Some+Artist/_/Some+Title",
"created_at" => "2019-09-28T12:40:45.000Z"
}
}

View file

@ -85,7 +85,8 @@ def listen(user, params) do
defp listen_object(draft) do
object =
draft.params
|> Map.take([:album, :artist, :title, :length, :externalLink])
|> Map.take([:album, :artist, :title, :length])
|> Map.put(:externalLink, Map.get(draft.params, :external_link))
|> Map.new(fn {key, value} -> {to_string(key), value} end)
|> Map.put("type", "Audio")
|> Map.put("to", draft.to)

View file

@ -24,6 +24,10 @@ defmodule Pleroma.Web.PleromaAPI.ScrobbleController do
defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.PleromaScrobbleOperation
def create(%{assigns: %{user: user}, body_params: params} = conn, _) do
params =
params
|> Map.put_new(:external_link, Map.get(params, :externalLink))
with {:ok, activity} <- CommonAPI.listen(user, params) do
render(conn, "show.json", activity: activity, for: user)
else

View file

@ -27,8 +27,10 @@ def render("show.json", %{activity: %Activity{data: %{"type" => "Listen"}} = act
title: object.data["title"] |> HTML.strip_tags(),
artist: object.data["artist"] |> HTML.strip_tags(),
album: object.data["album"] |> HTML.strip_tags(),
externalLink: object.data["externalLink"],
length: object.data["length"]
external_link: object.data["externalLink"],
length: object.data["length"],
# DEPRECATED
externalLink: object.data["externalLink"]
}
end

View file

@ -19,10 +19,33 @@ test "works correctly" do
"artist" => "lain",
"album" => "lain radio",
"length" => "180000",
"externalLink" => "https://www.last.fm/music/lain/lain+radio/lain+radio+episode+1"
"external_link" => "https://www.last.fm/music/lain/lain+radio/lain+radio+episode+1"
})
assert %{"title" => "lain radio episode 1"} = json_response_and_validate_schema(conn, 200)
assert %{
"title" => "lain radio episode 1",
"external_link" => "https://www.last.fm/music/lain/lain+radio/lain+radio+episode+1"
} = json_response_and_validate_schema(conn, 200)
end
test "external_link fallback" do
%{conn: conn} = oauth_access(["write"])
conn =
conn
|> put_req_header("content-type", "application/json")
|> post("/api/v1/pleroma/scrobble", %{
"title" => "lain radio episode 2",
"artist" => "lain",
"album" => "lain radio",
"length" => "180000",
"externalLink" => "https://www.last.fm/music/lain/lain+radio/lain+radio+episode+2"
})
assert %{
"title" => "lain radio episode 2",
"external_link" => "https://www.last.fm/music/lain/lain+radio/lain+radio+episode+2"
} = json_response_and_validate_schema(conn, 200)
end
end
@ -35,7 +58,7 @@ test "works correctly" do
title: "lain radio episode 1",
artist: "lain",
album: "lain radio",
externalLink: "https://www.last.fm/music/lain/lain+radio/lain+radio+episode+1"
external_link: "https://www.last.fm/music/lain/lain+radio/lain+radio+episode+1"
})
{:ok, _activity} =
@ -43,7 +66,7 @@ test "works correctly" do
title: "lain radio episode 2",
artist: "lain",
album: "lain radio",
externalLink: "https://www.last.fm/music/lain/lain+radio/lain+radio+episode+2"
external_link: "https://www.last.fm/music/lain/lain+radio/lain+radio+episode+2"
})
{:ok, _activity} =
@ -51,7 +74,7 @@ test "works correctly" do
title: "lain radio episode 3",
artist: "lain",
album: "lain radio",
externalLink: "https://www.last.fm/music/lain/lain+radio/lain+radio+episode+3"
external_link: "https://www.last.fm/music/lain/lain+radio/lain+radio+episode+3"
})
conn = get(conn, "/api/v1/pleroma/accounts/#{user.id}/scrobbles")