From e629106b6ff136910422e857466714ceb420f841 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 27 Jun 2023 09:07:24 -0500 Subject: stub files tab --- src/web/src/components/System/Files/index.js | 12 ++++++++++++ src/web/src/components/System/System.css | 4 ++++ src/web/src/components/System/System.js | 12 +++++++++++- 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 src/web/src/components/System/Files/index.js (limited to 'src') diff --git a/src/web/src/components/System/Files/index.js b/src/web/src/components/System/Files/index.js new file mode 100644 index 00000000..b51315d1 --- /dev/null +++ b/src/web/src/components/System/Files/index.js @@ -0,0 +1,12 @@ +import React from 'react'; +import { Header } from 'semantic-ui-react'; + +const Files = () => { + return ( +
+
Files
+
+ ); +}; + +export default Files; \ No newline at end of file diff --git a/src/web/src/components/System/System.css b/src/web/src/components/System/System.css index dc32d583..80642687 100644 --- a/src/web/src/components/System/System.css +++ b/src/web/src/components/System/System.css @@ -71,4 +71,8 @@ .transfer-header { margin-bottom: -15px !important; +} + +.file-management-header { + margin-bottom: -15px !important; } \ No newline at end of file diff --git a/src/web/src/components/System/System.js b/src/web/src/components/System/System.js index df77ded2..865a5743 100644 --- a/src/web/src/components/System/System.js +++ b/src/web/src/components/System/System.js @@ -5,11 +5,12 @@ import { Segment, Tab, Menu, Icon } from 'semantic-ui-react'; import './System.css'; +import { Switch } from '../Shared'; import Info from './Info'; import Logs from './Logs'; import Options from './Options'; import Shares from './Shares'; -import { Switch } from '../Shared'; +import Files from './Files'; import Data from './Data'; const System = ({ state = {}, theme, options = {} }) => { @@ -51,6 +52,15 @@ const System = ({ state = {}, theme, options = {} }) => { ), render: () => , }, + { + route: 'files', + menuItem: { + key: 'files', + icon: 'folder open', + content: 'Files' + }, + render: () => + }, { route: 'data', menuItem: { -- cgit v1.2.3 From 86f9197b6713483b2daec2378695ed863cf62912 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Thu, 29 Jun 2023 09:47:34 -0500 Subject: add trailing commas --- src/web/src/components/System/System.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/web/src/components/System/System.js b/src/web/src/components/System/System.js index 865a5743..3629082e 100644 --- a/src/web/src/components/System/System.js +++ b/src/web/src/components/System/System.js @@ -57,9 +57,9 @@ const System = ({ state = {}, theme, options = {} }) => { menuItem: { key: 'files', icon: 'folder open', - content: 'Files' + content: 'Files', }, - render: () => + render: () => , }, { route: 'data', -- cgit v1.2.3 From 5bc462d774633c40dd9ae5efd35cfca2cf71f0ef Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Thu, 29 Jun 2023 09:47:42 -0500 Subject: add tabs --- src/web/src/components/System/Files/index.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/web/src/components/System/Files/index.js b/src/web/src/components/System/Files/index.js index b51315d1..881d1246 100644 --- a/src/web/src/components/System/Files/index.js +++ b/src/web/src/components/System/Files/index.js @@ -1,10 +1,23 @@ import React from 'react'; -import { Header } from 'semantic-ui-react'; +import { Tab } from 'semantic-ui-react'; + +const panes = [ + { + route: 'downloads', + menuItem: 'Downloads', + render: () => Downloads, + }, + { + route: 'incomplete', + menuItem: 'Incomplete', + render: () => Incomplete, + }, +]; const Files = () => { return (
-
Files
+
); }; -- cgit v1.2.3 From 26786311ffc3a01bdd15158fe0c03bb58d8391ec Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Fri, 30 Jun 2023 09:43:11 -0500 Subject: include subdirectories in directory body, return only one --- src/slskd/Files/API/FilesController.cs | 8 ++++---- src/slskd/Files/FileService.cs | 20 +++++++++++++------- src/slskd/Files/IFileService.cs | 2 +- src/slskd/Files/Types/FilesystemDirectory.cs | 1 + 4 files changed, 19 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/slskd/Files/API/FilesController.cs b/src/slskd/Files/API/FilesController.cs index 08895639..f4b3ce87 100644 --- a/src/slskd/Files/API/FilesController.cs +++ b/src/slskd/Files/API/FilesController.cs @@ -50,7 +50,7 @@ namespace slskd.Files.API [HttpGet("downloads/directories")] [Authorize(Policy = AuthPolicy.Any)] - [ProducesResponseType(typeof(IEnumerable), 200)] + [ProducesResponseType(typeof(FilesystemDirectory), 200)] public async Task GetDownloadContentsAsync([FromQuery] bool recursive = false) { try @@ -77,7 +77,7 @@ namespace slskd.Files.API [HttpGet("downloads/directories/{base64SubdirectoryName}")] [Authorize(Policy = AuthPolicy.Any)] - [ProducesResponseType(typeof(IEnumerable), 200)] + [ProducesResponseType(typeof(FilesystemDirectory), 200)] public async Task GetDownloadSubdirectoryContentsAsync([FromRoute] string base64SubdirectoryName, [FromQuery] bool recursive = false) { var decodedDir = base64SubdirectoryName.FromBase64(); @@ -167,7 +167,7 @@ namespace slskd.Files.API [HttpGet("incomplete/directories")] [Authorize(Policy = AuthPolicy.Any)] - [ProducesResponseType(typeof(IEnumerable), 200)] + [ProducesResponseType(typeof(FilesystemDirectory), 200)] public async Task GetIncompleteContentsAsync([FromQuery] bool recursive = false) { try @@ -194,7 +194,7 @@ namespace slskd.Files.API [HttpGet("incomplete/directories/{base64SubdirectoryName}")] [Authorize(Policy = AuthPolicy.Any)] - [ProducesResponseType(typeof(IEnumerable), 200)] + [ProducesResponseType(typeof(FilesystemDirectory), 200)] public async Task GetIncompleteSubdirectoryContentsAsync([FromRoute, Required] string base64SubdirectoryName, [FromQuery] bool recursive = false) { var decodedDir = base64SubdirectoryName.FromBase64(); diff --git a/src/slskd/Files/FileService.cs b/src/slskd/Files/FileService.cs index f37c861b..1dfcb715 100644 --- a/src/slskd/Files/FileService.cs +++ b/src/slskd/Files/FileService.cs @@ -146,7 +146,7 @@ namespace slskd.Files /// The list of found contents. /// Thrown if the specified directory does not exist. /// Thrown if the specified directory is restricted. - public async Task> ListContentsAsync(string rootDirectory, string parentDirectory = null, EnumerationOptions enumerationOptions = null) + public async Task ListContentsAsync(string rootDirectory, string parentDirectory = null, EnumerationOptions enumerationOptions = null) { if (!AllowedDirectories.Any(d => rootDirectory == d)) { @@ -168,20 +168,26 @@ namespace slskd.Files var files = contents .OfType() - .Select(f => FilesystemFile.FromFileInfo(f)); + .Select(f => FilesystemFile.FromFileInfo(f) with + { + FullName = f.FullName.ReplaceFirst(rootDirectory, string.Empty).TrimStart('\\', '/'), + }); var dirs = contents .OfType() - .Prepend(dir) .Select(d => FilesystemDirectory.FromDirectoryInfo(d) with { FullName = d.FullName.ReplaceFirst(rootDirectory, string.Empty).TrimStart('\\', '/'), - Files = files - .Where(f => Path.GetDirectoryName(f.FullName) == d.FullName) - .Select(f => f with { FullName = f.FullName.ReplaceFirst(rootDirectory, string.Empty).TrimStart('\\', '/') }), }); - return dirs; + var response = FilesystemDirectory.FromDirectoryInfo(dir) with + { + FullName = dir.FullName.ReplaceFirst(rootDirectory, string.Empty).TrimStart('\\', '/'), + Files = files, + Directories = dirs, + }; + + return response; }); } } diff --git a/src/slskd/Files/IFileService.cs b/src/slskd/Files/IFileService.cs index 8e3ddcb7..2d4d66f5 100644 --- a/src/slskd/Files/IFileService.cs +++ b/src/slskd/Files/IFileService.cs @@ -65,6 +65,6 @@ namespace slskd.Files /// The list of found contents. /// Thrown if the specified directory does not exist. /// Thrown if the specified root directory is restricted. - Task> ListContentsAsync(string rootDirectory, string parentDirectory = null, EnumerationOptions enumerationOptions = null); + Task ListContentsAsync(string rootDirectory, string parentDirectory = null, EnumerationOptions enumerationOptions = null); } } \ No newline at end of file diff --git a/src/slskd/Files/Types/FilesystemDirectory.cs b/src/slskd/Files/Types/FilesystemDirectory.cs index 4183c724..9e573906 100644 --- a/src/slskd/Files/Types/FilesystemDirectory.cs +++ b/src/slskd/Files/Types/FilesystemDirectory.cs @@ -29,6 +29,7 @@ namespace slskd.Files public DateTime CreatedAt { get; init; } public DateTime ModifiedAt { get; init; } public IEnumerable Files { get; init; } + public IEnumerable Directories { get; init; } public static FilesystemDirectory FromDirectoryInfo(DirectoryInfo i) { -- cgit v1.2.3 From 686b2aa091aab7f4ec185aa03901e37c553ea1f6 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Fri, 30 Jun 2023 09:43:48 -0500 Subject: adjust logging --- src/slskd/Application.cs | 2 ++ src/slskd/Program.cs | 3 +++ 2 files changed, 5 insertions(+) (limited to 'src') diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs index 48406931..32eb6cb7 100644 --- a/src/slskd/Application.cs +++ b/src/slskd/Application.cs @@ -280,6 +280,8 @@ namespace slskd async Task IHostedService.StartAsync(CancellationToken cancellationToken) { + Log.Information("Application started"); + // if the application shut down "uncleanly", transfers may need to be cleaned up. we deliberately don't allow these // records to be updated if the application has started to shut down so that we can do this cleanup and properly // disposition them as having failed due to an application shutdown, instead of some random exception thrown while diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index 060284d8..418a29c2 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -397,6 +397,8 @@ namespace slskd Log.Information("Invocation ID: {InvocationId}", InvocationId); Log.Information("Instance Name: {InstanceName}", OptionsAtStartup.InstanceName); + Log.Information("Configuring application..."); + // SQLite must have specific capabilities to function properly. this shouldn't be a concern for shrinkwrapped // binaries or in Docker, but if someone builds from source weird things can happen. InitSQLiteOrFailFast(); @@ -465,6 +467,7 @@ namespace slskd return; } + Log.Information("Configuration complete. Starting application..."); app.Run(); } catch (Exception ex) -- cgit v1.2.3 From 2b5c0ab129c6ecad6509edf083e90a578a4d1160 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Fri, 30 Jun 2023 09:58:47 -0500 Subject: rough in file display --- src/web/src/components/System/Files/Explorer.js | 33 +++++++++++++++++++++++++ src/web/src/components/System/Files/index.js | 30 ++++++++++++---------- src/web/src/lib/files.js | 8 ++++++ 3 files changed, 58 insertions(+), 13 deletions(-) create mode 100644 src/web/src/components/System/Files/Explorer.js create mode 100644 src/web/src/lib/files.js (limited to 'src') diff --git a/src/web/src/components/System/Files/Explorer.js b/src/web/src/components/System/Files/Explorer.js new file mode 100644 index 00000000..6abbe5c6 --- /dev/null +++ b/src/web/src/components/System/Files/Explorer.js @@ -0,0 +1,33 @@ +import React, { useState, useEffect } from 'react'; + +import { list } from '../../../lib/files'; + +const Explorer = ({ root }) => { + const [directory, setDirectory] = useState({ files: [], directories: [] }); + const [subdirectory, setSubdirectory] = useState([]); + + useEffect(() => { + console.log('fetching...', subdirectory); + const fetch = async () => { + const dir = await list({ root, subdirectory: subdirectory.join('/') }); + setDirectory(dir); + }; + + fetch(); + }, [subdirectory]); + + const select = ({ path }) => { + setSubdirectory([...subdirectory, path]); + }; + + return ( +
+ {directory?.directories?.map(d =>
+ select({ path: d.name })}> + {d.name} +
)} +
+ ); +}; + +export default Explorer; \ No newline at end of file diff --git a/src/web/src/components/System/Files/index.js b/src/web/src/components/System/Files/index.js index 881d1246..b5ab465b 100644 --- a/src/web/src/components/System/Files/index.js +++ b/src/web/src/components/System/Files/index.js @@ -1,23 +1,27 @@ import React from 'react'; import { Tab } from 'semantic-ui-react'; -const panes = [ - { - route: 'downloads', - menuItem: 'Downloads', - render: () => Downloads, - }, - { - route: 'incomplete', - menuItem: 'Incomplete', - render: () => Incomplete, - }, -]; +import Explorer from './Explorer'; const Files = () => { + const panes = [ + { + route: 'downloads', + menuItem: 'Downloads', + render: () => , + }, + { + route: 'incomplete', + menuItem: 'Incomplete', + render: () => , + }, + ]; + return (
- +
); }; diff --git a/src/web/src/lib/files.js b/src/web/src/lib/files.js new file mode 100644 index 00000000..9c147d61 --- /dev/null +++ b/src/web/src/lib/files.js @@ -0,0 +1,8 @@ +import api from './api'; + +export const list = async ({ root, subdirectory = '' }) => { + subdirectory = btoa(subdirectory); + const response = (await api.get(`/files/${root}/directories/${subdirectory}`)).data; + + return response; +}; \ No newline at end of file -- cgit v1.2.3 From c310a97b6372c9908757be532da5aba0a8a5e196 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 1 Jul 2023 15:11:35 -0500 Subject: refactor file service to prevent relative navigation --- src/slskd/Files/FileService.cs | 143 ++++++++++++++++++++++++++-------------- src/slskd/Files/IFileService.cs | 26 ++++---- 2 files changed, 110 insertions(+), 59 deletions(-) (limited to 'src') diff --git a/src/slskd/Files/FileService.cs b/src/slskd/Files/FileService.cs index 1dfcb715..2324a492 100644 --- a/src/slskd/Files/FileService.cs +++ b/src/slskd/Files/FileService.cs @@ -23,8 +23,10 @@ namespace slskd.Files using System.Collections.Generic; using System.IO; using System.Linq; + using System.Security; using System.Threading.Tasks; using OneOf; + using Serilog; /// /// Manages files on disk. @@ -40,7 +42,13 @@ namespace slskd.Files OptionsSnapshot = optionsSnapshot; } - private IEnumerable AllowedDirectories => new[] { OptionsSnapshot.Value.Directories.Downloads, OptionsSnapshot.Value.Directories.Incomplete }; + private IEnumerable AllowedDirectories => new[] + { + Path.GetFullPath(OptionsSnapshot.Value.Directories.Downloads), + Path.GetFullPath(OptionsSnapshot.Value.Directories.Incomplete), + }; + + private ILogger Log { get; } = Serilog.Log.ForContext(); private IOptionsSnapshot OptionsSnapshot { get; } /// @@ -50,16 +58,33 @@ namespace slskd.Files /// Returns a dictionary keyed on directory name and containing a result for each specified directory. Exceptions are /// contained in the result, and are not thrown. /// - /// The root directory. /// The directories to delete. /// The operation context. + /// Thrown if any of the specified directories have a relative path. + /// + /// Thrown if any of the directories is an exact match for an application-controlled directory. + /// /// Thrown if a specified directory does not exist. - /// Thrown if a specified directory is restricted. - public async Task>> DeleteDirectoriesAsync(string rootDirectory, params string[] directories) + /// Thrown if a specified directory is restricted. + public async Task>> DeleteDirectoriesAsync(params string[] directories) { - if (!AllowedDirectories.Any(d => rootDirectory == d)) + if (directories.Any(directory => Path.GetFullPath(directory) != directory)) { - throw new ForbiddenException($"For security reasons, only application-controlled directories can be deleted"); + throw new ArgumentException("Only absolute paths may be specified", nameof(directories)); + } + + if (directories.Any(directory => AllowedDirectories.Contains(directory))) + { + throw new ArgumentException("Deletion of application-controlled directory roots is not supported"); + } + + // important! we must fully expand the given paths with GetFullPath() to resolve a given relative directory, like '..' + bool IsAllowed(string path) => AllowedDirectories.Any(allowed => path.StartsWith(allowed)); + + // if any of the resolved directory paths aren't rooted in one of the allowed directories, forbid the entire request + if (!directories.All(directory => IsAllowed(directory))) + { + throw new SecurityException("Only application-controlled directories can be deleted"); } await Task.Yield(); @@ -70,16 +95,18 @@ namespace slskd.Files { try { - Directory.Delete(Path.Combine(rootDirectory, directory), recursive: true); + Directory.Delete(directory, recursive: true); results.Add(directory, true); + + Log.Information("Deleted directory '{Directory}'", directory); } - catch (FileNotFoundException) + catch (DirectoryNotFoundException) { results.Add(directory, new NotFoundException($"The directory '{directory}' does not exist")); } catch (UnauthorizedAccessException) { - results.Add(directory, new ForbiddenException()); + results.Add(directory, new SecurityException()); } catch (Exception ex) { @@ -97,16 +124,25 @@ namespace slskd.Files /// Returns a dictionary keyed on directory name and containing a result for each specified directory. Exceptions are /// contained in the result, and are not thrown. /// - /// The root directory. /// The list of files to delete. /// The operation context. + /// Thrown if any of the specified files have a relative path. /// Thrown if a specified file does not exist. - /// Thrown if a specified file is restricted. - public async Task>> DeleteFilesAsync(string rootDirectory, params string[] files) + /// Thrown if a specified file is restricted. + public async Task>> DeleteFilesAsync(params string[] files) { - if (!AllowedDirectories.Any(d => rootDirectory == d)) + if (files.Any(file => Path.GetFullPath(file) != file)) { - throw new ForbiddenException($"For security reasons, only application-controlled directories can be deleted"); + throw new ArgumentException("Only absolute paths may be specified", nameof(files)); + } + + // important! we must fully expand the given paths with GetFullPath() to resolve a given relative directory, like '..' + bool IsAllowed(string path) => AllowedDirectories.Any(allowed => path.StartsWith(allowed)); + + // if any of the resolved file paths aren't rooted in one of the allowed directories, forbid the entire request + if (!files.All(file => IsAllowed(file))) + { + throw new SecurityException("Only files in application-controlled directories can be deleted"); } await Task.Yield(); @@ -117,7 +153,7 @@ namespace slskd.Files { try { - File.Delete(Path.Combine(rootDirectory, file)); + File.Delete(file); results.Add(file, true); } catch (FileNotFoundException) @@ -126,7 +162,7 @@ namespace slskd.Files } catch (UnauthorizedAccessException) { - results.Add(file, new ForbiddenException()); + results.Add(file, new SecurityException()); } catch (Exception ex) { @@ -138,56 +174,67 @@ namespace slskd.Files } /// - /// Lists the contents in the specified , optionally applying the specified . + /// Lists the contents in the specified , optionally applying the specified . /// - /// The root directory. - /// An optional subdirectory from which to start the listing. + /// The directory from which to start the listing. /// Optional enumeration options to apply. /// The list of found contents. + /// Thrown if the specified directory has a relative path. /// Thrown if the specified directory does not exist. - /// Thrown if the specified directory is restricted. - public async Task ListContentsAsync(string rootDirectory, string parentDirectory = null, EnumerationOptions enumerationOptions = null) + /// Thrown if the specified root directory is restricted. + public async Task ListContentsAsync(string directory, EnumerationOptions enumerationOptions = null) { - if (!AllowedDirectories.Any(d => rootDirectory == d)) + if (Path.GetFullPath(directory) != directory) { - throw new ForbiddenException($"For security reasons, only application-controlled directories can be deleted"); + throw new ArgumentException("Only absolute paths may be specified", nameof(directory)); } - var fullDirectory = parentDirectory is not null ? Path.Combine(rootDirectory, parentDirectory) : rootDirectory; + // important! we must fully expand the path with GetFullPath() to resolve a given relative directory, like '..' + if (!AllowedDirectories.Any(allowed => directory.StartsWith(allowed))) + { + throw new SecurityException($"For security reasons, only application-controlled directories can be deleted"); + } - if (!Directory.Exists(fullDirectory)) + if (!Directory.Exists(directory)) { - throw new NotFoundException($"The directory '{fullDirectory}' does not exist"); + throw new NotFoundException($"The directory '{directory}' does not exist"); } return await Task.Run(() => { - var dir = new DirectoryInfo(fullDirectory); - - var contents = dir.GetFileSystemInfos("*", enumerationOptions); - - var files = contents - .OfType() - .Select(f => FilesystemFile.FromFileInfo(f) with - { - FullName = f.FullName.ReplaceFirst(rootDirectory, string.Empty).TrimStart('\\', '/'), - }); + var dir = new DirectoryInfo(directory); - var dirs = contents - .OfType() - .Select(d => FilesystemDirectory.FromDirectoryInfo(d) with + try + { + var contents = dir.GetFileSystemInfos("*", enumerationOptions); + + var files = contents + .OfType() + .Select(f => FilesystemFile.FromFileInfo(f) with + { + FullName = f.FullName.ReplaceFirst(directory, string.Empty).TrimStart('\\', '/'), + }); + + var dirs = contents + .OfType() + .Select(d => FilesystemDirectory.FromDirectoryInfo(d) with + { + FullName = d.FullName.ReplaceFirst(directory, string.Empty).TrimStart('\\', '/'), + }); + + var response = FilesystemDirectory.FromDirectoryInfo(dir) with { - FullName = d.FullName.ReplaceFirst(rootDirectory, string.Empty).TrimStart('\\', '/'), - }); + FullName = dir.FullName.ReplaceFirst(directory, string.Empty).TrimStart('\\', '/'), + Files = files, + Directories = dirs, + }; - var response = FilesystemDirectory.FromDirectoryInfo(dir) with + return response; + } + catch (UnauthorizedAccessException ex) { - FullName = dir.FullName.ReplaceFirst(rootDirectory, string.Empty).TrimStart('\\', '/'), - Files = files, - Directories = dirs, - }; - - return response; + throw new SecurityException($"Access to '{directory}' was denied", ex); + } }); } } diff --git a/src/slskd/Files/IFileService.cs b/src/slskd/Files/IFileService.cs index 2d4d66f5..63b5f1a3 100644 --- a/src/slskd/Files/IFileService.cs +++ b/src/slskd/Files/IFileService.cs @@ -20,6 +20,7 @@ namespace slskd.Files using System; using System.Collections.Generic; using System.IO; + using System.Security; using System.Threading.Tasks; using OneOf; @@ -35,12 +36,15 @@ namespace slskd.Files /// Returns a dictionary keyed on directory name and containing a result for each specified directory. Exceptions are /// contained in the result, and are not thrown. /// - /// The root directory. /// The directories to delete. /// The operation context. + /// Thrown if any of the specified directories have a relative path. + /// + /// Thrown if any of the directories is an exact match for an application-controlled directory. + /// /// Thrown if a specified directory does not exist. - /// Thrown if a specified directory is restricted. - Task>> DeleteDirectoriesAsync(string rootDirectory, params string[] directories); + /// Thrown if a specified directory is restricted. + Task>> DeleteDirectoriesAsync(params string[] directories); /// /// Deletes the specified . @@ -49,22 +53,22 @@ namespace slskd.Files /// Returns a dictionary keyed on directory name and containing a result for each specified directory. Exceptions are /// contained in the result, and are not thrown. /// - /// The root directory. /// The list of files to delete. /// The operation context. + /// Thrown if any of the specified files have a relative path. /// Thrown if a specified file does not exist. - /// Thrown if a specified file is restricted. - Task>> DeleteFilesAsync(string rootDirectory, params string[] files); + /// Thrown if a specified file is restricted. + Task>> DeleteFilesAsync(params string[] files); /// - /// Lists the contents in the specified , optionally applying the specified . + /// Lists the contents in the specified , optionally applying the specified . /// - /// The root directory. - /// An optional subdirectory from which to start the listing. + /// The directory from which to start the listing. /// Optional enumeration options to apply. /// The list of found contents. + /// Thrown if the specified directory has a relative path. /// Thrown if the specified directory does not exist. - /// Thrown if the specified root directory is restricted. - Task ListContentsAsync(string rootDirectory, string parentDirectory = null, EnumerationOptions enumerationOptions = null); + /// Thrown if the specified root directory is restricted. + Task ListContentsAsync(string directory, EnumerationOptions enumerationOptions = null); } } \ No newline at end of file -- cgit v1.2.3 From e7bd2e44db0fd422b761a96447c504dc4bfe0da7 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 1 Jul 2023 15:11:50 -0500 Subject: remove ForbiddenException in favor of SecurityException --- src/slskd/Common/Exceptions/ForbiddenException.cs | 72 ----------------------- 1 file changed, 72 deletions(-) delete mode 100644 src/slskd/Common/Exceptions/ForbiddenException.cs (limited to 'src') diff --git a/src/slskd/Common/Exceptions/ForbiddenException.cs b/src/slskd/Common/Exceptions/ForbiddenException.cs deleted file mode 100644 index 814b8cfc..00000000 --- a/src/slskd/Common/Exceptions/ForbiddenException.cs +++ /dev/null @@ -1,72 +0,0 @@ -// -// Copyright (c) slskd Team. All rights reserved. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published -// by the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see https://www.gnu.org/licenses/. -// - -namespace slskd -{ - using System; - using System.Diagnostics.CodeAnalysis; - using System.Runtime.Serialization; - - /// - /// Represents errors that originate when an attempt is made to access a restricted resource. - /// - [ExcludeFromCodeCoverage] - [Serializable] - public class ForbiddenException : SlskdException - { - /// - /// Initializes a new instance of the class. - /// - public ForbiddenException() - : base() - { - } - - /// - /// Initializes a new instance of the class with a specified error message. - /// - /// The message that describes the error. - public ForbiddenException(string message) - : base(message) - { - } - - /// - /// Initializes a new instance of the class with a specified error message and a - /// reference to the inner exception that is the cause of this exception. - /// - /// The message that describes the error. - /// - /// The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if no - /// inner exception is specified. - /// - public ForbiddenException(string message, Exception innerException) - : base(message, innerException) - { - } - - /// - /// Initializes a new instance of the class with serialized data. - /// - /// The SerializationInfo that holds the serialized object data about the exception being thrown. - /// The StreamingContext that contains contextual information about the source or destination. - protected ForbiddenException(SerializationInfo info, StreamingContext context) - : base(info, context) - { - } - } -} \ No newline at end of file -- cgit v1.2.3 From 7316f144c2fca00fbcfe54b65846a4102ea536ab Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 1 Jul 2023 15:12:12 -0500 Subject: refactor, simplify, document --- src/slskd/Files/API/FilesController.cs | 288 ++++++++++++++++----------------- 1 file changed, 143 insertions(+), 145 deletions(-) (limited to 'src') diff --git a/src/slskd/Files/API/FilesController.cs b/src/slskd/Files/API/FilesController.cs index f4b3ce87..12c642c0 100644 --- a/src/slskd/Files/API/FilesController.cs +++ b/src/slskd/Files/API/FilesController.cs @@ -22,10 +22,12 @@ namespace slskd.Files.API using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.IO; + using System.Security; using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using OneOf; + using Serilog; /// /// Files. @@ -47,163 +49,145 @@ namespace slskd.Files.API private IFileService Files { get; } private IOptionsSnapshot OptionsSnapshot { get; } + private ILogger Log { get; set; } = Serilog.Log.ForContext(); + /// + /// Lists the contents of the downloads directory. + /// + /// An optional value indicating whether to recursively list subdirectories and files. + /// + /// The request completed successfully. + /// Authentication failed. [HttpGet("downloads/directories")] [Authorize(Policy = AuthPolicy.Any)] [ProducesResponseType(typeof(FilesystemDirectory), 200)] - public async Task GetDownloadContentsAsync([FromQuery] bool recursive = false) - { - try - { - var response = await Files.ListContentsAsync( - rootDirectory: OptionsSnapshot.Value.Directories.Downloads, - enumerationOptions: new EnumerationOptions - { - AttributesToSkip = FileAttributes.System, - RecurseSubdirectories = recursive, - }); - - return Ok(response); - } - catch (ForbiddenException) - { - return Forbid(); - } - catch (NotFoundException) - { - return NotFound(); - } - } + [ProducesResponseType(401)] + public Task GetDownloadContentsAsync([FromQuery] bool recursive = false) + => ListDirectoryAsync(rootDirectory: OptionsSnapshot.Value.Directories.Downloads, base64SubdirectoryName: null, recursive); + /// + /// Lists the contents of the specified subdirectory within the downloads directory. + /// + /// The relative, base 64 encoded, name of the subdirectory to list. + /// An optional value indicating whether to recursively list subdirectories and files. + /// + /// The request completed successfully. + /// Authentication failed. + /// Access to the specified subdirectory was denied. + /// The specified subdirectory does not exist. [HttpGet("downloads/directories/{base64SubdirectoryName}")] [Authorize(Policy = AuthPolicy.Any)] [ProducesResponseType(typeof(FilesystemDirectory), 200)] - public async Task GetDownloadSubdirectoryContentsAsync([FromRoute] string base64SubdirectoryName, [FromQuery] bool recursive = false) - { - var decodedDir = base64SubdirectoryName.FromBase64(); - - try - { - var response = await Files.ListContentsAsync( - rootDirectory: OptionsSnapshot.Value.Directories.Downloads, - parentDirectory: decodedDir, - enumerationOptions: new EnumerationOptions - { - AttributesToSkip = FileAttributes.System, - RecurseSubdirectories = recursive, - }); - - return Ok(response); - } - catch (ForbiddenException) - { - return Forbid(); - } - catch (NotFoundException) - { - return NotFound(); - } - } + [ProducesResponseType(401)] + [ProducesResponseType(403)] + [ProducesResponseType(404)] + public Task GetDownloadSubdirectoryContentsAsync([FromRoute] string base64SubdirectoryName, [FromQuery] bool recursive = false) + => ListDirectoryAsync(rootDirectory: OptionsSnapshot.Value.Directories.Downloads, base64SubdirectoryName, recursive); + /// + /// Deletes the specified subdirectory within the downloads directory. + /// + /// The relative, base 64 encoded, name of the subdirectory to delete. + /// + /// The request completed successfully. + /// Authentication failed. + /// Access to the specified subdirectory was denied. + /// The specified subdirectory does not exist. [HttpDelete("downloads/directories/{base64SubdirectoryName}")] [Authorize(Policy = AuthPolicy.Any)] [ProducesResponseType(typeof(Dictionary>), 204)] - public async Task DeleteDownloadSubdirectoryAsync([FromRoute] string base64SubdirectoryName) - { - if (!OptionsSnapshot.Value.RemoteFileManagement) - { - return Forbid(); - } - - var decodedDir = base64SubdirectoryName.FromBase64(); - - try - { - var results = await Files.DeleteDirectoriesAsync(OptionsSnapshot.Value.Directories.Downloads, decodedDir); - - return results[decodedDir].Match( - success => NoContent(), - failure => throw failure); - } - catch (ForbiddenException) - { - return Forbid(); - } - catch (NotFoundException) - { - return NotFound(); - } - } + public Task DeleteDownloadSubdirectoryAsync([FromRoute] string base64SubdirectoryName) + => DeleteSubdirectoryAsync(rootDirectory: OptionsSnapshot.Value.Directories.Downloads, base64SubdirectoryName); + /// + /// Deletes the specified file within the downloads directory. + /// + /// The relative, base 64 encoded, name of the file to delete. + /// + /// The request completed successfully. + /// Authentication failed. + /// Access to the specified subdirectory was denied. + /// The specified subdirectory does not exist. [HttpDelete("downloads/files/{base64Filename}")] [Authorize(Policy = AuthPolicy.Any)] [ProducesResponseType(typeof(Dictionary>), 204)] - public async Task DeleteDownloadFileAsync([FromRoute] string base64filename) - { - if (!OptionsSnapshot.Value.RemoteFileManagement) - { - return Forbid(); - } - - var decodedFilename = base64filename.FromBase64(); - - try - { - var results = await Files.DeleteFilesAsync(OptionsSnapshot.Value.Directories.Downloads, base64filename); - - return results[decodedFilename].Match( - success => NoContent(), - failure => throw failure); - } - catch (ForbiddenException) - { - return Forbid(); - } - catch (NotFoundException) - { - return NotFound(); - } - } + public Task DeleteDownloadFileAsync([FromRoute] string base64filename) + => DeleteFileAsync(rootDirectory: OptionsSnapshot.Value.Directories.Downloads, base64filename); + /// + /// Lists the contents of the downloads directory. + /// + /// An optional value indicating whether to recursively list subdirectories and files. + /// + /// The request completed successfully. + /// Authentication failed. [HttpGet("incomplete/directories")] [Authorize(Policy = AuthPolicy.Any)] [ProducesResponseType(typeof(FilesystemDirectory), 200)] - public async Task GetIncompleteContentsAsync([FromQuery] bool recursive = false) - { - try - { - var response = await Files.ListContentsAsync( - rootDirectory: OptionsSnapshot.Value.Directories.Incomplete, - enumerationOptions: new EnumerationOptions - { - AttributesToSkip = FileAttributes.System, - RecurseSubdirectories = recursive, - }); - - return Ok(response); - } - catch (ForbiddenException) - { - return Forbid(); - } - catch (NotFoundException) - { - return NotFound(); - } - } + public Task GetIncompleteContentsAsync([FromQuery] bool recursive = false) + => ListDirectoryAsync(rootDirectory: OptionsSnapshot.Value.Directories.Incomplete, base64SubdirectoryName: null, recursive); + /// + /// Lists the contents of the specified subdirectory within the incomplete directory. + /// + /// The relative, base 64 encoded, name of the subdirectory to list. + /// An optional value indicating whether to recursively list subdirectories and files. + /// + /// The request completed successfully. + /// Authentication failed. + /// Access to the specified subdirectory was denied. + /// The specified subdirectory does not exist. [HttpGet("incomplete/directories/{base64SubdirectoryName}")] [Authorize(Policy = AuthPolicy.Any)] [ProducesResponseType(typeof(FilesystemDirectory), 200)] - public async Task GetIncompleteSubdirectoryContentsAsync([FromRoute, Required] string base64SubdirectoryName, [FromQuery] bool recursive = false) + public Task GetIncompleteSubdirectoryContentsAsync([FromRoute, Required] string base64SubdirectoryName, [FromQuery] bool recursive = false) + => ListDirectoryAsync(rootDirectory: OptionsSnapshot.Value.Directories.Incomplete, base64SubdirectoryName, recursive); + + /// + /// Deletes the specified subdirectory within the downloads directory. + /// + /// The relative, base 64 encoded, name of the subdirectory to delete. + /// + /// The request completed successfully. + /// Authentication failed. + /// Access to the specified subdirectory was denied. + /// The specified subdirectory does not exist. + [HttpDelete("incomplete/directories/{base64SubdirectoryName}")] + [Authorize(Policy = AuthPolicy.Any)] + [ProducesResponseType(typeof(Dictionary>), 204)] + public Task DeleteIncompleteSubdirectoryAsync([FromRoute] string base64SubdirectoryName) + => DeleteSubdirectoryAsync(rootDirectory: OptionsSnapshot.Value.Directories.Incomplete, base64SubdirectoryName); + + /// + /// Deletes the specified file within the downloads directory. + /// + /// The relative, base 64 encoded, name of the file to delete. + /// + /// The request completed successfully. + /// Authentication failed. + /// Access to the specified subdirectory was denied. + /// The specified subdirectory does not exist. + [HttpDelete("incomplete/files/{base64Filename}")] + [Authorize(Policy = AuthPolicy.Any)] + [ProducesResponseType(204)] + public Task DeleteIncompleteFileAsync([FromRoute] string base64filename) + => DeleteFileAsync(rootDirectory: OptionsSnapshot.Value.Directories.Incomplete, base64filename); + + private async Task ListDirectoryAsync(string rootDirectory, string base64SubdirectoryName = null, bool recursive = false) { - var decodedDir = base64SubdirectoryName.FromBase64(); + var requestedDir = (base64SubdirectoryName ?? string.Empty) + .FromBase64() + .Replace('\\', Path.DirectorySeparatorChar) + .Replace('/', Path.DirectorySeparatorChar); + + requestedDir = Path.GetFullPath(Path.Combine(rootDirectory, requestedDir)); + + Log.Debug("Listing directory '{Directory}'", requestedDir); try { var response = await Files.ListContentsAsync( - rootDirectory: OptionsSnapshot.Value.Directories.Incomplete, - parentDirectory: decodedDir, + directory: requestedDir, enumerationOptions: new EnumerationOptions { AttributesToSkip = FileAttributes.System, @@ -212,72 +196,86 @@ namespace slskd.Files.API return Ok(response); } - catch (ForbiddenException) + catch (SecurityException) { + Log.Warning("Directory listing of '{Directory}' forbidden", requestedDir); return Forbid(); } catch (NotFoundException) { + Log.Debug("Directory '{Directory}' not found", requestedDir); return NotFound(); } } - [HttpDelete("incomplete/directories/{base64SubdirectoryName}")] - [Authorize(Policy = AuthPolicy.Any)] - [ProducesResponseType(typeof(Dictionary>), 204)] - public async Task DeleteIncompleteSubdirectoryAsync([FromRoute] string base64SubdirectoryName) + private async Task DeleteSubdirectoryAsync(string rootDirectory, string base64SubdirectoryName) { if (!OptionsSnapshot.Value.RemoteFileManagement) { return Forbid(); } - var decodedDir = base64SubdirectoryName.FromBase64(); + var requestedDir = base64SubdirectoryName + .FromBase64() + .Replace('\\', Path.DirectorySeparatorChar) + .Replace('/', Path.DirectorySeparatorChar); + + requestedDir = Path.GetFullPath(Path.Combine(rootDirectory, requestedDir)); + + Log.Information("Deleting directory '{Directory}'", requestedDir); try { - var results = await Files.DeleteDirectoriesAsync(OptionsSnapshot.Value.Directories.Incomplete, decodedDir); + var results = await Files.DeleteDirectoriesAsync(requestedDir); - return results[decodedDir].Match( + return results[requestedDir].Match( success => NoContent(), failure => throw failure); } - catch (ForbiddenException) + catch (SecurityException) { + Log.Warning("Directory deletion of '{Directory}' forbidden", requestedDir); return Forbid(); } catch (NotFoundException) { + Log.Information("Directory '{Directory}' not found", requestedDir); return NotFound(); } } - [HttpDelete("incomplete/files/{base64Filename}")] - [Authorize(Policy = AuthPolicy.Any)] - [ProducesResponseType(typeof(Dictionary>), 204)] - public async Task DeleteIncompleteFileAsync([FromRoute] string base64filename) + private async Task DeleteFileAsync(string rootDirectory, string base64Filename) { if (!OptionsSnapshot.Value.RemoteFileManagement) { return Forbid(); } - var decodedFilename = base64filename.FromBase64(); + var requestedFilename = base64Filename + .FromBase64() + .Replace('\\', Path.DirectorySeparatorChar) + .Replace('/', Path.DirectorySeparatorChar); + + requestedFilename = Path.GetFullPath(Path.Combine(rootDirectory, requestedFilename)); + + Log.Information("Deleting file '{File}'", requestedFilename); try { - var results = await Files.DeleteFilesAsync(OptionsSnapshot.Value.Directories.Incomplete, base64filename); + var results = await Files.DeleteFilesAsync(requestedFilename); - return results[decodedFilename].Match( + return results[requestedFilename].Match( success => NoContent(), failure => throw failure); } - catch (ForbiddenException) + catch (SecurityException) { + Log.Warning("File deletion of '{File}' forbidden", requestedFilename); return Forbid(); } catch (NotFoundException) { + Log.Information("File '{File}' not found", requestedFilename); return NotFound(); } } -- cgit v1.2.3 From 94712ee9915cd46212b589e283a211545ec1141e Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 1 Jul 2023 15:12:17 -0500 Subject: docs --- src/slskd/Files/Types/FilesystemDirectory.cs | 35 ++++++++++++++++++++++++++++ src/slskd/Files/Types/FilesystemFile.cs | 31 ++++++++++++++++++++++++ 2 files changed, 66 insertions(+) (limited to 'src') diff --git a/src/slskd/Files/Types/FilesystemDirectory.cs b/src/slskd/Files/Types/FilesystemDirectory.cs index 9e573906..6628ce15 100644 --- a/src/slskd/Files/Types/FilesystemDirectory.cs +++ b/src/slskd/Files/Types/FilesystemDirectory.cs @@ -21,16 +21,51 @@ namespace slskd.Files using System.Collections.Generic; using System.IO; + /// + /// A file directory on the host filesystem. + /// public record FilesystemDirectory { + /// + /// The name of the directory. + /// public string Name { get; init; } + + /// + /// The fully qualified name of the directory. + /// public string FullName { get; init; } + + /// + /// The directories' attributes. + /// public FileAttributes Attributes { get; init; } + + /// + /// The timestamp at which the directory was created. + /// public DateTime CreatedAt { get; init; } + + /// + /// The timestamp at which the directory was last modified. + /// public DateTime ModifiedAt { get; init; } + + /// + /// The files within the directory. + /// public IEnumerable Files { get; init; } + + /// + /// The directories within the directory. + /// public IEnumerable Directories { get; init; } + /// + /// Maps a from the specified . + /// + /// The DirectoryInfo instance from which to map. + /// A new instance of FilesystemDirectory. public static FilesystemDirectory FromDirectoryInfo(DirectoryInfo i) { return new FilesystemDirectory diff --git a/src/slskd/Files/Types/FilesystemFile.cs b/src/slskd/Files/Types/FilesystemFile.cs index fc36fff0..0b6feeb5 100644 --- a/src/slskd/Files/Types/FilesystemFile.cs +++ b/src/slskd/Files/Types/FilesystemFile.cs @@ -20,15 +20,46 @@ namespace slskd.Files using System; using System.IO; + /// + /// A file on the host filesystem. + /// public record FilesystemFile { + /// + /// The name of the file. + /// public string Name { get; init; } + + /// + /// The fully qualified name of the file. + /// public string FullName { get; init; } + + /// + /// The size of the file, in bytes. + /// public long Length { get; init; } + + /// + /// The file's attributes. + /// public FileAttributes Attributes { get; init; } + + /// + /// The timestamp at which the file was created. + /// public DateTime CreatedAt { get; init; } + + /// + /// The timestamp at which the file was last modified. + /// public DateTime ModifiedAt { get; init; } + /// + /// Maps a from the specified . + /// + /// The FileInfo instance from which to map. + /// A new instance of FilesystemFile. public static FilesystemFile FromFileInfo(FileInfo i) { return new FilesystemFile -- cgit v1.2.3 From da070602c8db9ec39b447c34857f2a8434e9cdd0 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 2 Jul 2023 12:22:39 -0500 Subject: add tests to ensure only desirable paths can be accessed --- .../Common/Exceptions/UnauthorizedException.cs | 72 +++++++++++ src/slskd/Files/FileService.cs | 22 ++-- src/slskd/Files/IFileService.cs | 6 +- tests/slskd.Tests.Unit/Files/FileServiceTests.cs | 137 +++++++++++++++++++++ 4 files changed, 223 insertions(+), 14 deletions(-) create mode 100644 src/slskd/Common/Exceptions/UnauthorizedException.cs create mode 100644 tests/slskd.Tests.Unit/Files/FileServiceTests.cs (limited to 'src') diff --git a/src/slskd/Common/Exceptions/UnauthorizedException.cs b/src/slskd/Common/Exceptions/UnauthorizedException.cs new file mode 100644 index 00000000..a7179c80 --- /dev/null +++ b/src/slskd/Common/Exceptions/UnauthorizedException.cs @@ -0,0 +1,72 @@ +// +// Copyright (c) slskd Team. All rights reserved. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published +// by the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see https://www.gnu.org/licenses/. +// + +namespace slskd +{ + using System; + using System.Diagnostics.CodeAnalysis; + using System.Runtime.Serialization; + + /// + /// Represents errors that originate when a restricted resources is accessed without authorization. + /// + [ExcludeFromCodeCoverage] + [Serializable] + public class UnauthorizedException : SlskdException + { + /// + /// Initializes a new instance of the class. + /// + public UnauthorizedException() + : base() + { + } + + /// + /// Initializes a new instance of the class with a specified error message. + /// + /// The message that describes the error. + public UnauthorizedException(string message) + : base(message) + { + } + + /// + /// Initializes a new instance of the class with a specified error message and a + /// reference to the inner exception that is the cause of this exception. + /// + /// The message that describes the error. + /// + /// The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if no + /// inner exception is specified. + /// + public UnauthorizedException(string message, Exception innerException) + : base(message, innerException) + { + } + + /// + /// Initializes a new instance of the class with serialized data. + /// + /// The SerializationInfo that holds the serialized object data about the exception being thrown. + /// The StreamingContext that contains contextual information about the source or destination. + protected UnauthorizedException(SerializationInfo info, StreamingContext context) + : base(info, context) + { + } + } +} \ No newline at end of file diff --git a/src/slskd/Files/FileService.cs b/src/slskd/Files/FileService.cs index 2324a492..c820220f 100644 --- a/src/slskd/Files/FileService.cs +++ b/src/slskd/Files/FileService.cs @@ -65,7 +65,7 @@ namespace slskd.Files /// Thrown if any of the directories is an exact match for an application-controlled directory. /// /// Thrown if a specified directory does not exist. - /// Thrown if a specified directory is restricted. + /// Thrown if a specified directory is restricted. public async Task>> DeleteDirectoriesAsync(params string[] directories) { if (directories.Any(directory => Path.GetFullPath(directory) != directory)) @@ -84,7 +84,7 @@ namespace slskd.Files // if any of the resolved directory paths aren't rooted in one of the allowed directories, forbid the entire request if (!directories.All(directory => IsAllowed(directory))) { - throw new SecurityException("Only application-controlled directories can be deleted"); + throw new UnauthorizedException("Only application-controlled directories can be deleted"); } await Task.Yield(); @@ -104,9 +104,9 @@ namespace slskd.Files { results.Add(directory, new NotFoundException($"The directory '{directory}' does not exist")); } - catch (UnauthorizedAccessException) + catch (UnauthorizedAccessException ex) { - results.Add(directory, new SecurityException()); + results.Add(directory, new UnauthorizedException($"Deletion of the directory '{directory}' was denied: {ex.Message}", ex)); } catch (Exception ex) { @@ -128,7 +128,7 @@ namespace slskd.Files /// The operation context. /// Thrown if any of the specified files have a relative path. /// Thrown if a specified file does not exist. - /// Thrown if a specified file is restricted. + /// Thrown if a specified file is restricted. public async Task>> DeleteFilesAsync(params string[] files) { if (files.Any(file => Path.GetFullPath(file) != file)) @@ -142,7 +142,7 @@ namespace slskd.Files // if any of the resolved file paths aren't rooted in one of the allowed directories, forbid the entire request if (!files.All(file => IsAllowed(file))) { - throw new SecurityException("Only files in application-controlled directories can be deleted"); + throw new UnauthorizedException("Only files in application-controlled directories can be deleted"); } await Task.Yield(); @@ -160,9 +160,9 @@ namespace slskd.Files { results.Add(file, new NotFoundException($"The file '{file}' does not exist")); } - catch (UnauthorizedAccessException) + catch (UnauthorizedAccessException ex) { - results.Add(file, new SecurityException()); + results.Add(file, new UnauthorizedException($"Deletion of the file '{file}' was denied: {ex.Message}", ex)); } catch (Exception ex) { @@ -181,7 +181,7 @@ namespace slskd.Files /// The list of found contents. /// Thrown if the specified directory has a relative path. /// Thrown if the specified directory does not exist. - /// Thrown if the specified root directory is restricted. + /// Thrown if the specified root directory is restricted. public async Task ListContentsAsync(string directory, EnumerationOptions enumerationOptions = null) { if (Path.GetFullPath(directory) != directory) @@ -192,7 +192,7 @@ namespace slskd.Files // important! we must fully expand the path with GetFullPath() to resolve a given relative directory, like '..' if (!AllowedDirectories.Any(allowed => directory.StartsWith(allowed))) { - throw new SecurityException($"For security reasons, only application-controlled directories can be deleted"); + throw new UnauthorizedException($"Only application-controlled directories can be deleted"); } if (!Directory.Exists(directory)) @@ -233,7 +233,7 @@ namespace slskd.Files } catch (UnauthorizedAccessException ex) { - throw new SecurityException($"Access to '{directory}' was denied", ex); + throw new UnauthorizedException($"Access to directory '{directory}' was denied: {ex.Message}", ex); } }); } diff --git a/src/slskd/Files/IFileService.cs b/src/slskd/Files/IFileService.cs index 63b5f1a3..89d4ce76 100644 --- a/src/slskd/Files/IFileService.cs +++ b/src/slskd/Files/IFileService.cs @@ -43,7 +43,7 @@ namespace slskd.Files /// Thrown if any of the directories is an exact match for an application-controlled directory. /// /// Thrown if a specified directory does not exist. - /// Thrown if a specified directory is restricted. + /// Thrown if a specified directory is restricted. Task>> DeleteDirectoriesAsync(params string[] directories); /// @@ -57,7 +57,7 @@ namespace slskd.Files /// The operation context. /// Thrown if any of the specified files have a relative path. /// Thrown if a specified file does not exist. - /// Thrown if a specified file is restricted. + /// Thrown if a specified file is restricted. Task>> DeleteFilesAsync(params string[] files); /// @@ -68,7 +68,7 @@ namespace slskd.Files /// The list of found contents. /// Thrown if the specified directory has a relative path. /// Thrown if the specified directory does not exist. - /// Thrown if the specified root directory is restricted. + /// Thrown if the specified root directory is restricted. Task ListContentsAsync(string directory, EnumerationOptions enumerationOptions = null); } } \ No newline at end of file diff --git a/tests/slskd.Tests.Unit/Files/FileServiceTests.cs b/tests/slskd.Tests.Unit/Files/FileServiceTests.cs new file mode 100644 index 00000000..7c9931ab --- /dev/null +++ b/tests/slskd.Tests.Unit/Files/FileServiceTests.cs @@ -0,0 +1,137 @@ +using Microsoft.Extensions.Options; + +namespace slskd.Tests.Unit.Files +{ + using System; + using System.IO; + using System.Threading.Tasks; + using Moq; + using slskd.Files; + using Xunit; + + public class FileServiceTests : IDisposable + { + public FileServiceTests() + { + OptionsSnapshotMock = new Mock>(); + + Temp = Path.Combine(Path.GetTempPath(), $"slskd.test.{Guid.NewGuid()}"); + Directory.CreateDirectory(Temp); + + FileService = new FileService( + optionsSnapshot: OptionsSnapshotMock.Object); + } + + public void Dispose() + { + Directory.Delete(Temp, recursive: true); + } + + private Mock> OptionsSnapshotMock { get; init; } + private string Temp { get; init; } + private IFileService FileService { get; init; } + + [Fact] + public async Task ListContentsAsync_Throws_ArgumentException_Given_Relative_Path() + { + var ex = await Record.ExceptionAsync(() => FileService.ListContentsAsync(directory: "../")); + + Assert.NotNull(ex); + Assert.IsType(ex); + Assert.Equal("directory", ((ArgumentException)ex).ParamName); + } + + [Fact] + public async Task ListContentsAsync_Throws_UnauthorizedException_Given_Disallowed_Directory() + { + OptionsSnapshotMock.Setup(o => o.Value).Returns(new Options + { + Directories = new Options.DirectoriesOptions + { + Downloads = Path.Combine(Temp, "downloads"), + Incomplete = Path.Combine(Temp, "incomplete"), + } + }); + + var ex = await Record.ExceptionAsync(() => FileService.ListContentsAsync(directory: Path.Combine(Temp, "foo"))); + + Assert.NotNull(ex); + Assert.IsType(ex); + } + + [Fact] + public async Task ListContentsAsync_Throws_NotFoundException_Given_NonExistent_Directory() + { + OptionsSnapshotMock.Setup(o => o.Value).Returns(new Options + { + Directories = new Options.DirectoriesOptions + { + Downloads = Path.Combine(Temp, "downloads"), + Incomplete = Path.Combine(Temp, "incomplete"), + } + }); + + var ex = await Record.ExceptionAsync(() => FileService.ListContentsAsync(directory: Path.Combine(Temp, "downloads", "foo"))); + + Assert.NotNull(ex); + Assert.IsType(ex); + } + + [Fact] + public async Task DeleteDirectoriesAsync_Throws_ArgumentException_Given_Relative_Path() + { + var ex = await Record.ExceptionAsync(() => FileService.DeleteDirectoriesAsync("../foo")); + + Assert.NotNull(ex); + Assert.IsType(ex); + Assert.Equal("directories", ((ArgumentException)ex).ParamName); + } + + [Fact] + public async Task DeleteDirectoriesAsync_Throws_ArgumentException_Given_Disallowed_Path() + { + OptionsSnapshotMock.Setup(o => o.Value).Returns(new Options + { + Directories = new Options.DirectoriesOptions + { + Downloads = Path.Combine(Temp, "downloads"), + Incomplete = Path.Combine(Temp, "incomplete"), + } + }); + + var ex = await Record.ExceptionAsync(() => FileService.DeleteDirectoriesAsync(Path.Combine(Temp, "foo"))); + + Assert.NotNull(ex); + Assert.IsType(ex); + } + + [Fact] + public async Task DeleteFilesAsync_Throws_ArgumentException_Given_Relative_Path() + { + var ex = await Record.ExceptionAsync(() => FileService.DeleteFilesAsync("../foo.bar")); + + Assert.NotNull(ex); + Assert.IsType(ex); + Assert.Equal("files", ((ArgumentException)ex).ParamName); + } + + [Fact] + public async Task DeleteFilesAsync_Throws_ArgumentException_Given_Disallowed_Path() + { + OptionsSnapshotMock.Setup(o => o.Value).Returns(new Options + { + Directories = new Options.DirectoriesOptions + { + Downloads = Path.Combine(Temp, "downloads"), + Incomplete = Path.Combine(Temp, "incomplete"), + } + }); + + var ex = await Record.ExceptionAsync(() => FileService.DeleteFilesAsync(Path.Combine(Temp, "foo"))); + + Assert.NotNull(ex); + Assert.IsType(ex); + } + } +} + -- cgit v1.2.3 From d3044304c1543b4df899a0eb1d4edf21b0ed3a61 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 2 Jul 2023 13:08:31 -0500 Subject: tweak --- src/slskd/Files/API/FilesController.cs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/slskd/Files/API/FilesController.cs b/src/slskd/Files/API/FilesController.cs index 12c642c0..2bb2d051 100644 --- a/src/slskd/Files/API/FilesController.cs +++ b/src/slskd/Files/API/FilesController.cs @@ -95,24 +95,24 @@ namespace slskd.Files.API /// The specified subdirectory does not exist. [HttpDelete("downloads/directories/{base64SubdirectoryName}")] [Authorize(Policy = AuthPolicy.Any)] - [ProducesResponseType(typeof(Dictionary>), 204)] + [ProducesResponseType(204)] public Task DeleteDownloadSubdirectoryAsync([FromRoute] string base64SubdirectoryName) => DeleteSubdirectoryAsync(rootDirectory: OptionsSnapshot.Value.Directories.Downloads, base64SubdirectoryName); /// /// Deletes the specified file within the downloads directory. /// - /// The relative, base 64 encoded, name of the file to delete. + /// The relative, base 64 encoded, name of the file to delete. /// /// The request completed successfully. /// Authentication failed. /// Access to the specified subdirectory was denied. /// The specified subdirectory does not exist. - [HttpDelete("downloads/files/{base64Filename}")] + [HttpDelete("downloads/files/{base64FileName}")] [Authorize(Policy = AuthPolicy.Any)] - [ProducesResponseType(typeof(Dictionary>), 204)] - public Task DeleteDownloadFileAsync([FromRoute] string base64filename) - => DeleteFileAsync(rootDirectory: OptionsSnapshot.Value.Directories.Downloads, base64filename); + [ProducesResponseType(204)] + public Task DeleteDownloadFileAsync([FromRoute] string base64FileName) + => DeleteFileAsync(rootDirectory: OptionsSnapshot.Value.Directories.Downloads, base64FileName); /// /// Lists the contents of the downloads directory. @@ -154,24 +154,24 @@ namespace slskd.Files.API /// The specified subdirectory does not exist. [HttpDelete("incomplete/directories/{base64SubdirectoryName}")] [Authorize(Policy = AuthPolicy.Any)] - [ProducesResponseType(typeof(Dictionary>), 204)] + [ProducesResponseType(204)] public Task DeleteIncompleteSubdirectoryAsync([FromRoute] string base64SubdirectoryName) => DeleteSubdirectoryAsync(rootDirectory: OptionsSnapshot.Value.Directories.Incomplete, base64SubdirectoryName); /// /// Deletes the specified file within the downloads directory. /// - /// The relative, base 64 encoded, name of the file to delete. + /// The relative, base 64 encoded, name of the file to delete. /// /// The request completed successfully. /// Authentication failed. /// Access to the specified subdirectory was denied. /// The specified subdirectory does not exist. - [HttpDelete("incomplete/files/{base64Filename}")] + [HttpDelete("incomplete/files/{base64FileName}")] [Authorize(Policy = AuthPolicy.Any)] [ProducesResponseType(204)] - public Task DeleteIncompleteFileAsync([FromRoute] string base64filename) - => DeleteFileAsync(rootDirectory: OptionsSnapshot.Value.Directories.Incomplete, base64filename); + public Task DeleteIncompleteFileAsync([FromRoute] string base64FileName) + => DeleteFileAsync(rootDirectory: OptionsSnapshot.Value.Directories.Incomplete, base64FileName); private async Task ListDirectoryAsync(string rootDirectory, string base64SubdirectoryName = null, bool recursive = false) { @@ -244,14 +244,14 @@ namespace slskd.Files.API } } - private async Task DeleteFileAsync(string rootDirectory, string base64Filename) + private async Task DeleteFileAsync(string rootDirectory, string base64FileName) { if (!OptionsSnapshot.Value.RemoteFileManagement) { return Forbid(); } - var requestedFilename = base64Filename + var requestedFilename = base64FileName .FromBase64() .Replace('\\', Path.DirectorySeparatorChar) .Replace('/', Path.DirectorySeparatorChar); -- cgit v1.2.3 From c30601e020a8de18078379fd70a12ae5798cae3e Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 22 Jul 2023 23:00:39 -0500 Subject: add formatDate --- src/web/src/lib/util.js | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/web/src/lib/util.js b/src/web/src/lib/util.js index 20653737..974915ed 100644 --- a/src/web/src/lib/util.js +++ b/src/web/src/lib/util.js @@ -21,6 +21,10 @@ export const formatBytes = (bytes, decimals = 2) => { return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i]; }; +export const formatDate = (date) => { + return new Date(date).toLocaleString(); +}; + export const getFileName = (fullPath) => { return fullPath.split('\\').pop().split('/').pop(); }; -- cgit v1.2.3 From cd2c5889754728410b3e11e55a37a169cc475993 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 22 Jul 2023 23:00:55 -0500 Subject: add Files.css --- src/web/src/components/System/Files/Files.css | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 src/web/src/components/System/Files/Files.css (limited to 'src') diff --git a/src/web/src/components/System/Files/Files.css b/src/web/src/components/System/Files/Files.css new file mode 100644 index 00000000..08cb3f4c --- /dev/null +++ b/src/web/src/components/System/Files/Files.css @@ -0,0 +1,3 @@ +.explorer-list-action { + width: 5px !important; + } \ No newline at end of file -- cgit v1.2.3 From 2ff09498b33c7b2e0d8318cc85e09da5025e0024 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 22 Jul 2023 23:01:10 -0500 Subject: track active tab --- src/web/src/components/System/Files/index.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/web/src/components/System/Files/index.js b/src/web/src/components/System/Files/index.js index b5ab465b..07e91a96 100644 --- a/src/web/src/components/System/Files/index.js +++ b/src/web/src/components/System/Files/index.js @@ -1,26 +1,34 @@ -import React from 'react'; +import React, { useState } from 'react'; import { Tab } from 'semantic-ui-react'; +import './Files.css'; import Explorer from './Explorer'; const Files = () => { + const [tab, setTab] = useState('downloads'); + const panes = [ { route: 'downloads', menuItem: 'Downloads', - render: () => , + render: () => , }, { route: 'incomplete', menuItem: 'Incomplete', - render: () => , + render: () => , }, ]; + const onTabChange = (e, { activeIndex }) => { + setTab(panes[activeIndex].route); + }; + return (
); -- cgit v1.2.3 From 3293f42555fafada32def098a30274267eab21c8 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 22 Jul 2023 23:01:17 -0500 Subject: add file table --- src/web/src/components/System/Files/Explorer.js | 62 +++++++++++++++++++++---- 1 file changed, 53 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/web/src/components/System/Files/Explorer.js b/src/web/src/components/System/Files/Explorer.js index 6abbe5c6..adc8d3bf 100644 --- a/src/web/src/components/System/Files/Explorer.js +++ b/src/web/src/components/System/Files/Explorer.js @@ -1,32 +1,76 @@ import React, { useState, useEffect } from 'react'; +import { + Table, + Icon, + Message +} from 'semantic-ui-react'; + import { list } from '../../../lib/files'; +import { formatBytes, formatDate } from '../../../lib/util'; +import { LoaderSegment } from '../../Shared'; -const Explorer = ({ root }) => { +const Explorer = ({ root, isActive }) => { const [directory, setDirectory] = useState({ files: [], directories: [] }); const [subdirectory, setSubdirectory] = useState([]); - + const [loading, setLoading] = useState(false); + useEffect(() => { + setLoading(true); + console.log('fetching...', subdirectory); const fetch = async () => { const dir = await list({ root, subdirectory: subdirectory.join('/') }); + console.log(dir) setDirectory(dir); + setLoading(false); }; fetch(); - }, [subdirectory]); + }, [isActive, subdirectory]); const select = ({ path }) => { setSubdirectory([...subdirectory, path]); + console.log(path) }; + const row = (icon, { name, fullName, modifiedAt, length }, onClick = () => { }) => + onClick({ path: name })} + >{name} + {modifiedAt ? formatDate(modifiedAt) : ''} + {length ? formatBytes(length) : ''} + + console.log(fullName)} style={{ cursor: 'pointer' }}/> + + ; + + if (loading) { + return ; + } + return ( -
- {directory?.directories?.map(d =>
- select({ path: d.name })}> - {d.name} -
)} -
+ <> + {!!subdirectory && + {root + '/' + subdirectory} + } + + + + Name + Date Modified + Size + + + + + {!!subdirectory && row('folder', { name: '..', fullName: '..' })} + {directory?.directories?.map((d => row('folder', d, select)))} + {directory?.files?.map(f => row('file outline', f))} + +
+ ); }; -- cgit v1.2.3 From 71ba3c4fe31912c6c8934b51d20f0320b386e8ff Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 23 Jul 2023 17:46:19 -0500 Subject: reduce message padding --- src/web/src/components/App.css | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/web/src/components/App.css b/src/web/src/components/App.css index ceb60536..1de44557 100644 --- a/src/web/src/components/App.css +++ b/src/web/src/components/App.css @@ -259,4 +259,8 @@ body { .search-list-wrapper { overflow-x: auto; +} + +.message { + padding: 8px 12px 8px 12px !important; } \ No newline at end of file -- cgit v1.2.3 From 1d45cca6c22c6a0f8c3fcdb50f2c9985459d4730 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 23 Jul 2023 17:46:29 -0500 Subject: add delete functions --- src/web/src/lib/files.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src') diff --git a/src/web/src/lib/files.js b/src/web/src/lib/files.js index 9c147d61..9284fb1b 100644 --- a/src/web/src/lib/files.js +++ b/src/web/src/lib/files.js @@ -4,5 +4,19 @@ export const list = async ({ root, subdirectory = '' }) => { subdirectory = btoa(subdirectory); const response = (await api.get(`/files/${root}/directories/${subdirectory}`)).data; + return response; +}; + +export const deleteDirectory = async ({ root, path }) => { + path = btoa(path); + const response = (await api.delete(`/files/${root}/directories/${path}`)); + + return response; +}; + +export const deleteFile = async ({ root, path }) => { + path = btoa(path); + const response = (await api.delete(`/files/${root}/files/${path}`)); + return response; }; \ No newline at end of file -- cgit v1.2.3 From 29ee68346f6649fe4a3865645d565f4752c2a92d Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 23 Jul 2023 17:46:44 -0500 Subject: remove tab tracking --- src/web/src/components/System/Files/index.js | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/web/src/components/System/Files/index.js b/src/web/src/components/System/Files/index.js index 07e91a96..cf3dc869 100644 --- a/src/web/src/components/System/Files/index.js +++ b/src/web/src/components/System/Files/index.js @@ -1,34 +1,27 @@ -import React, { useState } from 'react'; +import React from 'react'; import { Tab } from 'semantic-ui-react'; import './Files.css'; import Explorer from './Explorer'; const Files = () => { - const [tab, setTab] = useState('downloads'); - const panes = [ { route: 'downloads', menuItem: 'Downloads', - render: () => , + render: () => , }, { route: 'incomplete', menuItem: 'Incomplete', - render: () => , + render: () => , }, ]; - const onTabChange = (e, { activeIndex }) => { - setTab(panes[activeIndex].route); - }; - return (
); -- cgit v1.2.3 From 3ef512d000390a3f984394f462bceba6b30b9385 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 23 Jul 2023 17:47:00 -0500 Subject: fix font for directory display --- src/web/src/components/System/Files/Files.css | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/web/src/components/System/Files/Files.css b/src/web/src/components/System/Files/Files.css index 08cb3f4c..d5e48391 100644 --- a/src/web/src/components/System/Files/Files.css +++ b/src/web/src/components/System/Files/Files.css @@ -1,3 +1,7 @@ .explorer-list-action { - width: 5px !important; - } \ No newline at end of file + width: 5px !important; +} + +.explorer-working-directory { + font-size: initial !important; +} \ No newline at end of file -- cgit v1.2.3 From 5c139be17a369039dde9033ebb0ec2de20f4c6fc Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 23 Jul 2023 17:47:10 -0500 Subject: implement deletes --- src/web/src/components/System/Files/Explorer.js | 111 ++++++++++++++++++------ 1 file changed, 84 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/src/web/src/components/System/Files/Explorer.js b/src/web/src/components/System/Files/Explorer.js index adc8d3bf..aa2ae784 100644 --- a/src/web/src/components/System/Files/Explorer.js +++ b/src/web/src/components/System/Files/Explorer.js @@ -3,58 +3,115 @@ import React, { useState, useEffect } from 'react'; import { Table, Icon, - Message + Message, + Modal, + Header, } from 'semantic-ui-react'; -import { list } from '../../../lib/files'; +import { list, deleteDirectory, deleteFile } from '../../../lib/files'; import { formatBytes, formatDate } from '../../../lib/util'; import { LoaderSegment } from '../../Shared'; -const Explorer = ({ root, isActive }) => { +const Explorer = ({ root }) => { const [directory, setDirectory] = useState({ files: [], directories: [] }); const [subdirectory, setSubdirectory] = useState([]); const [loading, setLoading] = useState(false); useEffect(() => { - setLoading(true); - - console.log('fetching...', subdirectory); - const fetch = async () => { - const dir = await list({ root, subdirectory: subdirectory.join('/') }); - console.log(dir) - setDirectory(dir); - setLoading(false); - }; - fetch(); - }, [isActive, subdirectory]); + }, [subdirectory]); // eslint-disable-line react-hooks/exhaustive-deps + + useEffect(() => { + setSubdirectory([]); + }, [root]); + + const fetch = async () => { + setLoading(true); + const dir = await list({ root, subdirectory: subdirectory.join('/') }); + setDirectory(dir); + setLoading(false); + }; const select = ({ path }) => { setSubdirectory([...subdirectory, path]); - console.log(path) }; - const row = (icon, { name, fullName, modifiedAt, length }, onClick = () => { }) => - onClick({ path: name })} - >{name} + const upOneSubdirectory = () => { + const copy = [...subdirectory]; + copy.pop(); + setSubdirectory(copy); + }; + + const FileRow = ({ name, fullName, modifiedAt, length }) => + {name} {modifiedAt ? formatDate(modifiedAt) : ''} {length ? formatBytes(length) : ''} - console.log(fullName)} style={{ cursor: 'pointer' }}/> + + } + centered + size='small' + header={
} + content={`Are you sure you want to delete file '${fullName}'?`} + actions={[ + 'Cancel', + { + key: 'done', + content: 'Delete', + negative: true, + onClick: async () => { + await deleteFile({ root, path: `${subdirectory.join('/')}/${fullName}`}); + fetch(); + }, + }, + ]} + /> ; + const DirectoryRow = ({ name, fullName, modifiedAt, onClick = () => {} }) => + {name} + {modifiedAt ? formatDate(modifiedAt) : ''} + + + + } + centered + size='small' + header={
} + content={`Are you sure you want to delete directory '${fullName}'?`} + actions={[ + 'Cancel', + { + key: 'done', + content: 'Delete', + negative: true, + onClick: async () => { + await deleteDirectory({ root, path: `${subdirectory.join('/')}/${fullName}`}); + fetch(); + }, + }, + ]} + /> + + ; + if (loading) { return ; } return ( <> - {!!subdirectory && - {root + '/' + subdirectory} - } + + {'/' + root + '/' + subdirectory.join('/')} + @@ -65,9 +122,9 @@ const Explorer = ({ root, isActive }) => { - {!!subdirectory && row('folder', { name: '..', fullName: '..' })} - {directory?.directories?.map((d => row('folder', d, select)))} - {directory?.files?.map(f => row('file outline', f))} + {subdirectory.length > 0 && } + {directory?.directories?.map(d => select({ path: d.name })} {...d}/>)} + {directory?.files?.map(f => )}
-- cgit v1.2.3 From 8ed1baaa3bccf32490924920b8ff38c5812aa8c3 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 23 Jul 2023 17:48:30 -0500 Subject: ensure relative paths are supplied --- src/slskd/Files/API/FilesController.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/slskd/Files/API/FilesController.cs b/src/slskd/Files/API/FilesController.cs index 2bb2d051..372e5f5e 100644 --- a/src/slskd/Files/API/FilesController.cs +++ b/src/slskd/Files/API/FilesController.cs @@ -19,14 +19,12 @@ using Microsoft.Extensions.Options; namespace slskd.Files.API { - using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.IO; using System.Security; using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; - using OneOf; using Serilog; /// @@ -218,7 +216,8 @@ namespace slskd.Files.API var requestedDir = base64SubdirectoryName .FromBase64() .Replace('\\', Path.DirectorySeparatorChar) - .Replace('/', Path.DirectorySeparatorChar); + .Replace('/', Path.DirectorySeparatorChar) + .TrimStart(Path.DirectorySeparatorChar); requestedDir = Path.GetFullPath(Path.Combine(rootDirectory, requestedDir)); @@ -254,7 +253,8 @@ namespace slskd.Files.API var requestedFilename = base64FileName .FromBase64() .Replace('\\', Path.DirectorySeparatorChar) - .Replace('/', Path.DirectorySeparatorChar); + .Replace('/', Path.DirectorySeparatorChar) + .TrimStart(Path.DirectorySeparatorChar); requestedFilename = Path.GetFullPath(Path.Combine(rootDirectory, requestedFilename)); -- cgit v1.2.3 From 69a7f53324a4011e64abcd4b630291bf2a40958f Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Mon, 24 Jul 2023 08:15:33 -0500 Subject: use header for working dir --- src/web/src/components/System/Files/Explorer.js | 4 ++-- src/web/src/components/System/Files/Files.css | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/web/src/components/System/Files/Explorer.js b/src/web/src/components/System/Files/Explorer.js index aa2ae784..60eb01fa 100644 --- a/src/web/src/components/System/Files/Explorer.js +++ b/src/web/src/components/System/Files/Explorer.js @@ -109,9 +109,9 @@ const Explorer = ({ root }) => { return ( <> - +
{'/' + root + '/' + subdirectory.join('/')} - +
diff --git a/src/web/src/components/System/Files/Files.css b/src/web/src/components/System/Files/Files.css index d5e48391..204475b3 100644 --- a/src/web/src/components/System/Files/Files.css +++ b/src/web/src/components/System/Files/Files.css @@ -3,5 +3,5 @@ } .explorer-working-directory { - font-size: initial !important; + margin-top: 0px !important; } \ No newline at end of file -- cgit v1.2.3 From 8056b0fe5cf7a06103b1e09e148782b3642aebda Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Mon, 24 Jul 2023 08:25:07 -0500 Subject: display empty row --- src/web/src/components/System/Files/Explorer.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/web/src/components/System/Files/Explorer.js b/src/web/src/components/System/Files/Explorer.js index 60eb01fa..2b6715a0 100644 --- a/src/web/src/components/System/Files/Explorer.js +++ b/src/web/src/components/System/Files/Explorer.js @@ -107,6 +107,8 @@ const Explorer = ({ root }) => { return ; } + const total = directory?.directories?.length + directory?.files?.length ?? 0; + return ( <>
@@ -122,9 +124,18 @@ const Explorer = ({ root }) => { - {subdirectory.length > 0 && } - {directory?.directories?.map(d => select({ path: d.name })} {...d}/>)} - {directory?.files?.map(f => )} + {total === 0 + ? + + No files or directories + + + : <> + {subdirectory.length > 0 && } + {directory?.directories?.map(d => select({ path: d.name })} {...d}/>)} + {directory?.files?.map(f => )} + + }
-- cgit v1.2.3 From e4092c57bb98562f897b0abab1d085455205cc44 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Mon, 24 Jul 2023 08:29:21 -0500 Subject: column widths --- src/web/src/components/System/Files/Explorer.js | 6 +++--- src/web/src/components/System/Files/Files.css | 20 ++++++++++++++++---- 2 files changed, 19 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/web/src/components/System/Files/Explorer.js b/src/web/src/components/System/Files/Explorer.js index 2b6715a0..f98f5223 100644 --- a/src/web/src/components/System/Files/Explorer.js +++ b/src/web/src/components/System/Files/Explorer.js @@ -117,9 +117,9 @@ const Explorer = ({ root }) => { - Name - Date Modified - Size + Name + Date Modified + Size diff --git a/src/web/src/components/System/Files/Files.css b/src/web/src/components/System/Files/Files.css index 204475b3..535809dd 100644 --- a/src/web/src/components/System/Files/Files.css +++ b/src/web/src/components/System/Files/Files.css @@ -1,7 +1,19 @@ -.explorer-list-action { - width: 5px !important; +.explorer-working-directory { + margin-top: 7px !important; } -.explorer-working-directory { - margin-top: 0px !important; +.explorer-list-name { + word-wrap: break-word !important; +} + +.explorer-list-size { + width: 100px; +} + +.explorer-list-date { + width: 210px; +} + +.explorer-list-action { + width: 5px !important; } \ No newline at end of file -- cgit v1.2.3 From f3b4f3fc6328c5b56820b93a92d83680e0498833 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 25 Jul 2023 08:03:56 -0500 Subject: fix up dependencies --- src/web/package-lock.json | 133 ++++++++++++++---------- src/web/package.json | 1 + src/web/src/components/System/Files/Explorer.js | 57 +++++----- 3 files changed, 110 insertions(+), 81 deletions(-) (limited to 'src') diff --git a/src/web/package-lock.json b/src/web/package-lock.json index b7a8397c..bfe7f2cd 100644 --- a/src/web/package-lock.json +++ b/src/web/package-lock.json @@ -27,6 +27,7 @@ "yaml": "^1.10.2" }, "devDependencies": { + "@babel/plugin-proposal-private-property-in-object": "^7.21.11", "@craco/craco": "^7.0.0", "@semantic-ui-react/craco-less": "^3.0.0", "@semantic-ui-react/css-patch": "^1.0.0", @@ -111,9 +112,9 @@ } }, "node_modules/@babel/core/node_modules/semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", "dev": true, "bin": { "semver": "bin/semver.js" @@ -147,9 +148,9 @@ } }, "node_modules/@babel/eslint-parser/node_modules/semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", "dev": true, "bin": { "semver": "bin/semver.js" @@ -214,9 +215,9 @@ } }, "node_modules/@babel/helper-compilation-targets/node_modules/semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", "dev": true, "bin": { "semver": "bin/semver.js" @@ -246,9 +247,9 @@ } }, "node_modules/@babel/helper-create-class-features-plugin/node_modules/semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", "dev": true, "bin": { "semver": "bin/semver.js" @@ -272,9 +273,9 @@ } }, "node_modules/@babel/helper-create-regexp-features-plugin/node_modules/semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", "dev": true, "bin": { "semver": "bin/semver.js" @@ -298,9 +299,9 @@ } }, "node_modules/@babel/helper-define-polyfill-provider/node_modules/semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", "dev": true, "bin": { "semver": "bin/semver.js" @@ -761,10 +762,16 @@ } }, "node_modules/@babel/plugin-proposal-private-property-in-object": { - "version": "7.21.0-placeholder-for-preset-env.2", - "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-private-property-in-object/-/plugin-proposal-private-property-in-object-7.21.0-placeholder-for-preset-env.2.tgz", - "integrity": "sha512-SOSkfJDddaM7mak6cPEpswyTRnuRltl429hMraQEglW+OkovnCzsiszTmsrlY//qLFjCpQDFRvjdm2wA5pPm9w==", + "version": "7.21.11", + "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-private-property-in-object/-/plugin-proposal-private-property-in-object-7.21.11.tgz", + "integrity": "sha512-0QZ8qP/3RLDVBwBFoWAwCtgcDZJVwA5LUJRZU8x2YFfKNuFq161wK3cuGrALu5yiPu+vzwTAg/sMWVNeWeNyaw==", "dev": true, + "dependencies": { + "@babel/helper-annotate-as-pure": "^7.18.6", + "@babel/helper-create-class-features-plugin": "^7.21.0", + "@babel/helper-plugin-utils": "^7.20.2", + "@babel/plugin-syntax-private-property-in-object": "^7.14.5" + }, "engines": { "node": ">=6.9.0" }, @@ -1854,9 +1861,9 @@ } }, "node_modules/@babel/plugin-transform-runtime/node_modules/semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", "dev": true, "bin": { "semver": "bin/semver.js" @@ -2113,10 +2120,22 @@ "@babel/core": "^7.0.0-0" } }, + "node_modules/@babel/preset-env/node_modules/@babel/plugin-proposal-private-property-in-object": { + "version": "7.21.0-placeholder-for-preset-env.2", + "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-private-property-in-object/-/plugin-proposal-private-property-in-object-7.21.0-placeholder-for-preset-env.2.tgz", + "integrity": "sha512-SOSkfJDddaM7mak6cPEpswyTRnuRltl429hMraQEglW+OkovnCzsiszTmsrlY//qLFjCpQDFRvjdm2wA5pPm9w==", + "dev": true, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, "node_modules/@babel/preset-env/node_modules/semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", "dev": true, "bin": { "semver": "bin/semver.js" @@ -5274,9 +5293,9 @@ } }, "node_modules/babel-loader/node_modules/semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", "dev": true, "bin": { "semver": "bin/semver.js" @@ -5352,9 +5371,9 @@ } }, "node_modules/babel-plugin-polyfill-corejs2/node_modules/semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", "dev": true, "bin": { "semver": "bin/semver.js" @@ -7693,9 +7712,9 @@ } }, "node_modules/eslint-plugin-import/node_modules/semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", "dev": true, "bin": { "semver": "bin/semver.js" @@ -7756,9 +7775,9 @@ } }, "node_modules/eslint-plugin-jsx-a11y/node_modules/semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", "dev": true, "bin": { "semver": "bin/semver.js" @@ -7835,9 +7854,9 @@ } }, "node_modules/eslint-plugin-react/node_modules/semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", "dev": true, "bin": { "semver": "bin/semver.js" @@ -8482,9 +8501,9 @@ } }, "node_modules/find-cache-dir/node_modules/semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", "dev": true, "bin": { "semver": "bin/semver.js" @@ -10056,9 +10075,9 @@ } }, "node_modules/istanbul-lib-instrument/node_modules/semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", "dev": true, "bin": { "semver": "bin/semver.js" @@ -10094,9 +10113,9 @@ } }, "node_modules/istanbul-lib-report/node_modules/semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", "dev": true, "bin": { "semver": "bin/semver.js" @@ -11865,9 +11884,9 @@ } }, "node_modules/make-dir/node_modules/semver": { - "version": "5.7.1", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", - "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", + "version": "5.7.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.2.tgz", + "integrity": "sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g==", "dev": true, "optional": true, "bin": { @@ -15360,9 +15379,9 @@ } }, "node_modules/semver": { - "version": "7.5.1", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.1.tgz", - "integrity": "sha512-Wvss5ivl8TMRZXXESstBA4uR5iXgEN/VC5/sOcuXdVLzcdkz4HWetIoRfG5gb5X+ij/G9rw9YoGn3QoQ8OCSpw==", + "version": "7.5.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", + "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", "dev": true, "dependencies": { "lru-cache": "^6.0.0" diff --git a/src/web/package.json b/src/web/package.json index 278123bb..c0fd7657 100644 --- a/src/web/package.json +++ b/src/web/package.json @@ -32,6 +32,7 @@ "yaml": "^1.10.2" }, "devDependencies": { + "@babel/plugin-proposal-private-property-in-object": "^7.21.11", "@craco/craco": "^7.0.0", "@semantic-ui-react/craco-less": "^3.0.0", "@semantic-ui-react/css-patch": "^1.0.0", diff --git a/src/web/src/components/System/Files/Explorer.js b/src/web/src/components/System/Files/Explorer.js index f98f5223..093192bf 100644 --- a/src/web/src/components/System/Files/Explorer.js +++ b/src/web/src/components/System/Files/Explorer.js @@ -3,7 +3,6 @@ import React, { useState, useEffect } from 'react'; import { Table, Icon, - Message, Modal, Header, } from 'semantic-ui-react'; @@ -71,7 +70,13 @@ const Explorer = ({ root }) => { ; - const DirectoryRow = ({ name, fullName, modifiedAt, onClick = () => {} }) => + const DirectoryRow = ({ + name, + fullName, + modifiedAt, + onClick = () => {}, + deletable = true, + }) => { {modifiedAt ? formatDate(modifiedAt) : ''} - - } - centered - size='small' - header={
} - content={`Are you sure you want to delete directory '${fullName}'?`} - actions={[ - 'Cancel', - { - key: 'done', - content: 'Delete', - negative: true, - onClick: async () => { - await deleteDirectory({ root, path: `${subdirectory.join('/')}/${fullName}`}); - fetch(); + {deletable + ? + } + centered + size='small' + header={
} + content={`Are you sure you want to delete directory '${fullName}'?`} + actions={[ + 'Cancel', + { + key: 'done', + content: 'Delete', + negative: true, + onClick: async () => { + await deleteDirectory({ root, path: `${subdirectory.join('/')}/${fullName}`}); + fetch(); + }, }, - }, - ]} - /> + ]} + /> + : ''} ; @@ -131,8 +138,10 @@ const Explorer = ({ root }) => { : <> - {subdirectory.length > 0 && } - {directory?.directories?.map(d => select({ path: d.name })} {...d}/>)} + {subdirectory.length > 0 + && } + {directory?.directories?.map(d => select({ path: d.name })} {...d}/>)} {directory?.files?.map(f => )} } -- cgit v1.2.3