This repository has been archived on 2022-01-02. You can view files and clone it, but cannot push or open issues or pull requests.
AriaNg/app/scripts/services/aria2HttpRpcService.js

40 lines
1.2 KiB
JavaScript
Raw Normal View History

(function () {
'use strict';
angular.module('ariaNg').factory('aria2HttpRpcService', ['$http', 'ariaNgSettingService', function ($http, ariaNgSettingService) {
2016-05-16 18:59:27 +02:00
var rpcUrl = ariaNgSettingService.getJsonRpcUrl();
return {
request: function (context) {
if (!context) {
return;
}
var requestContext = {
url: rpcUrl,
method: 'POST',
data: context.requestBody
};
return $http(requestContext).success(function (data, header, config, status) {
2016-05-31 18:01:16 +02:00
if (!data) {
return;
}
2016-06-10 13:23:16 +02:00
if (context.successCallback) {
context.successCallback(data.id, data.result);
}
}).error(function (data, header, config, status) {
2016-06-02 18:16:27 +02:00
if (!data) {
return;
}
2016-06-04 11:08:42 +02:00
if (context.errorCallback) {
2016-06-10 13:23:16 +02:00
context.errorCallback(data.id, data.error);
2016-06-02 18:16:27 +02:00
}
});
}
};
}]);
})();