From 3a4607d297b9ddabaca32470d4c58ec2918effd1 Mon Sep 17 00:00:00 2001 From: inalone Date: Fri, 11 Nov 2022 17:32:26 +0000 Subject: Add 'get full directory' to FileList This commit adds a new {username}/directory/{directory} endpoint which returns the contents of a given directory from a user. This has been implemented in the frontend by adding a "Get Full Directory" button to FileList, which is rendered if a "getFullDirectory" function is passed a as a prop. This is not needed in Browse, so this is currently just added to the search. --- src/slskd/Users/API/Controllers/UsersController.cs | 23 +++++++++ src/web/src/components/App.css | 5 ++ src/web/src/components/Search/Response.js | 10 ++++ src/web/src/components/Shared/FileList.js | 58 ++++++++++++++-------- src/web/src/lib/users.js | 4 ++ 5 files changed, 79 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/slskd/Users/API/Controllers/UsersController.cs b/src/slskd/Users/API/Controllers/UsersController.cs index 0f06a677..6ef9fc3e 100644 --- a/src/slskd/Users/API/Controllers/UsersController.cs +++ b/src/slskd/Users/API/Controllers/UsersController.cs @@ -123,6 +123,29 @@ namespace slskd.Users.API return NotFound(); } + /// + /// Retrieves the files from the specified from the specified . + /// + /// The desired directory. + /// The username of the user. + /// + [HttpGet("{username}/directory/{directory}")] + [Authorize(Policy = AuthPolicy.Any)] + [ProducesResponseType(typeof(IEnumerable), 200)] + [ProducesResponseType(404)] + public async Task Directory([FromRoute, Required] string username, [FromRoute, Required] string directory) + { + try + { + var result = await Client.GetDirectoryContentsAsync(username, directory); + return Ok(result); + } + catch (UserOfflineException ex) + { + return NotFound(ex.Message); + } + } + /// /// Retrieves information about the specified . /// diff --git a/src/web/src/components/App.css b/src/web/src/components/App.css index 78b029b8..e5862c75 100644 --- a/src/web/src/components/App.css +++ b/src/web/src/components/App.css @@ -80,6 +80,11 @@ body { width: 65px; } +.getfulldirectory-button { + padding: 10px !important; + margin-left: 5px !important; +} + .showmore-button { padding: 20px !important; max-width: 1200px !important; diff --git a/src/web/src/components/Search/Response.js b/src/web/src/components/Search/Response.js index 6493393f..f8228106 100644 --- a/src/web/src/components/Search/Response.js +++ b/src/web/src/components/Search/Response.js @@ -11,6 +11,7 @@ import { Icon, Label, } from 'semantic-ui-react'; +import { getDirectoryContents } from '../../lib/users'; const buildTree = (response) => { let { files = [], lockedFiles = [] } = response; @@ -59,6 +60,13 @@ class Response extends Component { }); }; + getFullDirectory = async (username, directory) => { + const directoryContents = await getDirectoryContents({ username, directory }); + const newTree = this.state.tree; + newTree[directoryContents.name] = directoryContents.files; + this.setState({ tree: { ...newTree } }); + }; + toggleFolded = () => { this.setState({ isFolded: !this.state.isFolded }); }; @@ -107,6 +115,8 @@ class Response extends Component { files={tree[dir]} disabled={downloadRequest === 'inProgress'} onSelectionChange={this.onFileSelectionChange} + getFullDirectory={this.getFullDirectory} + username={response.username} /> )} diff --git a/src/web/src/components/Shared/FileList.js b/src/web/src/components/Shared/FileList.js index 9d19b886..bcbebee9 100644 --- a/src/web/src/components/Shared/FileList.js +++ b/src/web/src/components/Shared/FileList.js @@ -1,36 +1,52 @@ -import React, {useState} from 'react'; +import React, { useState } from 'react'; import { formatSeconds, formatBytes, getFileName, formatAttributes } from '../../lib/util'; -import { - Header, - Table, - Icon, - List, +import { + Button, + Header, + Table, + Icon, + List, Checkbox, } from 'semantic-ui-react'; -const FileList = ({ directoryName, files, locked, onSelectionChange, disabled, onClose }) => { +const FileList = ({ + directoryName, + files, + locked, + onSelectionChange, + disabled, + onClose, + getFullDirectory, + username, +}) => { const [folded, setFolded] = useState(false); return ( -
-
+
- !locked && setFolded(!folded)}/> {directoryName} - - {!!onClose && getFullDirectory(username, directoryName)} + className="getfulldirectory-button">Get Full Directory + } + + {!!onClose && onClose()} @@ -43,7 +59,7 @@ const FileList = ({ directoryName, files, locked, onSelectionChange, disabled, o - files.map(f => onSelectionChange(f, data.checked))} checked={files.filter(f => !f.selected).length === 0} @@ -57,11 +73,11 @@ const FileList = ({ directoryName, files, locked, onSelectionChange, disabled, o - {files.sort((a, b) => a.filename > b.filename ? 1 : -1).map((f, i) => + {files.sort((a, b) => a.filename > b.filename ? 1 : -1).map((f, i) => - onSelectionChange(f, data.checked)} checked={f.selected} disabled={disabled} diff --git a/src/web/src/lib/users.js b/src/web/src/lib/users.js index f79cea20..9107a0ca 100644 --- a/src/web/src/lib/users.js +++ b/src/web/src/lib/users.js @@ -18,4 +18,8 @@ export const browse = async ({ username }) => { export const getBrowseStatus = ({ username }) => { return api.get(`/users/${encodeURIComponent(username)}/browse/status`); +}; + +export const getDirectoryContents = async ({ username, directory }) => { + return (await api.get(`/users/${encodeURIComponent(username)}/directory/${encodeURIComponent(directory)}`)).data; }; \ No newline at end of file -- cgit v1.2.3