From: Tim Düsterhus Date: Fri, 25 Aug 2023 08:20:56 +0000 (+0200) Subject: Migrate RewriteTest.ts to the fetch-based request API X-Git-Tag: 6.0.0_Beta_4~54^2 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=59d95373173c6820e740c4808e6ce1c081fdf0b9;p=GitHub%2FWoltLab%2FWCF.git Migrate RewriteTest.ts to the fetch-based request API This makes the code much more readable and also prevents browser-side caching by default. --- diff --git a/ts/WoltLabSuite/Core/Acp/Ui/Option/RewriteTest.ts b/ts/WoltLabSuite/Core/Acp/Ui/Option/RewriteTest.ts index dbda953dcb..65dbe00dee 100644 --- a/ts/WoltLabSuite/Core/Acp/Ui/Option/RewriteTest.ts +++ b/ts/WoltLabSuite/Core/Acp/Ui/Option/RewriteTest.ts @@ -6,11 +6,11 @@ * @license GNU Lesser General Public License */ -import AjaxRequest from "../../../Ajax/Request"; import * as Language from "../../../Language"; import UiDialog from "../../../Ui/Dialog"; import { DialogCallbackSetup } from "../../../Ui/Dialog/Data"; import DomUtil from "../../../Dom/Util"; +import { prepareRequest } from "WoltLabSuite/Core/Ajax/Backend"; interface TestResult { app: string; @@ -72,35 +72,29 @@ class RewriteTest { this.setStatus("running"); const tests: Promise[] = Array.from(this.apps).map(([app, url]) => { - return new Promise((resolve, reject) => { - const request = new AjaxRequest({ - ignoreError: true, - // bypass the LinkHandler, because rewrites aren't enabled yet - url: url, - type: "GET", - includeRequestedWith: false, - success: (data) => { + return prepareRequest(url) + .get() + .disableLoadingIndicator() + .fetchAsJson() + .then( + (data: any) => { if ( !Object.prototype.hasOwnProperty.call(data, "core_rewrite_test") || data.core_rewrite_test !== "passed" ) { - reject({ app, pass: false }); + return false; } else { - resolve({ app, pass: true }); + return true; } }, - failure: () => { - reject({ app, pass: false }); - - return true; - }, + () => false, + ) + .then((pass) => { + return { app, pass }; }); - - request.sendRequest(false); - }); }); - const results: TestResult[] = await Promise.all(tests.map((test) => test.catch((result: TestResult) => result))); + const results: TestResult[] = await Promise.all(tests); const passed = results.every((result) => result.pass); diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/Option/RewriteTest.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/Option/RewriteTest.js index 47feff9e38..ac3e08c94c 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/Option/RewriteTest.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/Option/RewriteTest.js @@ -5,11 +5,10 @@ * @copyright 2001-2019 WoltLab GmbH * @license GNU Lesser General Public License */ -define(["require", "exports", "tslib", "../../../Ajax/Request", "../../../Language", "../../../Ui/Dialog", "../../../Dom/Util"], function (require, exports, tslib_1, Request_1, Language, Dialog_1, Util_1) { +define(["require", "exports", "tslib", "../../../Language", "../../../Ui/Dialog", "../../../Dom/Util", "WoltLabSuite/Core/Ajax/Backend"], function (require, exports, tslib_1, Language, Dialog_1, Util_1, Backend_1) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.init = void 0; - Request_1 = tslib_1.__importDefault(Request_1); Language = tslib_1.__importStar(Language); Dialog_1 = tslib_1.__importDefault(Dialog_1); Util_1 = tslib_1.__importDefault(Util_1); @@ -58,31 +57,24 @@ define(["require", "exports", "tslib", "../../../Ajax/Request", "../../../Langua this.buttonStartTest.classList.add("disabled"); this.setStatus("running"); const tests = Array.from(this.apps).map(([app, url]) => { - return new Promise((resolve, reject) => { - const request = new Request_1.default({ - ignoreError: true, - // bypass the LinkHandler, because rewrites aren't enabled yet - url: url, - type: "GET", - includeRequestedWith: false, - success: (data) => { - if (!Object.prototype.hasOwnProperty.call(data, "core_rewrite_test") || - data.core_rewrite_test !== "passed") { - reject({ app, pass: false }); - } - else { - resolve({ app, pass: true }); - } - }, - failure: () => { - reject({ app, pass: false }); - return true; - }, - }); - request.sendRequest(false); + return (0, Backend_1.prepareRequest)(url) + .get() + .disableLoadingIndicator() + .fetchAsJson() + .then((data) => { + if (!Object.prototype.hasOwnProperty.call(data, "core_rewrite_test") || + data.core_rewrite_test !== "passed") { + return false; + } + else { + return true; + } + }, () => false) + .then((pass) => { + return { app, pass }; }); }); - const results = await Promise.all(tests.map((test) => test.catch((result) => result))); + const results = await Promise.all(tests); const passed = results.every((result) => result.pass); // Delay the status update to prevent UI flicker. await new Promise((resolve) => window.setTimeout(resolve, 500));