mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2025-12-12 17:26:22 +00:00
committed by
Rainer Killinger
parent
296054c8e0
commit
dce08d9c03
@@ -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),
|
||||
]),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user