Add support for file copy and deletion
This commit is contained in:
parent
811026895b
commit
d79fe6982f
12 changed files with 173 additions and 53 deletions
|
@ -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);
|
||||
}
|
13
resources/assets/scripts/api/server/files/copyFile.ts
Normal file
13
resources/assets/scripts/api/server/files/copyFile.ts
Normal 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);
|
||||
});
|
||||
}
|
|
@ -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);
|
||||
})
|
||||
}
|
13
resources/assets/scripts/api/server/files/deleteFile.ts
Normal file
13
resources/assets/scripts/api/server/files/deleteFile.ts
Normal 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);
|
||||
})
|
||||
}
|
|
@ -10,12 +10,12 @@
|
|||
import {DirectoryContentObject} from '@/api/server/types';
|
||||
import {mapState} from "vuex";
|
||||
import {ServerState} from '@/store/types';
|
||||
import { join } from 'path';
|
||||
import {copyElement} from '@/api/server/files/copyElement';
|
||||
import {join} from 'path';
|
||||
import {copyFile} from '@/api/server/files/copyFile';
|
||||
import {AxiosError} from "axios";
|
||||
|
||||
export default Vue.extend({
|
||||
components: { SpinnerModal },
|
||||
components: {SpinnerModal},
|
||||
|
||||
computed: mapState('server', {
|
||||
server: (state: ServerState) => state.server,
|
||||
|
@ -24,7 +24,7 @@
|
|||
}),
|
||||
|
||||
props: {
|
||||
file: { type: Object as () => DirectoryContentObject, required: true },
|
||||
file: {type: Object as () => DirectoryContentObject, required: true},
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -46,7 +46,7 @@
|
|||
}
|
||||
}
|
||||
|
||||
copyElement(this.server.uuid, this.credentials, {currentPath: join(this.fm.currentDirectory, this.file.name), newPath})
|
||||
copyFile(this.server.uuid, join(this.fm.currentDirectory, this.file.name))
|
||||
.then(() => this.$emit('close'))
|
||||
.catch((error: AxiosError) => {
|
||||
alert(`There was an error creating a copy of this item: ${error.message}`);
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
import Vue from 'vue';
|
||||
import Modal from '@/components/core/Modal.vue';
|
||||
import {DirectoryContentObject} from "@/api/server/types";
|
||||
import {deleteElement} from '@/api/server/files/deleteElement';
|
||||
import {deleteFile} from '@/api/server/files/deleteFile';
|
||||
import {mapState} from "vuex";
|
||||
import {AxiosError} from "axios";
|
||||
import { join } from 'path';
|
||||
|
@ -75,10 +75,7 @@
|
|||
this.isLoading = true;
|
||||
|
||||
// @ts-ignore
|
||||
deleteElement(this.server.uuid, this.credentials, [
|
||||
// @ts-ignore
|
||||
join(this.fm.currentDirectory, this.object.name)
|
||||
])
|
||||
deleteFile(this.server.uuid, join(this.fm.currentDirectory, this.object.name))
|
||||
.then(() => this.$emit('deleted'))
|
||||
.catch((error: AxiosError) => {
|
||||
this.error = `There was an error deleting the requested ${(this.object.directory) ? 'folder' : 'file'}. Response was: ${error.message}`;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue