Slon/Api/V1/Accounts: Handle badly-behaved JSON API clients

An array of String is still an array, even if it contains a single
element. I'm looking at you,
[Tuba](https://github.com/GeopJr/Tuba/blob/main/src/API/Relationship.vala#L48).

Ref: https://docs.joinmastodon.org/methods/accounts/#relationships

It shouldn't be our responsibility to handle this, but life isn't fair,
so we'll begrudgingly handle it anyway.
This commit is contained in:
Alec Murphy 2025-03-21 16:34:55 -04:00
parent 3369304fb4
commit 0d19f9fa33

View file

@ -158,7 +158,7 @@ U0 @slon_api_v1_accounts_get(SlonHttpSession* session)
if (!StrICmp("relationships", session->path(3))) { if (!StrICmp("relationships", session->path(3))) {
if (@slon_api_authorized(session)) { if (@slon_api_authorized(session)) {
JsonArray* relationships = Json.CreateArray(slon_mem_task); JsonArray* relationships = Json.CreateArray(slon_mem_task);
JsonArray* relationship_of_ids = request_json->@("id"); JsonArray* relationship_of_ids = Json.KeyValueAsArray(request_json->@("id", 1), slon_mem_task);
JsonObject* target_account = NULL; JsonObject* target_account = NULL;
if (relationship_of_ids) { if (relationship_of_ids) {
for (i = 0; i < relationship_of_ids->length; i++) { for (i = 0; i < relationship_of_ids->length; i++) {