1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-14 11:23:42 +02:00
Sonarr/NzbDrone.Web/Controllers/DirectoryController.cs

62 lines
1.6 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Web.Mvc;
2011-11-13 07:07:06 +03:00
using NzbDrone.Common;
namespace NzbDrone.Web.Controllers
{
public class DirectoryController : Controller
{
private readonly DiskProvider _diskProvider;
public DirectoryController(DiskProvider diskProvider)
{
_diskProvider = diskProvider;
}
[HttpPost]
public JsonResult _autoCompletePath(string text, int? filterMode)
{
var data = GetDirectories(text);
return new JsonResult
{
JsonRequestBehavior = JsonRequestBehavior.AllowGet,
Data = data
};
}
2011-06-30 09:15:06 +03:00
[HttpGet]
public JsonResult GetDirectories(string term)
{
IEnumerable<string> dirs = null;
try
{
//Windows (Including UNC)
var windowsSep = term.LastIndexOf('\\');
if (windowsSep > -1)
{
dirs = _diskProvider.GetDirectories(term.Substring(0, windowsSep + 1));
2011-07-01 23:59:25 +03:00
}
//Unix
var index = term.LastIndexOf('/');
if (index > -1)
{
dirs = _diskProvider.GetDirectories(term.Substring(0, index + 1));
}
}
catch (Exception ex)
{
return Json(new List<string>(), JsonRequestBehavior.AllowGet);
//Swallow the exceptions so proper JSON is returned to the client (Empty results)
}
2011-07-01 23:59:25 +03:00
return Json(dirs, JsonRequestBehavior.AllowGet);
}
}
}