fix: reverse workaround after update of capacitor

Closes #179
This commit is contained in:
Jovan Krunić
2023-12-18 19:16:33 +01:00
committed by Rainer Killinger
parent 296054c8e0
commit dce08d9c03

View File

@@ -51,11 +51,7 @@ export class CapacitorRequestor extends Requestor {
private async post<T>(url: string, data: any, headers: HttpHeaders) {
return CapacitorHttp.post({
url,
// Workaround for CapacitorHttp bug (JSONException when "x-www-form-urlencoded" text is provided)
data:
headers['Content-Type'] === 'application/x-www-form-urlencoded'
? this.decodeURLSearchParams(data)
: data,
data,
headers,
}).then((response: HttpResponse) => {
return response.data as T;
@@ -66,11 +62,7 @@ export class CapacitorRequestor extends Requestor {
private async put<T>(url: string, data: any, headers: HttpHeaders) {
return CapacitorHttp.put({
url,
// Workaround for CapacitorHttp bug (JSONException when "x-www-form-urlencoded" text is provided)
data:
headers['Content-Type'] === 'application/x-www-form-urlencoded'
? this.decodeURLSearchParams(data)
: data,
data,
headers,
}).then((response: HttpResponse) => response.data as T);
}
@@ -78,14 +70,4 @@ export class CapacitorRequestor extends Requestor {
private async delete<T>(url: string, headers: HttpHeaders) {
return CapacitorHttp.delete({url, headers}).then((response: HttpResponse) => response.data as T);
}
private decodeURLSearchParams(parameters: string): Record<string, unknown> {
const searchParameters = new URLSearchParams(parameters);
return Object.fromEntries(
[...searchParameters.keys()].map(k => [
k,
searchParameters.getAll(k).length === 1 ? searchParameters.get(k) : searchParameters.getAll(k),
]),
);
}
}