mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-22 09:32:41 +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) {
|
private async post<T>(url: string, data: any, headers: HttpHeaders) {
|
||||||
return CapacitorHttp.post({
|
return CapacitorHttp.post({
|
||||||
url,
|
url,
|
||||||
// Workaround for CapacitorHttp bug (JSONException when "x-www-form-urlencoded" text is provided)
|
data,
|
||||||
data:
|
|
||||||
headers['Content-Type'] === 'application/x-www-form-urlencoded'
|
|
||||||
? this.decodeURLSearchParams(data)
|
|
||||||
: data,
|
|
||||||
headers,
|
headers,
|
||||||
}).then((response: HttpResponse) => {
|
}).then((response: HttpResponse) => {
|
||||||
return response.data as T;
|
return response.data as T;
|
||||||
@@ -66,11 +62,7 @@ export class CapacitorRequestor extends Requestor {
|
|||||||
private async put<T>(url: string, data: any, headers: HttpHeaders) {
|
private async put<T>(url: string, data: any, headers: HttpHeaders) {
|
||||||
return CapacitorHttp.put({
|
return CapacitorHttp.put({
|
||||||
url,
|
url,
|
||||||
// Workaround for CapacitorHttp bug (JSONException when "x-www-form-urlencoded" text is provided)
|
data,
|
||||||
data:
|
|
||||||
headers['Content-Type'] === 'application/x-www-form-urlencoded'
|
|
||||||
? this.decodeURLSearchParams(data)
|
|
||||||
: data,
|
|
||||||
headers,
|
headers,
|
||||||
}).then((response: HttpResponse) => response.data as T);
|
}).then((response: HttpResponse) => response.data as T);
|
||||||
}
|
}
|
||||||
@@ -78,14 +70,4 @@ export class CapacitorRequestor extends Requestor {
|
|||||||
private async delete<T>(url: string, headers: HttpHeaders) {
|
private async delete<T>(url: string, headers: HttpHeaders) {
|
||||||
return CapacitorHttp.delete({url, headers}).then((response: HttpResponse) => response.data as T);
|
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