2018-10-11 22:32:17 +00:00
|
|
|
angular.module('portainer.agent').factory('VolumeBrowserService', [
|
2020-04-10 21:54:53 +00:00
|
|
|
'StateManager',
|
|
|
|
'Browse',
|
|
|
|
'BrowseVersion1',
|
|
|
|
'$q',
|
|
|
|
'API_ENDPOINT_ENDPOINTS',
|
|
|
|
'EndpointProvider',
|
|
|
|
'Upload',
|
2018-10-26 03:16:29 +00:00
|
|
|
function VolumeBrowserServiceFactory(StateManager, Browse, BrowseVersion1, $q, API_ENDPOINT_ENDPOINTS, EndpointProvider, Upload) {
|
2018-10-11 22:32:17 +00:00
|
|
|
'use strict';
|
|
|
|
var service = {};
|
2018-07-23 05:01:03 +00:00
|
|
|
|
2018-10-26 03:16:29 +00:00
|
|
|
function getAgentApiVersion() {
|
|
|
|
var state = StateManager.getState();
|
|
|
|
return state.endpoint.agentApiVersion;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getBrowseService() {
|
|
|
|
var agentVersion = getAgentApiVersion();
|
|
|
|
return agentVersion > 1 ? Browse : BrowseVersion1;
|
|
|
|
}
|
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
service.ls = function (volumeId, path) {
|
2018-10-26 03:16:29 +00:00
|
|
|
return getBrowseService().ls({ volumeID: volumeId, path: path, version: getAgentApiVersion() }).$promise;
|
2018-10-11 22:32:17 +00:00
|
|
|
};
|
2018-07-23 05:01:03 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
service.get = function (volumeId, path) {
|
2018-10-26 03:16:29 +00:00
|
|
|
return getBrowseService().get({ volumeID: volumeId, path: path, version: getAgentApiVersion() }).$promise;
|
2018-10-11 22:32:17 +00:00
|
|
|
};
|
2018-07-23 05:01:03 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
service.delete = function (volumeId, path) {
|
2018-10-26 03:16:29 +00:00
|
|
|
return getBrowseService().delete({ volumeID: volumeId, path: path, version: getAgentApiVersion() }).$promise;
|
2018-10-11 22:32:17 +00:00
|
|
|
};
|
2018-07-23 05:01:03 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
service.rename = function (volumeId, path, newPath) {
|
2018-10-11 22:32:17 +00:00
|
|
|
var payload = {
|
2020-04-10 21:54:53 +00:00
|
|
|
CurrentFilePath: path,
|
|
|
|
NewFilePath: newPath,
|
2018-10-11 22:32:17 +00:00
|
|
|
};
|
2018-10-26 03:16:29 +00:00
|
|
|
return getBrowseService().rename({ volumeID: volumeId, version: getAgentApiVersion() }, payload).$promise;
|
|
|
|
};
|
|
|
|
|
|
|
|
service.upload = function upload(path, file, volumeId, onProgress) {
|
|
|
|
var deferred = $q.defer();
|
|
|
|
var agentVersion = StateManager.getAgentApiVersion();
|
2020-04-10 21:54:53 +00:00
|
|
|
if (agentVersion < 2) {
|
2018-10-26 03:16:29 +00:00
|
|
|
deferred.reject('upload is not supported on this agent version');
|
|
|
|
return;
|
|
|
|
}
|
2020-04-10 21:54:53 +00:00
|
|
|
var url = API_ENDPOINT_ENDPOINTS + '/' + EndpointProvider.endpointID() + '/docker' + '/v' + agentVersion + '/browse/put?volumeID=' + volumeId;
|
2018-10-26 03:16:29 +00:00
|
|
|
|
|
|
|
Upload.upload({
|
|
|
|
url: url,
|
2020-04-10 21:54:53 +00:00
|
|
|
data: { file: file, Path: path },
|
2018-10-26 03:16:29 +00:00
|
|
|
}).then(deferred.resolve, deferred.reject, onProgress);
|
|
|
|
return deferred.promise;
|
2018-07-23 05:01:03 +00:00
|
|
|
};
|
|
|
|
|
2018-10-11 22:32:17 +00:00
|
|
|
return service;
|
2020-04-10 21:54:53 +00:00
|
|
|
},
|
2018-10-11 22:32:17 +00:00
|
|
|
]);
|