Add support for file copy and deletion

This commit is contained in:
Dane Everitt 2019-05-04 17:26:24 -07:00
parent 811026895b
commit d79fe6982f
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
12 changed files with 173 additions and 53 deletions

View file

@ -1,29 +0,0 @@
import {withCredentials} from "@/api/http";
import {ServerApplicationCredentials} from "@/store/types";
type PathChangeObject = {
currentPath: string,
newPath: string,
}
/**
* Creates a copy of the given file or directory on the Daemon. Expects a fully resolved path
* to be passed through for both data arguments.
*/
export function copyElement(server: string, credentials: ServerApplicationCredentials, data: PathChangeObject, isMove = false): Promise<void> {
return new Promise((resolve, reject) => {
withCredentials(server, credentials).post(`/v1/server/file/${isMove ? 'move' : 'copy'}`, {
from: data.currentPath,
to: data.newPath,
})
.then(() => resolve())
.catch(reject);
});
}
/**
* Moves a file or folder to a new location on the server. Works almost exactly the same as the copy
* file logic, so it really just passes an extra argument to copy to indicate that it is a move.
*/
export function moveElement(server: string, credentials: ServerApplicationCredentials, data: PathChangeObject): Promise<void> {
return copyElement(server, credentials, data, true);
}

View file

@ -0,0 +1,13 @@
import http from "@/api/http";
/**
* Creates a copy of the given file or directory on the Daemon. Expects a fully resolved path
* to be passed through for both data arguments.
*/
export function copyFile(server: string, location: string): Promise<void> {
return new Promise((resolve, reject) => {
http.post(`/api/client/servers/${server}/files/copy`, {location})
.then(() => resolve())
.catch(reject);
});
}

View file

@ -1,14 +0,0 @@
import {withCredentials} from "@/api/http";
import {ServerApplicationCredentials} from "@/store/types";
/**
* Deletes files and/or folders from the server. You should pass through an array of
* file or folder paths to be deleted.
*/
export function deleteElement(server: string, credentials: ServerApplicationCredentials, items: Array<string>): Promise<void> {
return new Promise((resolve, reject) => {
withCredentials(server, credentials).post('/v1/server/file/delete', { items })
.then(() => resolve())
.catch(reject);
})
}

View file

@ -0,0 +1,13 @@
import http from "@/api/http";
/**
* Deletes files and/or folders from the server. You should pass through an array of
* file or folder paths to be deleted.
*/
export function deleteFile(server: string, location: string): Promise<void> {
return new Promise((resolve, reject) => {
http.post(`/api/client/servers/${server}/files/delete`, {location})
.then(() => resolve())
.catch(reject);
})
}