diff --git a/tests/api.test.ts b/tests/api.test.ts index 285cdbb9..35965dab 100644 --- a/tests/api.test.ts +++ b/tests/api.test.ts @@ -486,16 +486,12 @@ describe("POST /api/v1/accounts/:id/note", () => { describe("GET /api/v1/accounts/relationships", () => { test("should return an array of APIRelationship objects for the authenticated user's relationships", async () => { const response = await fetch( - `${config.http.base_url}/api/v1/accounts/relationships`, + `${config.http.base_url}/api/v1/accounts/relationships?id[]=${user2.id}`, { - method: "POST", + method: "GET", headers: { Authorization: `Bearer ${token.access_token}`, - "Content-Type": "application/json", }, - body: JSON.stringify({ - "id[]": [user2.id], - }), } ); diff --git a/utils/request.ts b/utils/request.ts index f1cfd731..64efbc93 100644 --- a/utils/request.ts +++ b/utils/request.ts @@ -8,6 +8,15 @@ export async function parseRequest(request: Request): Promise> { const query = new URL(request.url).searchParams; + // Parse SearchParams arrays into JSON arrays + const arrayKeys = [...query.keys()].filter(key => key.endsWith("[]")); + + for (const key of arrayKeys) { + const value = query.getAll(key); + query.delete(key); + query.append(key, JSON.stringify(value)); + } + // if request contains a JSON body if (request.headers.get("Content-Type")?.includes("application/json")) { return (await request.json()) as T; @@ -42,10 +51,14 @@ export async function parseRequest(request: Request): Promise> { } if ([...query.entries()].length > 0) { - const data: Record = {}; + const data: Record = {}; for (const [key, value] of query.entries()) { - data[key] = value.toString(); + try { + data[key] = JSON.parse(value) as string[]; + } catch { + data[key] = value.toString(); + } } return data as T;