mirror of
https://github.com/lidarr/lidarr.git
synced 2025-07-16 10:03:51 -07:00
Initial Commit Rework
This commit is contained in:
parent
74a4cc048c
commit
95051cbd63
2483 changed files with 101351 additions and 111396 deletions
47
frontend/src/jQuery/jquery.ajax.js
Normal file
47
frontend/src/jQuery/jquery.ajax.js
Normal 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);
|
||||
};
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue