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