1
0
Fork 0
mirror of https://github.com/Radarr/Radarr synced 2024-12-25 17:27:59 +00:00
Radarr/NzbDrone.Web/Controllers/DirectoryController.cs
Mark McDowall d330c65165 AutoComplete is now using jQuery UI AutoComplete.
Removed jquery.liveQuery.
2011-09-08 20:26:48 -07:00

62 lines
1.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Helpers;
using System.Web.Mvc;
using NzbDrone.Core.Providers.Core;
namespace NzbDrone.Web.Controllers
{
public class DirectoryController : Controller
{
private readonly DiskProvider _diskProvider;
public DirectoryController(DiskProvider diskProvider)
{
_diskProvider = diskProvider;
}
[HttpPost]
public ActionResult _autoCompletePath(string text, int? filterMode)
{
var data = GetDirectories(text);
return new JsonResult
{
JsonRequestBehavior = JsonRequestBehavior.AllowGet,
Data = data
};
}
[HttpGet]
public JsonResult GetDirectories(string term)
{
string[] dirs = null;
try
{
//Windows (Including UNC)
var windowsSep = term.LastIndexOf('\\');
if (windowsSep > -1)
{
dirs = _diskProvider.GetDirectories(term.Substring(0, windowsSep + 1));
}
//Unix
var index = term.LastIndexOf('/');
if (index > -1)
{
dirs = _diskProvider.GetDirectories(term.Substring(0, index + 1));
}
}
catch
{
//Swallow the exceptions so proper JSON is returned to the client (Empty results)
}
return Json(dirs, JsonRequestBehavior.AllowGet);
}
}
}