Initial Commit Rework

This commit is contained in:
Qstick 2017-09-03 22:20:56 -04:00
parent 74a4cc048c
commit 95051cbd63
2483 changed files with 101351 additions and 111396 deletions

View file

@ -0,0 +1,47 @@
const $ = require('JsLibraries/jquery');
const absUrlRegex = /^(https?:)?\/\//i;
const apiRoot = window.Sonarr.apiRoot;
const urlBase = window.Sonarr.urlBase;
function isRelative(xhr) {
return !absUrlRegex.test(xhr.url);
}
function moveBodyToQuery(xhr) {
if (xhr.data && xhr.type === 'DELETE') {
if (xhr.url.contains('?')) {
xhr.url += '&';
} else {
xhr.url += '?';
}
xhr.url += $.param(xhr.data);
delete xhr.data;
}
}
function addRootUrl(xhr) {
const url = xhr.url;
if (url.startsWith('/signalr')) {
xhr.url = urlBase + xhr.url;
} else {
xhr.url = apiRoot + xhr.url;
}
}
function addApiKey(xhr) {
xhr.headers = xhr.headers || {};
xhr.headers['X-Api-Key'] = window.Sonarr.apiKey;
}
module.exports = function(jQuery) {
const originalAjax = jQuery.ajax;
jQuery.ajax = function(xhr) {
if (xhr && isRelative(xhr)) {
moveBodyToQuery(xhr);
addRootUrl(xhr);
addApiKey(xhr);
}
return originalAjax.apply(this, arguments);
};
};