Add support for moving files via the file manager

This commit is contained in:
Dane Everitt 2019-03-16 16:36:08 -07:00
parent 5aa40800c8
commit 4e669771ca
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
5 changed files with 154 additions and 10 deletions

View file

@ -1,15 +1,17 @@
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: {
currentPath: string, newPath: string
}): Promise<void> {
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/copy', {
withCredentials(server, credentials).post(`/v1/server/file/${isMove ? 'move' : 'copy'}`, {
from: data.currentPath,
to: data.newPath,
})
@ -17,3 +19,11 @@ export function copyElement(server: string, credentials: ServerApplicationCreden
.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);
}