Change from manual URL construction to using a lib
Makes the code cleaner to read and more resilient to changes Fixes https://jira.coreos.com/browse/QUAY-940
This commit is contained in:
parent
e33760fcd2
commit
648590c356
13 changed files with 85 additions and 56 deletions
|
@ -1,3 +1,5 @@
|
|||
var urlParseURL = require('url-parse');
|
||||
|
||||
/**
|
||||
* Service which exposes the server-defined API as a nice set of helper methods and automatic
|
||||
* callbacks. Any method defined on the server is exposed here as an equivalent method. Also
|
||||
|
@ -44,7 +46,7 @@ angular.module('quay').factory('ApiService', ['Restangular', '$q', 'UtilService'
|
|||
|
||||
// Build the path, adjusted with the inline parameters.
|
||||
var used = {};
|
||||
var url = '';
|
||||
var urlPath = '';
|
||||
for (var i = 0; i < path.length; ++i) {
|
||||
var c = path[i];
|
||||
if (c == '{') {
|
||||
|
@ -56,29 +58,29 @@ angular.module('quay').factory('ApiService', ['Restangular', '$q', 'UtilService'
|
|||
}
|
||||
|
||||
used[varName] = true;
|
||||
url += parameters[varName];
|
||||
urlPath += encodeURI(parameters[varName]);
|
||||
i = end;
|
||||
continue;
|
||||
}
|
||||
|
||||
url += c;
|
||||
urlPath += c;
|
||||
}
|
||||
|
||||
// Append any query parameters.
|
||||
var isFirst = true;
|
||||
var url = new urlParseURL(urlPath, '/');
|
||||
url.query = {};
|
||||
|
||||
for (var paramName in parameters) {
|
||||
if (!parameters.hasOwnProperty(paramName)) { continue; }
|
||||
if (used[paramName]) { continue; }
|
||||
|
||||
var value = parameters[paramName];
|
||||
if (value != null) {
|
||||
url += isFirst ? '?' : '&';
|
||||
url += paramName + '=' + encodeURIComponent(value)
|
||||
isFirst = false;
|
||||
url.query[paramName] = value
|
||||
}
|
||||
}
|
||||
|
||||
return url;
|
||||
return url.toString();
|
||||
};
|
||||
|
||||
var getGenericOperationName = function(userOperationName) {
|
||||
|
|
Reference in a new issue