Add support for renaming files on the fly in the file manager

This commit is contained in:
Dane Everitt 2019-02-18 20:41:58 -08:00
parent 52115b5c77
commit ff820f30ad
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
10 changed files with 230 additions and 37 deletions

View file

@ -1,27 +1,13 @@
import {ServerApplicationCredentials} from "@/store/types";
import http from "@/api/http";
import {AxiosError, AxiosRequestConfig} from "axios";
import {ServerData} from "@/models/server";
import {withCredentials} from "@/api/http";
/**
* Connects to the remote daemon and creates a new folder on the server.
*/
export function createFolder(server: ServerData, credentials: ServerApplicationCredentials, path: string): Promise<void> {
const config: AxiosRequestConfig = {
baseURL: credentials.node,
headers: {
'X-Access-Server': server.uuid,
'X-Access-Token': credentials.key,
},
};
export function createFolder(server: string, credentials: ServerApplicationCredentials, path: string): Promise<void> {
return new Promise((resolve, reject) => {
http.post('/v1/server/file/folder', { path }, config)
.then(() => {
resolve();
})
.catch((error: AxiosError) => {
reject(error);
});
withCredentials(server, credentials).post('/v1/server/file/folder', { path })
.then(() => resolve())
.catch(reject);
});
}

View file

@ -0,0 +1,23 @@
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);
});
}