This commit is contained in:
2026-02-11 05:05:32 +01:00
parent 42caaecb18
commit 7345010391
5 changed files with 30 additions and 10 deletions
+9 -4
View File
@@ -14,6 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = fetchApi;
const lodash_1 = __importDefault(require("lodash"));
const serialize_query_1 = __importDefault(require("../../package-shared/utils/serialize-query"));
/**
* # Fetch API
*/
@@ -26,19 +27,23 @@ function fetchApi(url, options) {
if ((options === null || options === void 0 ? void 0 : options.csrfKey) && options.csrfValue) {
finalHeaders[options.csrfKey] = options.csrfValue;
}
let finalURL = url;
if (options === null || options === void 0 ? void 0 : options.query) {
finalURL += (0, serialize_query_1.default)(options.query);
}
if (typeof options === "string") {
try {
let fetchData;
switch (options) {
case "post":
fetchData = yield fetch(url, {
fetchData = yield fetch(finalURL, {
method: options,
headers: finalHeaders,
});
data = fetchData.json();
break;
default:
fetchData = yield fetch(url);
fetchData = yield fetch(finalURL);
data = fetchData.json();
break;
}
@@ -60,7 +65,7 @@ function fetchApi(url, options) {
}
fetchOptions.headers = lodash_1.default.merge(finalHeaders, options.headers || {});
fetchOptions = lodash_1.default.merge(fetchOptions, options.fetchOptions);
fetchData = yield fetch(url, fetchOptions);
fetchData = yield fetch(finalURL, fetchOptions);
data = fetchData.json();
}
catch (error) {
@@ -70,7 +75,7 @@ function fetchApi(url, options) {
}
else {
try {
let fetchData = yield fetch(url);
let fetchData = yield fetch(finalURL);
data = yield fetchData.json();
}
catch (error) {