refactor(agent): refactor hostBrowserService to es6 (#4092)

related to #4071
pull/4098/head
Chaim Lev-Ari 2020-07-23 10:46:02 +03:00 committed by GitHub
parent f761e65167
commit 822c4e117c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 29 additions and 41 deletions

View File

@ -1,51 +1,39 @@
angular.module('portainer.agent').factory('HostBrowserService', [
'Browse',
'Upload',
'API_ENDPOINT_ENDPOINTS',
'EndpointProvider',
'$q',
'StateManager',
function HostBrowserServiceFactory(Browse, Upload, API_ENDPOINT_ENDPOINTS, EndpointProvider, $q, StateManager) {
var service = {};
import angular from 'angular';
service.ls = ls;
service.get = get;
service.delete = deletePath;
service.rename = rename;
service.upload = upload;
angular.module('portainer.agent').factory('HostBrowserService', HostBrowserServiceFactory);
function ls(path) {
return Browse.ls({ path: path }).$promise;
}
function HostBrowserServiceFactory(Browse, Upload, API_ENDPOINT_ENDPOINTS, EndpointProvider, StateManager) {
return { ls, get, delete: deletePath, rename, upload };
function get(path) {
return Browse.get({ path: path }).$promise;
}
function ls(path) {
return Browse.ls({ path: path }).$promise;
}
function deletePath(path) {
return Browse.delete({ path: path }).$promise;
}
function get(path) {
return Browse.get({ path: path }).$promise;
}
function rename(path, newPath) {
var payload = {
CurrentFilePath: path,
NewFilePath: newPath,
};
return Browse.rename({}, payload).$promise;
}
function deletePath(path) {
return Browse.delete({ path: path }).$promise;
}
function upload(path, file, onProgress) {
var deferred = $q.defer();
var agentVersion = StateManager.getAgentApiVersion();
var url = API_ENDPOINT_ENDPOINTS + '/' + EndpointProvider.endpointID() + '/docker' + (agentVersion > 1 ? '/v' + agentVersion : '') + '/browse/put';
function rename(path, newPath) {
const payload = {
CurrentFilePath: path,
NewFilePath: newPath,
};
return Browse.rename({}, payload).$promise;
}
function upload(path, file, onProgress) {
const agentVersion = StateManager.getAgentApiVersion();
const url = `${API_ENDPOINT_ENDPOINTS}/${EndpointProvider.endpointID()}/docker${agentVersion > 1 ? '/v' + agentVersion : ''}/browse/put`;
return new Promise((resolve, reject) => {
Upload.upload({
url: url,
data: { file: file, Path: path },
}).then(deferred.resolve, deferred.reject, onProgress);
return deferred.promise;
}
return service;
},
]);
}).then(resolve, reject, onProgress);
});
}
}