From 457c743afebaa2dd6cc4376484031f751e86d40d Mon Sep 17 00:00:00 2001 From: Thomas Amland Date: Fri, 18 Oct 2024 13:35:14 +0200 Subject: [PATCH] add support for formPost extension --- src/shared/api.ts | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/shared/api.ts b/src/shared/api.ts index de50c05..f9d5d40 100644 --- a/src/shared/api.ts +++ b/src/shared/api.ts @@ -107,18 +107,26 @@ export class API { constructor(private auth: AuthService) { this.fetch = (path: string, params: any) => { - const url = `${this.auth.server}/${path}?${toQueryString({ - ...params, - v: '1.15.0', - f: 'json', - c: this.clientName, - })}&${this.auth.urlParams}` - - return window - .fetch(url, { + params = { ...params, v: '1.15.0', f: 'json', c: this.clientName } + + const request = auth.serverInfo?.extensions.includes('formPost') + ? new Request(`${this.auth.server}/${path}`, { + method: 'POST', + headers: { + Accept: 'application/json', + 'Content-Type': 'application/x-www-form-urlencoded', + }, + body: `${toQueryString(params)}&${this.auth.urlParams}` + }) + : new Request(`${this.auth.server}/${path}?${toQueryString(params)}&${this.auth.urlParams}`, { method: 'GET', - headers: { Accept: 'application/json' } + headers: { + Accept: 'application/json', + } }) + + return window + .fetch(request) .then(response => { if (response.ok) { return response.json()