Added: Allow folders without trailing slashes in file browser

Co-Authored-By: Mark McDowall <markus101@users.noreply.github.com>
This commit is contained in:
Qstick 2018-08-10 20:46:34 -04:00
parent ef107fc63d
commit 36b2942cef
6 changed files with 83 additions and 55 deletions

View file

@ -48,14 +48,20 @@ class FileBrowserModalContentConnector extends Component {
// Lifecycle // Lifecycle
componentDidMount() { componentDidMount() {
this.props.fetchPaths({ path: this.props.value }); this.props.fetchPaths({
path: this.props.value,
allowFoldersWithoutTrailingSlashes: true
});
} }
// //
// Listeners // Listeners
onFetchPaths = (path) => { onFetchPaths = (path) => {
this.props.fetchPaths({ path }); this.props.fetchPaths({
path,
allowFoldersWithoutTrailingSlashes: true
});
} }
onClearPaths = () => { onClearPaths = () => {

View file

@ -44,15 +44,21 @@ export const actionHandlers = handleThunks({
[FETCH_PATHS]: function(getState, payload, dispatch) { [FETCH_PATHS]: function(getState, payload, dispatch) {
dispatch(set({ section, isFetching: true })); dispatch(set({ section, isFetching: true }));
const {
path,
allowFoldersWithoutTrailingSlashes = false
} = payload;
const promise = $.ajax({ const promise = $.ajax({
url: '/filesystem', url: '/filesystem',
data: { data: {
path: payload.path path,
allowFoldersWithoutTrailingSlashes
} }
}); });
promise.done((data) => { promise.done((data) => {
dispatch(updatePaths({ path: payload.path, ...data })); dispatch(updatePaths({ path, ...data }));
dispatch(set({ dispatch(set({
section, section,

View file

@ -32,9 +32,9 @@ namespace Lidarr.Api.V1.FileSystem
{ {
var pathQuery = Request.Query.path; var pathQuery = Request.Query.path;
var includeFiles = Request.GetBooleanQueryParameter("includeFiles"); var includeFiles = Request.GetBooleanQueryParameter("includeFiles");
var allowFoldersWithoutTrailingSlashes = Request.GetBooleanQueryParameter("allowFoldersWithoutTrailingSlashes");
return _fileSystemLookupService.LookupContents((string)pathQuery.Value, includeFiles, allowFoldersWithoutTrailingSlashes).AsResponse();
return _fileSystemLookupService.LookupContents((string)pathQuery.Value, includeFiles).AsResponse();
} }
private Response GetEntityType() private Response GetEntityType()

View file

@ -1,4 +1,4 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using FluentAssertions; using FluentAssertions;
@ -49,7 +49,7 @@ namespace NzbDrone.Common.Test.DiskTests
.Setup(s => s.GetDirectoryInfos(It.IsAny<string>())) .Setup(s => s.GetDirectoryInfos(It.IsAny<string>()))
.Returns(_folders); .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] [Test]
@ -62,7 +62,7 @@ namespace NzbDrone.Common.Test.DiskTests
.Setup(s => s.GetDirectoryInfos(It.IsAny<string>())) .Setup(s => s.GetDirectoryInfos(It.IsAny<string>()))
.Returns(_folders); .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] [Test]
@ -75,7 +75,7 @@ namespace NzbDrone.Common.Test.DiskTests
.Setup(s => s.GetDirectoryInfos(It.IsAny<string>())) .Setup(s => s.GetDirectoryInfos(It.IsAny<string>()))
.Returns(_folders); .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().HaveCount(_folders.Count - 3);

View file

@ -9,7 +9,7 @@ namespace NzbDrone.Common.Disk
{ {
public interface IFileSystemLookupService public interface IFileSystemLookupService
{ {
FileSystemResult LookupContents(string query, bool includeFiles); FileSystemResult LookupContents(string query, bool includeFiles, bool allowFoldersWithoutTrailingSlashes);
} }
public class FileSystemLookupService : IFileSystemLookupService public class FileSystemLookupService : IFileSystemLookupService
@ -51,14 +51,13 @@ namespace NzbDrone.Common.Disk
_diskProvider = 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 (query.IsNullOrWhiteSpace())
{ {
if (OsInfo.IsWindows) if (OsInfo.IsWindows)
{ {
var result = new FileSystemResult();
result.Directories = GetDrives(); result.Directories = GetDrives();
return result; return result;
@ -67,11 +66,42 @@ namespace NzbDrone.Common.Disk
query = "/"; query = "/";
} }
if (
allowFoldersWithoutTrailingSlashes &&
query.IsPathValid() &&
_diskProvider.FolderExists(query))
{
return GetResult(query, includeFiles);
}
var lastSeparatorIndex = query.LastIndexOf(Path.DirectorySeparatorChar); var lastSeparatorIndex = query.LastIndexOf(Path.DirectorySeparatorChar);
var path = query.Substring(0, lastSeparatorIndex + 1); var path = query.Substring(0, lastSeparatorIndex + 1);
if (lastSeparatorIndex != -1) if (lastSeparatorIndex != -1)
{ {
return GetResult(path, includeFiles);
}
return new FileSystemResult();
}
private List<FileSystemModel> GetDrives()
{
return _diskProvider.GetMounts()
.Select(d => new FileSystemModel
{
Type = FileSystemEntityType.Drive,
Name = d.VolumeName,
Path = d.RootDirectory,
LastModified = null
})
.ToList();
}
private FileSystemResult GetResult(string path, bool includeFiles)
{
var result = new FileSystemResult();
try try
{ {
result.Parent = GetParent(path); result.Parent = GetParent(path);
@ -99,24 +129,10 @@ namespace NzbDrone.Common.Disk
{ {
return new FileSystemResult { Parent = GetParent(path) }; return new FileSystemResult { Parent = GetParent(path) };
} }
}
return result; return result;
} }
private List<FileSystemModel> GetDrives()
{
return _diskProvider.GetMounts()
.Select(d => new FileSystemModel
{
Type = FileSystemEntityType.Drive,
Name = d.VolumeName,
Path = d.RootDirectory,
LastModified = null
})
.ToList();
}
private List<FileSystemModel> GetDirectories(string path) private List<FileSystemModel> GetDirectories(string path)
{ {
var directories = _diskProvider.GetDirectoryInfos(path) var directories = _diskProvider.GetDirectoryInfos(path)