mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-14 02:37:08 -07:00
Added auto complete to AddSeries RootDir
This commit is contained in:
parent
7ed148b12c
commit
7f0dc84b29
7 changed files with 86 additions and 1 deletions
60
NzbDrone.Api/Directories/DirectoryModule.cs
Normal file
60
NzbDrone.Api/Directories/DirectoryModule.cs
Normal file
|
@ -0,0 +1,60 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Nancy;
|
||||
using NzbDrone.Api.Extentions;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.RootFolders;
|
||||
|
||||
namespace NzbDrone.Api.Directories
|
||||
{
|
||||
public class DirectoryModule : NzbDroneApiModule
|
||||
{
|
||||
private readonly DiskProvider _diskProvider;
|
||||
|
||||
public DirectoryModule(DiskProvider diskProvider)
|
||||
: base("/directories")
|
||||
{
|
||||
_diskProvider = diskProvider;
|
||||
Post["/"] = x => GetDirectories();
|
||||
}
|
||||
|
||||
private Response GetDirectories()
|
||||
{
|
||||
if (!Request.Form.query.HasValue)
|
||||
return new List<string>().AsResponse();
|
||||
|
||||
string query = Request.Form.query.Value;
|
||||
|
||||
IEnumerable<String> dirs = null;
|
||||
try
|
||||
{
|
||||
//Windows (Including UNC)
|
||||
var windowsSep = query.LastIndexOf('\\');
|
||||
|
||||
if (windowsSep > -1)
|
||||
{
|
||||
dirs = _diskProvider.GetDirectories(query.Substring(0, windowsSep + 1));
|
||||
}
|
||||
|
||||
//Unix
|
||||
var index = query.LastIndexOf('/');
|
||||
|
||||
if (index > -1)
|
||||
{
|
||||
dirs = _diskProvider.GetDirectories(query.Substring(0, index + 1));
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//Swallow the exceptions so proper JSON is returned to the client (Empty results)
|
||||
return new List<string>().AsResponse();
|
||||
}
|
||||
|
||||
if (dirs == null)
|
||||
throw new Exception("A valid path was not provided");
|
||||
|
||||
return dirs.AsResponse();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue