mirror of https://github.com/portainer/portainer
parent
f761e65167
commit
822c4e117c
|
@ -1,18 +1,9 @@
|
||||||
angular.module('portainer.agent').factory('HostBrowserService', [
|
import angular from 'angular';
|
||||||
'Browse',
|
|
||||||
'Upload',
|
|
||||||
'API_ENDPOINT_ENDPOINTS',
|
|
||||||
'EndpointProvider',
|
|
||||||
'$q',
|
|
||||||
'StateManager',
|
|
||||||
function HostBrowserServiceFactory(Browse, Upload, API_ENDPOINT_ENDPOINTS, EndpointProvider, $q, StateManager) {
|
|
||||||
var service = {};
|
|
||||||
|
|
||||||
service.ls = ls;
|
angular.module('portainer.agent').factory('HostBrowserService', HostBrowserServiceFactory);
|
||||||
service.get = get;
|
|
||||||
service.delete = deletePath;
|
function HostBrowserServiceFactory(Browse, Upload, API_ENDPOINT_ENDPOINTS, EndpointProvider, StateManager) {
|
||||||
service.rename = rename;
|
return { ls, get, delete: deletePath, rename, upload };
|
||||||
service.upload = upload;
|
|
||||||
|
|
||||||
function ls(path) {
|
function ls(path) {
|
||||||
return Browse.ls({ path: path }).$promise;
|
return Browse.ls({ path: path }).$promise;
|
||||||
|
@ -27,7 +18,7 @@ angular.module('portainer.agent').factory('HostBrowserService', [
|
||||||
}
|
}
|
||||||
|
|
||||||
function rename(path, newPath) {
|
function rename(path, newPath) {
|
||||||
var payload = {
|
const payload = {
|
||||||
CurrentFilePath: path,
|
CurrentFilePath: path,
|
||||||
NewFilePath: newPath,
|
NewFilePath: newPath,
|
||||||
};
|
};
|
||||||
|
@ -35,17 +26,14 @@ angular.module('portainer.agent').factory('HostBrowserService', [
|
||||||
}
|
}
|
||||||
|
|
||||||
function upload(path, file, onProgress) {
|
function upload(path, file, onProgress) {
|
||||||
var deferred = $q.defer();
|
const agentVersion = StateManager.getAgentApiVersion();
|
||||||
var agentVersion = StateManager.getAgentApiVersion();
|
const url = `${API_ENDPOINT_ENDPOINTS}/${EndpointProvider.endpointID()}/docker${agentVersion > 1 ? '/v' + agentVersion : ''}/browse/put`;
|
||||||
var url = API_ENDPOINT_ENDPOINTS + '/' + EndpointProvider.endpointID() + '/docker' + (agentVersion > 1 ? '/v' + agentVersion : '') + '/browse/put';
|
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
Upload.upload({
|
Upload.upload({
|
||||||
url: url,
|
url: url,
|
||||||
data: { file: file, Path: path },
|
data: { file: file, Path: path },
|
||||||
}).then(deferred.resolve, deferred.reject, onProgress);
|
}).then(resolve, reject, onProgress);
|
||||||
return deferred.promise;
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return service;
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
|
|
Loading…
Reference in New Issue