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);
});
}

View file

@ -2,7 +2,7 @@ import http from '../http';
import {filter, isObject} from 'lodash';
// @ts-ignore
import route from '../../../../../vendor/tightenco/ziggy/src/js/route';
import {DirectoryContents} from "./types";
import {DirectoryContentObject, DirectoryContents} from "./types";
/**
* Get the contents of a specific directory for a given server.
@ -12,10 +12,10 @@ export function getDirectoryContents(server: string, directory: string): Promise
http.get(route('server.files', {server, directory}))
.then((response) => {
return resolve({
files: filter(response.data.contents, function (o) {
files: filter(response.data.contents, function (o: DirectoryContentObject) {
return o.file;
}),
directories: filter(response.data.contents, function (o) {
directories: filter(response.data.contents, function (o: DirectoryContentObject) {
return o.directory;
}),
editable: response.data.editable,

View file

@ -1,9 +1,21 @@
export type DirectoryContents = {
files: Array<string>,
directories: Array<string>,
files: Array<DirectoryContentObject>,
directories: Array<DirectoryContentObject>,
editable: Array<string>
}
export type DirectoryContentObject = {
name: string,
created: string,
modified: string,
mode: number,
size: number,
directory: boolean,
file: boolean,
symlink: boolean,
mime: string,
}
export type ServerDatabase = {
id: string,
name: string,