1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

update fetch requests

This commit is contained in:
Luke Pulverenti 2015-12-06 14:46:18 -05:00
parent 5f6d68e3b5
commit 7c3fa06651
10 changed files with 74 additions and 39 deletions

View file

@ -196,7 +196,7 @@
} else {
fetchRequest.body = paramsToString(request.data);
contentType = contentType || 'application/x-www-form-urlencoded';
contentType = contentType || 'application/x-www-form-urlencoded; charset=UTF-8';
}
}
@ -208,6 +208,21 @@
return fetch(request.url, fetchRequest);
}
function paramsToString(params) {
var values = [];
for (var key in params) {
var value = params[key];
if (value !== null && value !== undefined && value !== '') {
values.push(encodeURIComponent(key) + "=" + encodeURIComponent(value));
}
}
return values.join('&');
}
/**
* Wraps around jQuery ajax methods to add additional info to the request.
*/
@ -407,21 +422,6 @@
});
};
function paramsToString(params) {
var values = [];
for (var key in params) {
var value = params[key];
if (value !== null && value !== undefined && value !== '') {
values.push(encodeURIComponent(key) + "=" + encodeURIComponent(value));
}
}
return values.join('&');
}
/**
* Creates an api url based on a handler name and query string parameters
* @param {String} name

View file

@ -95,23 +95,52 @@
method: request.type
};
var contentType = request.contentType;
if (request.data) {
if (typeof request.data === 'string') {
fetchRequest.body = request.data;
} else {
fetchRequest.body = paramsToString(request.data);
contentType = contentType || 'application/x-www-form-urlencoded; charset=UTF-8';
}
}
if (request.contentType) {
if (contentType) {
headers['Content-Type'] = request.contentType;
headers['Content-Type'] = contentType;
}
return fetch(request.url, fetchRequest);
}
function paramsToString(params) {
var values = [];
for (var key in params) {
var value = params[key];
if (value !== null && value !== undefined && value !== '') {
values.push(encodeURIComponent(key) + "=" + encodeURIComponent(value));
}
}
return values.join('&');
}
function ajax(request) {
if (!request) {
throw new Error("Request cannot be null");
}
request.headers = request.headers || {};
logger.log('Requesting url without automatic networking: ' + request.url);
return getFetchPromise(request).then(function (response) {
if (response.status < 400) {
@ -122,12 +151,10 @@
return response;
}
} else {
onFetchFail(request.url, response);
return Promise.reject(response);
}
}, function () {
onFetchFail(request.url, {});
return Promise.reject({});
});
}
@ -1227,17 +1254,22 @@
"X-CONNECT-TOKEN": "CONNECT-REGISTER"
}
}).then(resolve, function (e) {
}).then(resolve, function (response) {
try {
return response.json();
var result = JSON.parse(e.responseText);
reject({ errorCode: result.Status });
} catch (err) {
reject({});
reject();
}
});
}).then(function (result) {
if (result && result.Status) {
reject({ errorCode: result.Status });
}
}, reject);
});
});
};

View file

@ -29,14 +29,14 @@
"webcomponentsjs": "webcomponents/webcomponentsjs#^0.7.0"
},
"ignore": [],
"homepage": "https://github.com/PolymerElements/iron-behaviors",
"homepage": "https://github.com/polymerelements/iron-behaviors",
"_release": "1.0.11",
"_resolution": {
"type": "version",
"tag": "v1.0.11",
"commit": "084fbc7f60343d717bb2208f350774f4c9899777"
},
"_source": "git://github.com/PolymerElements/iron-behaviors.git",
"_source": "git://github.com/polymerelements/iron-behaviors.git",
"_target": "^1.0.0",
"_originalSource": "PolymerElements/iron-behaviors"
"_originalSource": "polymerelements/iron-behaviors"
}

View file

@ -106,7 +106,8 @@
ValidateLogin: true
}),
data: JSON.stringify(info),
contentType: "application/json"
contentType: "application/json",
dataType: 'json'
}).then(function (result) {

View file

@ -1,5 +1,5 @@
.viewMenuBar, .libraryViewNav:not(.paperLibraryViewNav), paper-tabs {
background-color: #101010;
background-color: #080808;
}
.viewMenuBar.semiTransparent {
@ -7,7 +7,7 @@
}
.background-theme-b, paper-dialog.background-theme-b {
background-color: #202020;
background-color: #1b1b1b;
}
.defaultBackground .cardImage {

View file

@ -191,7 +191,7 @@
}
function supportInAppSignup() {
return AppInfo.isNativeApp;
return true;
return AppInfo.isNativeApp || window.location.href.toLowerCase().indexOf('https') == 0;
}

View file

@ -44,7 +44,8 @@
CameraUploadPath: $('#txtUploadPath', page).val()
}),
contentType: "application/json"
contentType: "application/json",
dataType: 'json'
}).then(Dashboard.processServerConfigurationUpdateResult);
}

View file

@ -37,7 +37,7 @@
data: JSON.stringify(info),
contentType: "application/json"
}).then(function (result) {
}).then(function () {
Dashboard.processServerConfigurationUpdateResult();
Dashboard.navigate('livetvstatus.html');

View file

@ -759,9 +759,10 @@ var Dashboard = {
if (!apiClient) {
var deferred = $.Deferred();
deferred.reject();
return deferred.promise();
return new Promise(function (resolve, reject) {
reject();
});
}
if (!Dashboard.getPluginSecurityInfoPromise) {

View file

@ -483,7 +483,7 @@ paper-textarea.mono textarea {
}
.ui-body-b .paperList {
background-color: #303030;
background-color: #2b2b2b;
}
paper-dropdown-menu {