diff --git a/app/Transformers/Daemon/FileObjectTransformer.php b/app/Transformers/Daemon/FileObjectTransformer.php index acaba0c43..84fcaf2d4 100644 --- a/app/Transformers/Daemon/FileObjectTransformer.php +++ b/app/Transformers/Daemon/FileObjectTransformer.php @@ -14,14 +14,6 @@ class FileObjectTransformer extends BaseDaemonTransformer */ private $editable = []; - /** - * FileObjectTransformer constructor. - */ - public function __construct() - { - $this->editable = config('pterodactyl.files.editable', []); - } - /** * Transform a file object response from the daemon into a standardized response. * @@ -36,8 +28,7 @@ class FileObjectTransformer extends BaseDaemonTransformer 'size' => Arr::get($item, 'size'), 'is_file' => Arr::get($item, 'file', true), 'is_symlink' => Arr::get($item, 'symlink', false), - 'is_editable' => in_array(Arr::get($item, 'mime', ''), $this->editable), - 'mimetype' => Arr::get($item, 'mime'), + 'mimetype' => Arr::get($item, 'mime', 'application/octet-stream'), 'created_at' => Carbon::parse(Arr::get($item, 'created', ''))->toIso8601String(), 'modified_at' => Carbon::parse(Arr::get($item, 'modified', ''))->toIso8601String(), ]; diff --git a/config/pterodactyl.php b/config/pterodactyl.php index 671a64fd3..75ece65b2 100644 --- a/config/pterodactyl.php +++ b/config/pterodactyl.php @@ -178,20 +178,6 @@ return [ */ 'files' => [ 'max_edit_size' => env('PTERODACTYL_FILES_MAX_EDIT_SIZE', 1024 * 1024 * 4), - 'editable' => [ - 'application/json', - 'application/javascript', - 'application/xml', - 'application/xhtml+xml', - 'inode/x-empty', - 'text/xml', - 'text/css', - 'text/html', - 'text/plain', - 'text/x-perl', - 'text/x-shellscript', - 'text/x-python', - ], ], /* diff --git a/resources/scripts/api/server/files/loadDirectory.ts b/resources/scripts/api/server/files/loadDirectory.ts index 77e44bce8..1caf6bf9d 100644 --- a/resources/scripts/api/server/files/loadDirectory.ts +++ b/resources/scripts/api/server/files/loadDirectory.ts @@ -8,11 +8,11 @@ export interface FileObject { size: number; isFile: boolean; isSymlink: boolean; - isEditable: boolean; mimetype: string; createdAt: Date; modifiedAt: Date; isArchiveType: () => boolean; + isEditable: () => boolean; } export default async (uuid: string, directory?: string): Promise => { diff --git a/resources/scripts/api/transformers.ts b/resources/scripts/api/transformers.ts index 595f2b9c8..f17787e03 100644 --- a/resources/scripts/api/transformers.ts +++ b/resources/scripts/api/transformers.ts @@ -19,7 +19,6 @@ export const rawDataToFileObject = (data: FractalResponseData): FileObject => ({ size: Number(data.attributes.size), isFile: data.attributes.is_file, isSymlink: data.attributes.is_symlink, - isEditable: data.attributes.is_editable, mimetype: data.attributes.mimetype, createdAt: new Date(data.attributes.created_at), modifiedAt: new Date(data.attributes.modified_at), @@ -39,6 +38,19 @@ export const rawDataToFileObject = (data: FractalResponseData): FileObject => ({ 'application/zip', // .zip ].indexOf(this.mimetype) >= 0; }, + + isEditable: function () { + if (this.isArchiveType() || !this.isFile) return false; + + const matches = [ + 'application/jar', + 'application/octet-stream', + 'inode/directory', + /^image\//, + ]; + + return matches.every(m => !this.mimetype.match(m)); + }, }); export const rawDataToServerBackup = ({ attributes }: FractalResponseData): ServerBackup => ({ diff --git a/resources/scripts/components/server/files/FileObjectRow.tsx b/resources/scripts/components/server/files/FileObjectRow.tsx index 0a14aca8c..bb8935744 100644 --- a/resources/scripts/components/server/files/FileObjectRow.tsx +++ b/resources/scripts/components/server/files/FileObjectRow.tsx @@ -16,7 +16,7 @@ const Row = styled.div` ${tw`flex bg-neutral-700 rounded-sm mb-px text-sm hover:text-neutral-100 cursor-pointer items-center no-underline hover:bg-neutral-600`}; `; -const FileObjectRow = ({ file }: { file: FileObject }) => { +const Clickable: React.FC<{ file: FileObject }> = memo(({ file, children }) => { const directory = ServerContext.useStoreState(state => state.files.directory); const history = useHistory(); @@ -35,48 +35,59 @@ const FileObjectRow = ({ file }: { file: FileObject }) => { }; return ( - { - e.preventDefault(); - window.dispatchEvent(new CustomEvent(`pterodactyl:files:ctx:${file.key}`, { detail: e.clientX })); - }} - > - + file.isFile && !file.isEditable() ? +
+ {children} +
+ : -
- {file.isFile ? - - : - - } -
-
- {file.name} -
- {file.isFile && -
- {bytesToHuman(file.size)} -
- } -
- {Math.abs(differenceInHours(file.modifiedAt, new Date())) > 48 ? - format(file.modifiedAt, 'MMM do, yyyy h:mma') - : - formatDistanceToNow(file.modifiedAt, { addSuffix: true }) - } -
+ {children}
- -
); -}; +}, isEqual); -export default memo(FileObjectRow, (prevProps, nextProps) => isEqual(prevProps.file, nextProps.file)); +const FileObjectRow = ({ file }: { file: FileObject }) => ( + { + e.preventDefault(); + window.dispatchEvent(new CustomEvent(`pterodactyl:files:ctx:${file.key}`, { detail: e.clientX })); + }} + > + + +
+ {file.isFile ? + + : + + } +
+
+ {file.name} +
+ {file.isFile && +
+ {bytesToHuman(file.size)} +
+ } +
+ {Math.abs(differenceInHours(file.modifiedAt, new Date())) > 48 ? + format(file.modifiedAt, 'MMM do, yyyy h:mma') + : + formatDistanceToNow(file.modifiedAt, { addSuffix: true }) + } +
+
+ +
+); + +export default memo(FileObjectRow, isEqual); diff --git a/resources/scripts/components/server/files/NewDirectoryButton.tsx b/resources/scripts/components/server/files/NewDirectoryButton.tsx index 709fdd5e6..8cb82dd9b 100644 --- a/resources/scripts/components/server/files/NewDirectoryButton.tsx +++ b/resources/scripts/components/server/files/NewDirectoryButton.tsx @@ -26,12 +26,12 @@ const generateDirectoryData = (name: string): FileObject => ({ mode: '0644', size: 0, isFile: false, - isEditable: false, isSymlink: false, mimetype: '', createdAt: new Date(), modifiedAt: new Date(), isArchiveType: () => false, + isEditable: () => false, }); export default () => {