2020-07-23 10:46:02 +03:00
|
|
|
import angular from 'angular';
|
2018-10-26 06:16:29 +03:00
|
|
|
|
2020-07-23 10:46:02 +03:00
|
|
|
angular.module('portainer.agent').factory('HostBrowserService', HostBrowserServiceFactory);
|
|
|
|
|
|
|
|
function HostBrowserServiceFactory(Browse, Upload, API_ENDPOINT_ENDPOINTS, EndpointProvider, StateManager) {
|
|
|
|
return { ls, get, delete: deletePath, rename, upload };
|
|
|
|
|
|
|
|
function ls(path) {
|
|
|
|
return Browse.ls({ path: path }).$promise;
|
|
|
|
}
|
|
|
|
|
|
|
|
function get(path) {
|
|
|
|
return Browse.get({ path: path }).$promise;
|
|
|
|
}
|
|
|
|
|
|
|
|
function deletePath(path) {
|
|
|
|
return Browse.delete({ path: path }).$promise;
|
|
|
|
}
|
|
|
|
|
|
|
|
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) => {
|
2018-10-12 01:32:17 +03:00
|
|
|
Upload.upload({
|
2018-10-26 06:16:29 +03:00
|
|
|
url: url,
|
2020-04-11 00:54:53 +03:00
|
|
|
data: { file: file, Path: path },
|
2020-07-23 10:46:02 +03:00
|
|
|
}).then(resolve, reject, onProgress);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|