From: Alexander Ebert Date: Thu, 3 Nov 2022 16:57:13 +0000 (+0100) Subject: Add support for `FormData` and JSON body X-Git-Tag: 6.0.0_Alpha_1~629^2~5 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=5fdbddf5de03d9fc8ee305ef88440b028bcee3da;p=GitHub%2FWoltLab%2FWCF.git Add support for `FormData` and JSON body --- diff --git a/ts/WoltLabSuite/Core/Ajax/Backend.ts b/ts/WoltLabSuite/Core/Ajax/Backend.ts index 1fd167d9cb..70de0ba8c2 100644 --- a/ts/WoltLabSuite/Core/Ajax/Backend.ts +++ b/ts/WoltLabSuite/Core/Ajax/Backend.ts @@ -15,7 +15,7 @@ const enum RequestType { POST, } -type Payload = Record; +type Payload = FormData | Record; class SetupRequest { private readonly url: string; @@ -79,10 +79,15 @@ class BackendRequest { if (this.#type === RequestType.POST) { init.method = "POST"; - init.headers!["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8"; if (this.#payload) { - init.body = JSON.stringify(this.#payload); + if (this.#payload instanceof FormData) { + init.headers!["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8"; + init.body = this.#payload; + } else { + init.headers!["Content-Type"] = "application/json; charset=UTF-8"; + init.body = JSON.stringify(this.#payload); + } } } else { init.method = "GET"; diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ajax/Backend.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ajax/Backend.js index ed528d7800..374b853e23 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ajax/Backend.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ajax/Backend.js @@ -52,9 +52,15 @@ define(["require", "exports", "tslib", "./Status", "./Error", "../Core"], functi }; if (this.#type === 1 /* RequestType.POST */) { init.method = "POST"; - init.headers["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8"; if (this.#payload) { - init.body = JSON.stringify(this.#payload); + if (this.#payload instanceof FormData) { + init.headers["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8"; + init.body = this.#payload; + } + else { + init.headers["Content-Type"] = "application/json; charset=UTF-8"; + init.body = JSON.stringify(this.#payload); + } } } else {