2013-08-04 17:26:37 +00:00
|
|
|
|
using System.Collections.Generic;
|
2013-08-03 03:01:16 +00:00
|
|
|
|
using System.Linq;
|
2013-02-06 06:28:56 +00:00
|
|
|
|
using Nancy;
|
2013-02-23 20:35:26 +00:00
|
|
|
|
using NzbDrone.Api.Extensions;
|
2013-02-06 06:28:56 +00:00
|
|
|
|
using NzbDrone.Common;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Api.Directories
|
|
|
|
|
{
|
|
|
|
|
public class DirectoryModule : NzbDroneApiModule
|
|
|
|
|
{
|
2013-08-03 03:01:16 +00:00
|
|
|
|
private readonly IDirectoryLookupService _directoryLookupService;
|
2013-02-06 06:28:56 +00:00
|
|
|
|
|
2013-08-03 03:01:16 +00:00
|
|
|
|
public DirectoryModule(IDirectoryLookupService directoryLookupService)
|
2013-02-06 06:28:56 +00:00
|
|
|
|
: base("/directories")
|
|
|
|
|
{
|
2013-08-03 03:01:16 +00:00
|
|
|
|
_directoryLookupService = directoryLookupService;
|
2013-02-15 23:38:53 +00:00
|
|
|
|
Get["/"] = x => GetDirectories();
|
2013-02-06 06:28:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Response GetDirectories()
|
|
|
|
|
{
|
2013-02-15 23:38:53 +00:00
|
|
|
|
if (!Request.Query.query.HasValue)
|
2013-02-06 06:28:56 +00:00
|
|
|
|
return new List<string>().AsResponse();
|
|
|
|
|
|
2013-02-15 23:38:53 +00:00
|
|
|
|
string query = Request.Query.query.Value;
|
2013-02-06 06:28:56 +00:00
|
|
|
|
|
2013-08-04 17:26:37 +00:00
|
|
|
|
var dirs = _directoryLookupService.LookupSubDirectories(query)
|
|
|
|
|
.Select(p => p.GetActualCasing())
|
|
|
|
|
.ToList();
|
2013-02-06 06:28:56 +00:00
|
|
|
|
|
|
|
|
|
return dirs.AsResponse();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|