mirror of
https://github.com/lidarr/Lidarr
synced 2025-02-25 15:22:42 +00:00
Added: Allow folders without trailing slashes in file browser
Co-Authored-By: Mark McDowall <markus101@users.noreply.github.com>
This commit is contained in:
parent
ef107fc63d
commit
36b2942cef
6 changed files with 83 additions and 55 deletions
|
@ -143,22 +143,22 @@ class FileBrowserModalContent extends Component {
|
|||
<TableBody>
|
||||
{
|
||||
emptyParent &&
|
||||
<FileBrowserRow
|
||||
type="computer"
|
||||
name="My Computer"
|
||||
path={parent}
|
||||
onPress={this.onRowPress}
|
||||
/>
|
||||
<FileBrowserRow
|
||||
type="computer"
|
||||
name="My Computer"
|
||||
path={parent}
|
||||
onPress={this.onRowPress}
|
||||
/>
|
||||
}
|
||||
|
||||
{
|
||||
!emptyParent && parent &&
|
||||
<FileBrowserRow
|
||||
type="parent"
|
||||
name="..."
|
||||
path={parent}
|
||||
onPress={this.onRowPress}
|
||||
/>
|
||||
<FileBrowserRow
|
||||
type="parent"
|
||||
name="..."
|
||||
path={parent}
|
||||
onPress={this.onRowPress}
|
||||
/>
|
||||
}
|
||||
|
||||
{
|
||||
|
|
|
@ -48,14 +48,20 @@ class FileBrowserModalContentConnector extends Component {
|
|||
// Lifecycle
|
||||
|
||||
componentDidMount() {
|
||||
this.props.fetchPaths({ path: this.props.value });
|
||||
this.props.fetchPaths({
|
||||
path: this.props.value,
|
||||
allowFoldersWithoutTrailingSlashes: true
|
||||
});
|
||||
}
|
||||
|
||||
//
|
||||
// Listeners
|
||||
|
||||
onFetchPaths = (path) => {
|
||||
this.props.fetchPaths({ path });
|
||||
this.props.fetchPaths({
|
||||
path,
|
||||
allowFoldersWithoutTrailingSlashes: true
|
||||
});
|
||||
}
|
||||
|
||||
onClearPaths = () => {
|
||||
|
|
|
@ -44,15 +44,21 @@ export const actionHandlers = handleThunks({
|
|||
[FETCH_PATHS]: function(getState, payload, dispatch) {
|
||||
dispatch(set({ section, isFetching: true }));
|
||||
|
||||
const {
|
||||
path,
|
||||
allowFoldersWithoutTrailingSlashes = false
|
||||
} = payload;
|
||||
|
||||
const promise = $.ajax({
|
||||
url: '/filesystem',
|
||||
data: {
|
||||
path: payload.path
|
||||
path,
|
||||
allowFoldersWithoutTrailingSlashes
|
||||
}
|
||||
});
|
||||
|
||||
promise.done((data) => {
|
||||
dispatch(updatePaths({ path: payload.path, ...data }));
|
||||
dispatch(updatePaths({ path, ...data }));
|
||||
|
||||
dispatch(set({
|
||||
section,
|
||||
|
|
|
@ -32,9 +32,9 @@ private Response GetContents()
|
|||
{
|
||||
var pathQuery = Request.Query.path;
|
||||
var includeFiles = Request.GetBooleanQueryParameter("includeFiles");
|
||||
var allowFoldersWithoutTrailingSlashes = Request.GetBooleanQueryParameter("allowFoldersWithoutTrailingSlashes");
|
||||
|
||||
|
||||
return _fileSystemLookupService.LookupContents((string)pathQuery.Value, includeFiles).AsResponse();
|
||||
return _fileSystemLookupService.LookupContents((string)pathQuery.Value, includeFiles, allowFoldersWithoutTrailingSlashes).AsResponse();
|
||||
}
|
||||
|
||||
private Response GetEntityType()
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using FluentAssertions;
|
||||
|
@ -49,7 +49,7 @@ public void should_not_contain_recycling_bin_for_root_of_drive()
|
|||
.Setup(s => s.GetDirectoryInfos(It.IsAny<string>()))
|
||||
.Returns(_folders);
|
||||
|
||||
Subject.LookupContents(root, false).Directories.Should().NotContain(Path.Combine(root, RECYCLING_BIN));
|
||||
Subject.LookupContents(root, false, false).Directories.Should().NotContain(Path.Combine(root, RECYCLING_BIN));
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@ -62,7 +62,7 @@ public void should_not_contain_system_volume_information()
|
|||
.Setup(s => s.GetDirectoryInfos(It.IsAny<string>()))
|
||||
.Returns(_folders);
|
||||
|
||||
Subject.LookupContents(root, false).Directories.Should().NotContain(Path.Combine(root, SYSTEM_VOLUME_INFORMATION));
|
||||
Subject.LookupContents(root, false, false).Directories.Should().NotContain(Path.Combine(root, SYSTEM_VOLUME_INFORMATION));
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@ -75,8 +75,8 @@ public void should_not_contain_recycling_bin_or_system_volume_information_for_ro
|
|||
.Setup(s => s.GetDirectoryInfos(It.IsAny<string>()))
|
||||
.Returns(_folders);
|
||||
|
||||
var result = Subject.LookupContents(root, false);
|
||||
|
||||
var result = Subject.LookupContents(root, false, false);
|
||||
|
||||
result.Directories.Should().HaveCount(_folders.Count - 3);
|
||||
|
||||
result.Directories.Should().NotContain(f => f.Name == RECYCLING_BIN);
|
||||
|
|
|
@ -9,7 +9,7 @@ namespace NzbDrone.Common.Disk
|
|||
{
|
||||
public interface IFileSystemLookupService
|
||||
{
|
||||
FileSystemResult LookupContents(string query, bool includeFiles);
|
||||
FileSystemResult LookupContents(string query, bool includeFiles, bool allowFoldersWithoutTrailingSlashes);
|
||||
}
|
||||
|
||||
public class FileSystemLookupService : IFileSystemLookupService
|
||||
|
@ -51,14 +51,13 @@ public FileSystemLookupService(IDiskProvider diskProvider)
|
|||
_diskProvider = diskProvider;
|
||||
}
|
||||
|
||||
public FileSystemResult LookupContents(string query, bool includeFiles)
|
||||
public FileSystemResult LookupContents(string query, bool includeFiles, bool allowFoldersWithoutTrailingSlashes)
|
||||
{
|
||||
var result = new FileSystemResult();
|
||||
|
||||
if (query.IsNullOrWhiteSpace())
|
||||
{
|
||||
if (OsInfo.IsWindows)
|
||||
{
|
||||
var result = new FileSystemResult();
|
||||
result.Directories = GetDrives();
|
||||
|
||||
return result;
|
||||
|
@ -67,41 +66,23 @@ public FileSystemResult LookupContents(string query, bool includeFiles)
|
|||
query = "/";
|
||||
}
|
||||
|
||||
if (
|
||||
allowFoldersWithoutTrailingSlashes &&
|
||||
query.IsPathValid() &&
|
||||
_diskProvider.FolderExists(query))
|
||||
{
|
||||
return GetResult(query, includeFiles);
|
||||
}
|
||||
|
||||
var lastSeparatorIndex = query.LastIndexOf(Path.DirectorySeparatorChar);
|
||||
var path = query.Substring(0, lastSeparatorIndex + 1);
|
||||
|
||||
if (lastSeparatorIndex != -1)
|
||||
{
|
||||
try
|
||||
{
|
||||
result.Parent = GetParent(path);
|
||||
result.Directories = GetDirectories(path);
|
||||
|
||||
if (includeFiles)
|
||||
{
|
||||
result.Files = GetFiles(path);
|
||||
}
|
||||
}
|
||||
|
||||
catch (DirectoryNotFoundException)
|
||||
{
|
||||
return new FileSystemResult { Parent = GetParent(path) };
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
return new FileSystemResult();
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
return new FileSystemResult { Parent = GetParent(path) };
|
||||
}
|
||||
catch (UnauthorizedAccessException)
|
||||
{
|
||||
return new FileSystemResult { Parent = GetParent(path) };
|
||||
}
|
||||
return GetResult(path, includeFiles);
|
||||
}
|
||||
|
||||
return result;
|
||||
return new FileSystemResult();
|
||||
}
|
||||
|
||||
private List<FileSystemModel> GetDrives()
|
||||
|
@ -117,6 +98,41 @@ private List<FileSystemModel> GetDrives()
|
|||
.ToList();
|
||||
}
|
||||
|
||||
private FileSystemResult GetResult(string path, bool includeFiles)
|
||||
{
|
||||
var result = new FileSystemResult();
|
||||
|
||||
try
|
||||
{
|
||||
result.Parent = GetParent(path);
|
||||
result.Directories = GetDirectories(path);
|
||||
|
||||
if (includeFiles)
|
||||
{
|
||||
result.Files = GetFiles(path);
|
||||
}
|
||||
}
|
||||
|
||||
catch (DirectoryNotFoundException)
|
||||
{
|
||||
return new FileSystemResult { Parent = GetParent(path) };
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
return new FileSystemResult();
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
return new FileSystemResult { Parent = GetParent(path) };
|
||||
}
|
||||
catch (UnauthorizedAccessException)
|
||||
{
|
||||
return new FileSystemResult { Parent = GetParent(path) };
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<FileSystemModel> GetDirectories(string path)
|
||||
{
|
||||
var directories = _diskProvider.GetDirectoryInfos(path)
|
||||
|
|
Loading…
Reference in a new issue