Update support for moving/renaming files and folders
This commit is contained in:
parent
eed4be49ab
commit
811026895b
9 changed files with 97 additions and 41 deletions
|
@ -1,23 +0,0 @@
|
|||
import {withCredentials} from "@/api/http";
|
||||
import {ServerApplicationCredentials} from "@/store/types";
|
||||
import { join } from 'path';
|
||||
|
||||
type RenameObject = {
|
||||
path: string,
|
||||
fromName: string,
|
||||
toName: string,
|
||||
}
|
||||
|
||||
/**
|
||||
* Renames a file or folder on the server using the node.
|
||||
*/
|
||||
export function renameElement(server: string, credentials: ServerApplicationCredentials, data: RenameObject): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
withCredentials(server, credentials).post('/v1/server/file/rename', {
|
||||
from: join(data.path, data.fromName),
|
||||
to: join(data.path, data.toName),
|
||||
})
|
||||
.then(() => resolve())
|
||||
.catch(reject);
|
||||
});
|
||||
}
|
12
resources/assets/scripts/api/server/files/renameFile.ts
Normal file
12
resources/assets/scripts/api/server/files/renameFile.ts
Normal file
|
@ -0,0 +1,12 @@
|
|||
import http from "@/api/http";
|
||||
|
||||
export function renameFile(server: string, renameFrom: string, renameTo: string): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
http.put(`/api/client/servers/${server}/files/rename`, {
|
||||
rename_from: renameFrom,
|
||||
rename_to: renameTo,
|
||||
})
|
||||
.then(() => resolve())
|
||||
.catch(reject);
|
||||
});
|
||||
}
|
|
@ -42,7 +42,7 @@
|
|||
import Modal from "@/components/core/Modal.vue";
|
||||
import MessageBox from "@/components/MessageBox.vue";
|
||||
import {DirectoryContentObject} from "@/api/server/types";
|
||||
import {moveElement} from '@/api/server/files/copyElement';
|
||||
import {renameFile} from '@/api/server/files/renameFile';
|
||||
import {mapState} from "vuex";
|
||||
import {ApplicationState} from "@/store/types";
|
||||
import {join} from 'path';
|
||||
|
@ -106,12 +106,7 @@
|
|||
this.isLoading = true;
|
||||
|
||||
// @ts-ignore
|
||||
moveElement(this.server.uuid, this.credentials, {
|
||||
// @ts-ignore
|
||||
currentPath: join(this.fm.currentDirectory, this.file.name),
|
||||
// @ts-ignore
|
||||
newPath: join(this.fm.currentDirectory, this.moveTo),
|
||||
})
|
||||
renameFile(this.server.uuid, join(this.fm.currentDirectory, this.file.name), join(this.fm.currentDirectory, this.moveTo))
|
||||
.then(() => this.$emit('moved'))
|
||||
.catch((error: AxiosError) => {
|
||||
this.error = `There was an error moving the requested ${(this.file.directory) ? 'folder' : 'file'}. Response was: ${error.message}`;
|
||||
|
|
|
@ -47,9 +47,10 @@
|
|||
import MessageBox from '@/components/MessageBox.vue';
|
||||
import {DirectoryContentObject} from "@/api/server/types";
|
||||
import {mapState} from "vuex";
|
||||
import {renameElement} from "@/api/server/files/renameElement";
|
||||
import {renameFile} from "@/api/server/files/renameFile";
|
||||
import {AxiosError} from 'axios';
|
||||
import {ApplicationState} from "@/store/types";
|
||||
import {join} from "path";
|
||||
|
||||
type DataStructure = {
|
||||
error: null | string,
|
||||
|
@ -109,12 +110,7 @@
|
|||
this.error = null;
|
||||
|
||||
// @ts-ignore
|
||||
renameElement(this.server.uuid, this.credentials, {
|
||||
// @ts-ignore
|
||||
path: this.fm.currentDirectory,
|
||||
toName: this.newName,
|
||||
fromName: this.object.name
|
||||
})
|
||||
renameFile(this.server.uuid, join(this.fm.currentDirectory, this.object.name), join(this.fm.currentDirectory, this.newName))
|
||||
.then(() => {
|
||||
this.$emit('renamed', this.newName);
|
||||
this.closeModal();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue