4.3.3 ApiVersion workaround, stopped working with jsonp

This commit is contained in:
Trevor Squillario 2015-01-05 19:24:59 -05:00
parent a91e220608
commit 1b526970b3
3 changed files with 35 additions and 41 deletions

View file

@ -351,35 +351,6 @@
}
});
};
$scope.ping = function () {
return $http({
method: 'GET',
timeout: globals.settings.Timeout,
url: globals.BaseURL() + '/ping.view?' + globals.BaseParams(),
}).error(function (data) {
notifications.updateMessage('Unable to connect to Subsonic server');
});
/*
$.ajax({
url: globals.BaseURL() + '/ping.view?' + globals.BaseParams(),
method: 'GET',
dataType: globals.settings.Protocol,
timeout: globals.settings.Timeout,
success: function (data) {
if (data["subsonic-response"].status == 'ok') {
globals.settings.ApiVersion = data["subsonic-response"].version;
} else {
if (typeof data["subsonic-response"].error != 'undefined') {
notifications.updateMessage(data["subsonic-response"].error.message);
}
}
},
error: function () {
notifications.updateMessage('Unable to connect to Subsonic server');
}
});
*/
};
$scope.queueRemoveSelected = function (data, event) {
angular.forEach($scope.selectedSongs, function (item, key) {
var index = $rootScope.queue.indexOf(item);

View file

@ -70,6 +70,7 @@ angular.module('jamstash.settings', [])
this.BaseURL = function () { return this.settings.Server + '/rest'; };
this.BaseParams = function () { return 'u=' + this.settings.Username + '&p=' + this.settings.Password + '&f=' + this.settings.Protocol + '&v=' + this.settings.ApiVersion + '&c=' + this.settings.ApplicationName; };
this.BaseJSONParams = function () { return 'u=' + this.settings.Username + '&p=' + this.settings.Password + '&f=json&v=' + this.settings.ApiVersion + '&c=' + this.settings.ApplicationName; };
})
.factory('json', ['$http', function ($http) { // Deferred loading

View file

@ -1,10 +1,11 @@
angular.module('JamStash')
.controller('SettingsCtrl', ['$rootScope', '$scope', '$routeParams', '$location', 'utils', 'globals', 'json', 'notifications', 'player',
function ($rootScope, $scope, $routeParams, $location, utils, globals, json, notifications, player) {
.controller('SettingsCtrl', ['$rootScope', '$scope', '$routeParams', '$location', '$http', '$q', 'utils', 'globals', 'json', 'notifications', 'player',
function ($rootScope, $scope, $routeParams, $location, $http, $q, utils, globals, json, notifications, player) {
'use strict';
$rootScope.hideQueue();
$scope.settings = globals.settings; /* See service.js */
$scope.ApiVersion = globals.settings.ApiVersion;
$scope.Timeouts = [
{ id: 10000, name: 10 },
{ id: 20000, name: 20 },
@ -27,6 +28,34 @@
$('#AZIndex').show();
}
});
$scope.ping = function () {
var exception = {reason: 'Error when contacting the Subsonic server.'};
var deferred = $q.defer();
var httpPromise;
httpPromise = $http({
method: 'GET',
timeout: globals.settings.Timeout,
// 2015-1-5: This API call only works with json as of SS v5.0?!?
//url: globals.BaseURL() + '/ping.view?' + globals.BaseParams(),
url: globals.BaseURL() + '/ping.view?' + globals.BaseJSONParams()
});
httpPromise.success(function(data, status) {
var subsonicResponse = (data['subsonic-response'] !== undefined) ? data['subsonic-response'] : {status: 'failed'};
if (subsonicResponse.status === 'ok') {
$scope.ApiVersion = subsonicResponse.version;
globals.settings.ApiVersion = $scope.ApiVersion;
deferred.resolve(data);
} else {
if(subsonicResponse.status === 'failed' && subsonicResponse.error !== undefined) {
notifications.updateMessage(subsonicResponse.error.message);
}
}
}).error(function(data, status) {
exception.httpError = status;
deferred.reject(exception);
});
return deferred.promise;
};
$scope.reset = function () {
utils.setValue('Settings', null, true);
$scope.loadSettings();
@ -63,16 +92,9 @@
notifications.updateMessage('Settings Updated!', true);
$scope.loadSettings();
if (globals.settings.Server !== '' && globals.settings.Username !== '' && globals.settings.Password !== '') {
$scope.ping().then(function(data) {
if (data["subsonic-response"].status == 'ok') {
globals.settings.ApiVersion = data["subsonic-response"].version;
$location.path('/library').replace();
$rootScope.showIndex = true;
} else {
if (typeof data["subsonic-response"].error != 'undefined') {
notifications.updateMessage(data["subsonic-response"].error.message);
}
}
$scope.ping().then(function() {
$location.path('/library').replace();
$rootScope.showIndex = true;
});
}
};