Update files to new format
This commit is contained in:
parent
feffdacf57
commit
097d308ccd
26 changed files with 173 additions and 181 deletions
142
resources/scripts/api/server/files.ts
Normal file
142
resources/scripts/api/server/files.ts
Normal file
|
@ -0,0 +1,142 @@
|
|||
import http from '@/api/http';
|
||||
import { rawDataToFileObject } from '@/api/transformers';
|
||||
|
||||
export interface FileObject {
|
||||
key: string;
|
||||
name: string;
|
||||
mode: string;
|
||||
modeBits: string,
|
||||
size: number;
|
||||
isFile: boolean;
|
||||
isSymlink: boolean;
|
||||
mimetype: string;
|
||||
createdAt: Date;
|
||||
modifiedAt: Date;
|
||||
isArchiveType: () => boolean;
|
||||
isEditable: () => boolean;
|
||||
}
|
||||
|
||||
const chmodFiles = (uuid: string, directory: string, files: { file: string; mode: string }[]): Promise<void> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
http.post(`/api/client/servers/${uuid}/files/chmod`, { root: directory, files })
|
||||
.then(() => resolve())
|
||||
.catch(reject);
|
||||
});
|
||||
};
|
||||
|
||||
const compressFiles = async (uuid: string, directory: string, files: string[]): Promise<FileObject> => {
|
||||
const { data } = await http.post(`/api/client/servers/${uuid}/files/compress`, { root: directory, files }, {
|
||||
timeout: 60000,
|
||||
timeoutErrorMessage: 'It looks like this archive is taking a long time to generate. It will appear once completed.',
|
||||
});
|
||||
|
||||
return rawDataToFileObject(data);
|
||||
};
|
||||
|
||||
const copyFiles = (uuid: string, location: string): Promise<void> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
http.post(`/api/client/servers/${uuid}/files/copy`, { location })
|
||||
.then(() => resolve())
|
||||
.catch(reject);
|
||||
});
|
||||
};
|
||||
|
||||
const createDirectory = (uuid: string, root: string, name: string): Promise<void> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
http.post(`/api/client/servers/${uuid}/files/create-folder`, { root, name })
|
||||
.then(() => resolve())
|
||||
.catch(reject);
|
||||
});
|
||||
};
|
||||
|
||||
const decompressFiles = async (uuid: string, directory: string, file: string): Promise<void> => {
|
||||
await http.post(`/api/client/servers/${uuid}/files/decompress`, { root: directory, file }, {
|
||||
timeout: 300000,
|
||||
timeoutErrorMessage: 'It looks like this archive is taking a long time to be unarchived. Once completed the unarchived files will appear.',
|
||||
});
|
||||
};
|
||||
|
||||
const deleteFiles = (uuid: string, directory: string, files: string[]): Promise<void> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
http.post(`/api/client/servers/${uuid}/files/delete`, { root: directory, files })
|
||||
.then(() => resolve())
|
||||
.catch(reject);
|
||||
});
|
||||
};
|
||||
|
||||
const getFileContents = (server: string, file: string): Promise<string> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
http.get(`/api/client/servers/${server}/files/contents`, {
|
||||
params: { file },
|
||||
transformResponse: res => res,
|
||||
responseType: 'text',
|
||||
})
|
||||
.then(({ data }) => resolve(data))
|
||||
.catch(reject);
|
||||
});
|
||||
};
|
||||
|
||||
const getFileDownloadUrl = (uuid: string, file: string): Promise<string> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
http.get(`/api/client/servers/${uuid}/files/download`, { params: { file } })
|
||||
.then(({ data }) => resolve(data.attributes.url))
|
||||
.catch(reject);
|
||||
});
|
||||
};
|
||||
|
||||
const getFileUploadUrl = (uuid: string): Promise<string> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
http.get(`/api/client/servers/${uuid}/files/upload`)
|
||||
.then(({ data }) => resolve(data.attributes.url))
|
||||
.catch(reject);
|
||||
});
|
||||
};
|
||||
|
||||
const loadDirectory = async (uuid: string, directory?: string): Promise<FileObject[]> => {
|
||||
const { data } = await http.get(`/api/client/servers/${uuid}/files/list`, {
|
||||
params: { directory: directory ?? '/' },
|
||||
});
|
||||
|
||||
return (data.data || []).map(rawDataToFileObject);
|
||||
};
|
||||
|
||||
const pullFile = (uuid: string, directory: string, url: string): Promise<void> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
http.post(`/api/client/servers/${uuid}/files/pull`, { root: directory, url })
|
||||
.then(() => resolve())
|
||||
.catch(reject);
|
||||
});
|
||||
};
|
||||
|
||||
const renameFiles = (uuid: string, directory: string, files: { from: string; to: string }[]): Promise<void> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
http.put(`/api/client/servers/${uuid}/files/rename`, { root: directory, files })
|
||||
.then(() => resolve())
|
||||
.catch(reject);
|
||||
});
|
||||
};
|
||||
|
||||
const saveFileContents = async (uuid: string, file: string, content: string): Promise<void> => {
|
||||
await http.post(`/api/client/servers/${uuid}/files/write`, content, {
|
||||
params: { file },
|
||||
headers: {
|
||||
'Content-Type': 'text/plain',
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export {
|
||||
chmodFiles,
|
||||
compressFiles,
|
||||
copyFiles,
|
||||
createDirectory,
|
||||
decompressFiles,
|
||||
deleteFiles,
|
||||
getFileContents,
|
||||
getFileDownloadUrl,
|
||||
getFileUploadUrl,
|
||||
loadDirectory,
|
||||
pullFile,
|
||||
renameFiles,
|
||||
saveFileContents,
|
||||
};
|
|
@ -1,14 +0,0 @@
|
|||
import http from '@/api/http';
|
||||
|
||||
interface Data {
|
||||
file: string;
|
||||
mode: string;
|
||||
}
|
||||
|
||||
export default (uuid: string, directory: string, files: Data[]): Promise<void> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
http.post(`/api/client/servers/${uuid}/files/chmod`, { root: directory, files })
|
||||
.then(() => resolve())
|
||||
.catch(reject);
|
||||
});
|
||||
};
|
|
@ -1,12 +0,0 @@
|
|||
import { FileObject } from '@/api/server/files/loadDirectory';
|
||||
import http from '@/api/http';
|
||||
import { rawDataToFileObject } from '@/api/transformers';
|
||||
|
||||
export default async (uuid: string, directory: string, files: string[]): Promise<FileObject> => {
|
||||
const { data } = await http.post(`/api/client/servers/${uuid}/files/compress`, { root: directory, files }, {
|
||||
timeout: 60000,
|
||||
timeoutErrorMessage: 'It looks like this archive is taking a long time to generate. It will appear once completed.',
|
||||
});
|
||||
|
||||
return rawDataToFileObject(data);
|
||||
};
|
|
@ -1,9 +0,0 @@
|
|||
import http from '@/api/http';
|
||||
|
||||
export default (uuid: string, location: string): Promise<void> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
http.post(`/api/client/servers/${uuid}/files/copy`, { location })
|
||||
.then(() => resolve())
|
||||
.catch(reject);
|
||||
});
|
||||
};
|
|
@ -1,9 +0,0 @@
|
|||
import http from '@/api/http';
|
||||
|
||||
export default (uuid: string, root: string, name: string): Promise<void> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
http.post(`/api/client/servers/${uuid}/files/create-folder`, { root, name })
|
||||
.then(() => resolve())
|
||||
.catch(reject);
|
||||
});
|
||||
};
|
|
@ -1,8 +0,0 @@
|
|||
import http from '@/api/http';
|
||||
|
||||
export default async (uuid: string, directory: string, file: string): Promise<void> => {
|
||||
await http.post(`/api/client/servers/${uuid}/files/decompress`, { root: directory, file }, {
|
||||
timeout: 300000,
|
||||
timeoutErrorMessage: 'It looks like this archive is taking a long time to be unarchived. Once completed the unarchived files will appear.',
|
||||
});
|
||||
};
|
|
@ -1,9 +0,0 @@
|
|||
import http from '@/api/http';
|
||||
|
||||
export default (uuid: string, directory: string, files: string[]): Promise<void> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
http.post(`/api/client/servers/${uuid}/files/delete`, { root: directory, files })
|
||||
.then(() => resolve())
|
||||
.catch(reject);
|
||||
});
|
||||
};
|
|
@ -1,13 +0,0 @@
|
|||
import http from '@/api/http';
|
||||
|
||||
export default (server: string, file: string): Promise<string> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
http.get(`/api/client/servers/${server}/files/contents`, {
|
||||
params: { file },
|
||||
transformResponse: res => res,
|
||||
responseType: 'text',
|
||||
})
|
||||
.then(({ data }) => resolve(data))
|
||||
.catch(reject);
|
||||
});
|
||||
};
|
|
@ -1,9 +0,0 @@
|
|||
import http from '@/api/http';
|
||||
|
||||
export default (uuid: string, file: string): Promise<string> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
http.get(`/api/client/servers/${uuid}/files/download`, { params: { file } })
|
||||
.then(({ data }) => resolve(data.attributes.url))
|
||||
.catch(reject);
|
||||
});
|
||||
};
|
|
@ -1,9 +0,0 @@
|
|||
import http from '@/api/http';
|
||||
|
||||
export default (uuid: string): Promise<string> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
http.get(`/api/client/servers/${uuid}/files/upload`)
|
||||
.then(({ data }) => resolve(data.attributes.url))
|
||||
.catch(reject);
|
||||
});
|
||||
};
|
|
@ -1,25 +0,0 @@
|
|||
import http from '@/api/http';
|
||||
import { rawDataToFileObject } from '@/api/transformers';
|
||||
|
||||
export interface FileObject {
|
||||
key: string;
|
||||
name: string;
|
||||
mode: string;
|
||||
modeBits: string,
|
||||
size: number;
|
||||
isFile: boolean;
|
||||
isSymlink: boolean;
|
||||
mimetype: string;
|
||||
createdAt: Date;
|
||||
modifiedAt: Date;
|
||||
isArchiveType: () => boolean;
|
||||
isEditable: () => boolean;
|
||||
}
|
||||
|
||||
export default async (uuid: string, directory?: string): Promise<FileObject[]> => {
|
||||
const { data } = await http.get(`/api/client/servers/${uuid}/files/list`, {
|
||||
params: { directory: directory ?? '/' },
|
||||
});
|
||||
|
||||
return (data.data || []).map(rawDataToFileObject);
|
||||
};
|
|
@ -1,9 +0,0 @@
|
|||
import http from '@/api/http';
|
||||
|
||||
export default (uuid: string, directory: string, url: string): Promise<void> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
http.post(`/api/client/servers/${uuid}/files/pull`, { root: directory, url })
|
||||
.then(() => resolve())
|
||||
.catch(reject);
|
||||
});
|
||||
};
|
|
@ -1,14 +0,0 @@
|
|||
import http from '@/api/http';
|
||||
|
||||
interface Data {
|
||||
to: string;
|
||||
from: string;
|
||||
}
|
||||
|
||||
export default (uuid: string, directory: string, files: Data[]): Promise<void> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
http.put(`/api/client/servers/${uuid}/files/rename`, { root: directory, files })
|
||||
.then(() => resolve())
|
||||
.catch(reject);
|
||||
});
|
||||
};
|
|
@ -1,10 +0,0 @@
|
|||
import http from '@/api/http';
|
||||
|
||||
export default async (uuid: string, file: string, content: string): Promise<void> => {
|
||||
await http.post(`/api/client/servers/${uuid}/files/write`, content, {
|
||||
params: { file },
|
||||
headers: {
|
||||
'Content-Type': 'text/plain',
|
||||
},
|
||||
});
|
||||
};
|
|
@ -1,3 +0,0 @@
|
|||
import * as Models from '@definitions/user/models';
|
||||
|
||||
export type Allocation = Models.Allocation;
|
|
@ -3,7 +3,7 @@ import { ServerContext } from '@/state/server';
|
|||
import Modal from '@/components/elements/Modal';
|
||||
import tw from 'twin.macro';
|
||||
import Button from '@/components/elements/Button';
|
||||
import saveFileContents from '@/api/server/files/saveFileContents';
|
||||
import { saveFileContents } from '@/api/server/files';
|
||||
import FlashMessageRender from '@/components/FlashMessageRender';
|
||||
import useFlash from '@/plugins/useFlash';
|
||||
import { SocketEvent, SocketRequest } from '@/components/server/events';
|
||||
|
|
|
@ -4,7 +4,7 @@ import React from 'react';
|
|||
import Modal, { RequiredModalProps } from '@/components/elements/Modal';
|
||||
import { Form, Formik, FormikHelpers } from 'formik';
|
||||
import Field from '@/components/elements/Field';
|
||||
import chmodFiles from '@/api/server/files/chmodFiles';
|
||||
import { chmodFiles } from '@/api/server/files';
|
||||
import { ServerContext } from '@/state/server';
|
||||
import tw from 'twin.macro';
|
||||
import Button from '@/components/elements/Button';
|
||||
|
|
|
@ -1,22 +1,29 @@
|
|||
import React, { memo, useRef, useState } from 'react';
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
import { faBoxOpen, faCopy, faEllipsisH, faFileArchive, faFileCode, faFileDownload, faLevelUpAlt, faPencilAlt, faTrashAlt, IconDefinition } from '@fortawesome/free-solid-svg-icons';
|
||||
import {
|
||||
faBoxOpen,
|
||||
faCopy,
|
||||
faEllipsisH,
|
||||
faFileArchive,
|
||||
faFileCode,
|
||||
faFileDownload,
|
||||
faLevelUpAlt,
|
||||
faPencilAlt,
|
||||
faTrashAlt,
|
||||
IconDefinition,
|
||||
} from '@fortawesome/free-solid-svg-icons';
|
||||
import RenameFileModal from '@/components/server/files/RenameFileModal';
|
||||
import { ServerContext } from '@/state/server';
|
||||
import { join } from 'path';
|
||||
import deleteFiles from '@/api/server/files/deleteFiles';
|
||||
import { compressFiles, copyFiles, decompressFiles, deleteFiles, getFileDownloadUrl } from '@/api/server/files';
|
||||
import SpinnerOverlay from '@/components/elements/SpinnerOverlay';
|
||||
import copyFile from '@/api/server/files/copyFile';
|
||||
import Can from '@/components/elements/Can';
|
||||
import getFileDownloadUrl from '@/api/server/files/getFileDownloadUrl';
|
||||
import useFlash from '@/plugins/useFlash';
|
||||
import tw, { styled } from 'twin.macro';
|
||||
import { FileObject } from '@/api/server/files/loadDirectory';
|
||||
import useFileManagerSwr from '@/plugins/useFileManagerSwr';
|
||||
import DropdownMenu from '@/components/elements/DropdownMenu';
|
||||
import useEventListener from '@/plugins/useEventListener';
|
||||
import compressFiles from '@/api/server/files/compressFiles';
|
||||
import decompressFiles from '@/api/server/files/decompressFiles';
|
||||
import isEqual from 'react-fast-compare';
|
||||
import ConfirmationModal from '@/components/elements/ConfirmationModal';
|
||||
import ChmodFileModal from '@/components/server/files/ChmodFileModal';
|
||||
|
@ -75,7 +82,7 @@ const FileDropdownMenu = ({ file }: { file: FileObject }) => {
|
|||
setShowSpinner(true);
|
||||
clearFlashes('files');
|
||||
|
||||
copyFile(uuid, join(directory, file.name))
|
||||
copyFiles(uuid, join(directory, file.name))
|
||||
.then(async () => await mutate())
|
||||
.catch(error => clearAndAddHttpError({ key: 'files', error }))
|
||||
.then(() => setShowSpinner(false));
|
||||
|
|
|
@ -3,8 +3,7 @@ import { useHistory, useLocation, useParams } from 'react-router';
|
|||
import { dirname } from 'path';
|
||||
import tw from 'twin.macro';
|
||||
import { httpErrorToHuman } from '@/api/http';
|
||||
import getFileContents from '@/api/server/files/getFileContents';
|
||||
import saveFileContents from '@/api/server/files/saveFileContents';
|
||||
import { getFileContents, saveFileContents } from '@/api/server/files';
|
||||
import Can from '@/components/elements/Can';
|
||||
import Editor, { modes } from '@/components/elements/Editor';
|
||||
import ErrorBoundary from '@/components/elements/ErrorBoundary';
|
||||
|
|
|
@ -7,10 +7,9 @@ import { faFileArchive, faLevelUpAlt, faTrashAlt } from '@fortawesome/free-solid
|
|||
import SpinnerOverlay from '@/components/elements/SpinnerOverlay';
|
||||
import useFileManagerSwr from '@/plugins/useFileManagerSwr';
|
||||
import useFlash from '@/plugins/useFlash';
|
||||
import compressFiles from '@/api/server/files/compressFiles';
|
||||
import { compressFiles, deleteFiles } from '@/api/server/files';
|
||||
import { ServerContext } from '@/state/server';
|
||||
import ConfirmationModal from '@/components/elements/ConfirmationModal';
|
||||
import deleteFiles from '@/api/server/files/deleteFiles';
|
||||
import RenameFileModal from '@/components/server/files/RenameFileModal';
|
||||
|
||||
const MassActionsBar = () => {
|
||||
|
@ -79,10 +78,10 @@ const MassActionsBar = () => {
|
|||
Deleting the file(s) listed below is a permanent operation, you cannot undo this action.
|
||||
<br/>
|
||||
<code>
|
||||
{ selectedFiles.slice(0, 15).map(file => (
|
||||
{selectedFiles.slice(0, 15).map(file => (
|
||||
<li key={file}>{file}<br/></li>))
|
||||
}
|
||||
{ selectedFiles.length > 15 &&
|
||||
{selectedFiles.length > 15 &&
|
||||
<li> + {selectedFiles.length - 15} other(s) </li>
|
||||
}
|
||||
</code>
|
||||
|
|
|
@ -5,10 +5,9 @@ import { Form, Formik, FormikHelpers } from 'formik';
|
|||
import Field from '@/components/elements/Field';
|
||||
import { join } from 'path';
|
||||
import { object, string } from 'yup';
|
||||
import createDirectory from '@/api/server/files/createDirectory';
|
||||
import { createDirectory, FileObject } from '@/api/server/files';
|
||||
import tw from 'twin.macro';
|
||||
import Button from '@/components/elements/Button';
|
||||
import { FileObject } from '@/api/server/files/loadDirectory';
|
||||
import useFlash from '@/plugins/useFlash';
|
||||
import useFileManagerSwr from '@/plugins/useFileManagerSwr';
|
||||
import { WithClassname } from '@/components/types';
|
||||
|
|
|
@ -2,7 +2,7 @@ import { Form, Formik, FormikHelpers } from 'formik';
|
|||
import React, { useEffect, useState } from 'react';
|
||||
import tw from 'twin.macro';
|
||||
import { object, string } from 'yup';
|
||||
import pullFile from '@/api/server/files/pullFile';
|
||||
import { pullFile, FileObject } from '@/api/server/files';
|
||||
import { WithClassname } from '@/components/types';
|
||||
import Button from '@/components/elements/Button';
|
||||
import Field from '@/components/elements/Field';
|
||||
|
@ -10,7 +10,6 @@ import Modal from '@/components/elements/Modal';
|
|||
import useFileManagerSwr from '@/plugins/useFileManagerSwr';
|
||||
import useFlash from '@/plugins/useFlash';
|
||||
import { ServerContext } from '@/state/server';
|
||||
import { FileObject } from '@/api/server/files/loadDirectory';
|
||||
import FlashMessageRender from '@/components/FlashMessageRender';
|
||||
import { join } from 'path';
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ import Modal, { RequiredModalProps } from '@/components/elements/Modal';
|
|||
import { Form, Formik, FormikHelpers } from 'formik';
|
||||
import Field from '@/components/elements/Field';
|
||||
import { join } from 'path';
|
||||
import renameFiles from '@/api/server/files/renameFiles';
|
||||
import { renameFiles } from '@/api/server/files';
|
||||
import { ServerContext } from '@/state/server';
|
||||
import tw from 'twin.macro';
|
||||
import Button from '@/components/elements/Button';
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import axios from 'axios';
|
||||
import getFileUploadUrl from '@/api/server/files/getFileUploadUrl';
|
||||
import { getFileUploadUrl } from '@/api/server/files';
|
||||
import tw, { styled } from 'twin.macro';
|
||||
import Button from '@/components/elements/Button';
|
||||
import React, { useEffect, useRef, useState } from 'react';
|
||||
|
|
|
@ -8,9 +8,9 @@ import { Textarea } from '@/components/elements/Input';
|
|||
import Can from '@/components/elements/Can';
|
||||
import Button from '@/components/elements/Button';
|
||||
import GreyRowBox from '@/components/elements/GreyRowBox';
|
||||
import { Allocation } from '@/api/server/getServer';
|
||||
import { Allocation } from '@definitions/user';
|
||||
import { debounce } from 'debounce';
|
||||
import { setServerAllocationNotes, setPrimaryServerAllocation } from '@/api/server/network';
|
||||
import { setPrimaryServerAllocation, setServerAllocationNotes } from '@/api/server/network';
|
||||
import useFlash from '@/plugins/useFlash';
|
||||
import { ServerContext } from '@/state/server';
|
||||
import CopyOnClick from '@/components/elements/CopyOnClick';
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import useSWR from 'swr';
|
||||
import loadDirectory, { FileObject } from '@/api/server/files/loadDirectory';
|
||||
import { loadDirectory, FileObject } from '@/api/server/files';
|
||||
import { cleanDirectoryPath } from '@/helpers';
|
||||
import { ServerContext } from '@/state/server';
|
||||
|
||||
|
|
Loading…
Reference in a new issue