import {Button, Icon, Placeholder} from "./Theme"; import { Button as SButton, Checkbox, Confirm, Image, Modal, ModalActions, ModalContent, PlaceholderLine, TableCell, TableFooter, TableHeaderCell, TableRow } from "semantic-ui-react"; import {FileIcon, humanFileSize} from "./Common"; import React from "react"; import {deleteFile} from "../api"; import _ from 'lodash'; import {SortableTable} from "./SortableTable"; import {useBrowseFiles} from "../hooks/customHooks"; import {DirectoryRefreshButton, FilesRefreshButton} from "./Files"; function depthIndentation(path) { // Repeated spaces for every folder a path is in. const depth = (path.match(/\//g) || []).length; return '\xa0\xa0\xa0\xa0'.repeat(depth); } function Folder({folder, onFolderClick, sortData, selectedPath, onFileClick, onSelect}) { // Creates a single table row for a folder, or a row for itself and indented rows for its children. let {path, children} = folder; const pathWithNoTrailingSlash = path.substring(0, path.length - 1); const name = path.substring(pathWithNoTrailingSlash.lastIndexOf('/') + 1); const f = onSelect(folder['path'])}/> onFolderClick(path)} className='file-path'> {depthIndentation(pathWithNoTrailingSlash)} {name} ({folder['child_count']}) ; if (children && !_.isEmpty(children)) { // Folder has children, recursively display them. children = sortData(children); let childPaths = []; _.forEach(children, (p, k) => { childPaths = [...childPaths, ]; }); return {f} {childPaths} } else { // Folder has no children. return f; } } function File({file, onFileClick, selectedPath, onSelect}) { const {path, size} = file; const name = path.substring(path.lastIndexOf('/') + 1); return onSelect(path)}/> onFileClick(file)} className='file-path'> {depthIndentation(path)} {/*null size to make icon the correct size*/} {name} {humanFileSize(size)} } function Path({path, onFolderClick, onFileClick, sortData, selectedPath, onSelect}) { if (path['path'].endsWith('/')) { return } else { return } } export function FileBrowser() { const [selectedPath, setSelectedPath] = React.useState(null); const [deleteOpen, setDeleteOpen] = React.useState(false); const [fileSelected, setFileSelected] = React.useState(false); const [folderSelected, setFolderSelected] = React.useState(false); const {browseFiles, openFolders, setOpenFolders, fetchFiles} = useBrowseFiles(); const headers = [{key: 'select', text: ''}, { key: 'path', text: 'Path', sortBy: i => i['path'].toLowerCase() }, {key: 'size', text: 'Size', sortBy: 'size'},]; const [modal, setModal] = React.useState(null); const onFileClick = (path) => { const {mimetype} = path; const url = `/media/${path['path']}`; let modalBody; if (mimetype === 'text/plain' || mimetype === 'text/html') { modalBody =