mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2025-09-17 17:14:18 +02:00
New: Many UI Updates and Performance Tweaks
This commit is contained in:
@@ -1,6 +1,34 @@
|
||||
import $ from 'jquery';
|
||||
|
||||
export default function createAjaxRequest(ajaxOptions) {
|
||||
const absUrlRegex = /^(https?:)?\/\//i;
|
||||
const apiRoot = window.Radarr.apiRoot;
|
||||
|
||||
function isRelative(ajaxOptions) {
|
||||
return !absUrlRegex.test(ajaxOptions.url);
|
||||
}
|
||||
|
||||
function moveBodyToQuery(ajaxOptions) {
|
||||
if (ajaxOptions.data && ajaxOptions.type === 'DELETE') {
|
||||
if (ajaxOptions.url.contains('?')) {
|
||||
ajaxOptions.url += '&';
|
||||
} else {
|
||||
ajaxOptions.url += '?';
|
||||
}
|
||||
ajaxOptions.url += $.param(ajaxOptions.data);
|
||||
delete ajaxOptions.data;
|
||||
}
|
||||
}
|
||||
|
||||
function addRootUrl(ajaxOptions) {
|
||||
ajaxOptions.url = apiRoot + ajaxOptions.url;
|
||||
}
|
||||
|
||||
function addApiKey(ajaxOptions) {
|
||||
ajaxOptions.headers = ajaxOptions.headers || {};
|
||||
ajaxOptions.headers['X-Api-Key'] = window.Radarr.apiKey;
|
||||
}
|
||||
|
||||
export default function createAjaxRequest(originalAjaxOptions) {
|
||||
const requestXHR = new window.XMLHttpRequest();
|
||||
let aborted = false;
|
||||
let complete = false;
|
||||
@@ -12,6 +40,14 @@ export default function createAjaxRequest(ajaxOptions) {
|
||||
}
|
||||
}
|
||||
|
||||
const ajaxOptions = { ...originalAjaxOptions };
|
||||
|
||||
if (isRelative(ajaxOptions)) {
|
||||
moveBodyToQuery(ajaxOptions);
|
||||
addRootUrl(ajaxOptions);
|
||||
addApiKey(ajaxOptions);
|
||||
}
|
||||
|
||||
const request = $.ajax({
|
||||
xhr: () => requestXHR,
|
||||
...ajaxOptions
|
||||
|
@@ -1,5 +1,6 @@
|
||||
import $ from 'jquery';
|
||||
import _ from 'lodash';
|
||||
import createAjaxRequest from './createAjaxRequest';
|
||||
|
||||
function flattenProviderData(providerData) {
|
||||
return _.reduce(Object.keys(providerData), (result, key) => {
|
||||
@@ -34,7 +35,7 @@ function requestAction(payload) {
|
||||
ajaxOptions.url += `?${$.param(queryParams, true)}`;
|
||||
}
|
||||
|
||||
return $.ajax(ajaxOptions);
|
||||
return createAjaxRequest(ajaxOptions).request;
|
||||
}
|
||||
|
||||
export default requestAction;
|
||||
|
Reference in New Issue
Block a user