2020-07-23 07:46:29 +00:00
|
|
|
import angular from 'angular';
|
|
|
|
|
|
|
|
angular.module('portainer.agent').factory('VolumeBrowserService', VolumeBrowserServiceFactory);
|
|
|
|
|
|
|
|
function VolumeBrowserServiceFactory(StateManager, Browse, BrowseVersion1, API_ENDPOINT_ENDPOINTS, EndpointProvider, Upload) {
|
|
|
|
return {
|
|
|
|
ls,
|
|
|
|
get,
|
|
|
|
delete: deletePath,
|
|
|
|
rename,
|
|
|
|
upload,
|
|
|
|
};
|
|
|
|
|
|
|
|
function getAgentApiVersion() {
|
|
|
|
const state = StateManager.getState();
|
|
|
|
return state.endpoint.agentApiVersion;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getBrowseService() {
|
|
|
|
const agentVersion = getAgentApiVersion();
|
|
|
|
return agentVersion > 1 ? Browse : BrowseVersion1;
|
|
|
|
}
|
|
|
|
|
|
|
|
function ls(volumeId, path) {
|
|
|
|
return getBrowseService().ls({ volumeID: volumeId, path, version: getAgentApiVersion() }).$promise;
|
|
|
|
}
|
|
|
|
|
|
|
|
function get(volumeId, path) {
|
|
|
|
return getBrowseService().get({ volumeID: volumeId, path, version: getAgentApiVersion() }).$promise;
|
|
|
|
}
|
|
|
|
|
|
|
|
function deletePath(volumeId, path) {
|
|
|
|
return getBrowseService().delete({ volumeID: volumeId, path, version: getAgentApiVersion() }).$promise;
|
|
|
|
}
|
|
|
|
|
|
|
|
function rename(volumeId, path, newPath) {
|
|
|
|
const payload = {
|
|
|
|
CurrentFilePath: path,
|
|
|
|
NewFilePath: newPath,
|
2018-10-11 22:32:17 +00:00
|
|
|
};
|
2020-07-23 07:46:29 +00:00
|
|
|
return getBrowseService().rename({ volumeID: volumeId, version: getAgentApiVersion() }, payload).$promise;
|
|
|
|
}
|
2018-07-23 05:01:03 +00:00
|
|
|
|
2020-07-23 07:46:29 +00:00
|
|
|
function upload(path, file, volumeId, onProgress) {
|
|
|
|
const agentVersion = StateManager.getAgentApiVersion();
|
|
|
|
if (agentVersion < 2) {
|
|
|
|
throw new Error('upload is not supported on this agent version');
|
|
|
|
}
|
2018-10-26 03:16:29 +00:00
|
|
|
|
2020-07-23 07:46:29 +00:00
|
|
|
const url = `${API_ENDPOINT_ENDPOINTS}/${EndpointProvider.endpointID()}/docker/v${agentVersion}/browse/put?volumeID=${volumeId}`;
|
2018-10-26 03:16:29 +00:00
|
|
|
|
2020-07-23 07:46:29 +00:00
|
|
|
return new Promise((resolve, reject) => {
|
2018-10-26 03:16:29 +00:00
|
|
|
Upload.upload({
|
|
|
|
url: url,
|
2020-07-23 07:46:29 +00:00
|
|
|
data: { file, Path: path },
|
|
|
|
}).then(resolve, reject, onProgress);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|