From 790564b74e5179112e7935d7c6cfc3ed7b6d1a2a Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 17 Dec 2024 18:01:40 -0600 Subject: [PATCH 1/2] Fix BACKEND_URL with baseClient --- src/api/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/index.ts b/src/api/index.ts index 3d531c105..1630a3db2 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -22,7 +22,7 @@ export const baseClient = ( accessToken?: string | null, baseURL?: string, ): MastodonClient => { - return new MastodonClient(baseURL || location.origin, accessToken || undefined); + return new MastodonClient(baseURL || BuildConfig.BACKEND_URL || location.origin, accessToken || undefined); }; /** From f0043813e6efd5564977594f6ed2b9ec9d11003c Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 17 Dec 2024 18:16:34 -0600 Subject: [PATCH 2/2] MastodonClient: merge searchParams --- src/api/MastodonClient.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/api/MastodonClient.ts b/src/api/MastodonClient.ts index 6ad2fce06..78ad6633b 100644 --- a/src/api/MastodonClient.ts +++ b/src/api/MastodonClient.ts @@ -57,18 +57,25 @@ export class MastodonClient { ? opts.searchParams : Object .entries(opts.searchParams) - .reduce<[string, string][]>((acc, [key, value]) => { + .reduce((acc, [key, value]) => { if (Array.isArray(value)) { for (const v of value) { - acc.push([`${key}[]`, String(v)]); + acc.append(`${key}[]`, String(v)); } } else if (value !== undefined && value !== null) { - acc.push([key, String(value)]); + acc.append(key, String(value)); } return acc; - }, []); + }, new URLSearchParams()); - url.search = new URLSearchParams(params).toString(); + // Merge search params. + // If a key exists in the URL, it will be replaced. Otherwise it will be added. + for (const key of params.keys()) { + url.searchParams.delete(key); + } + for (const [key, value] of params) { + url.searchParams.append(key, value); + } } const headers = new Headers(opts.headers);