sonarr-repo-only/NzbDrone.Web/Controllers/DirectoryController.cs

65 lines
1.8 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
2011-06-30 06:15:06 +00:00
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
};
}
2011-06-30 06:15:06 +00:00
[HttpGet]
public JsonResult GetDirectories(string q)
{
try
{
//Windows (Including UNC)
2011-06-30 06:15:06 +00:00
var windowsSep = q.LastIndexOf('\\');
if (windowsSep > -1)
{
2011-06-30 06:15:06 +00:00
var dirs = _diskProvider.GetDirectories(q.Substring(0, windowsSep + 1));
return Json(dirs, JsonRequestBehavior.AllowGet);
}
2011-06-30 06:15:06 +00:00
return Json(new string[] { }, JsonRequestBehavior.AllowGet);
//Unix
2011-06-30 06:15:06 +00:00
var index = q.LastIndexOf('/');
if (index > -1)
{
2011-06-30 06:15:06 +00:00
var dirs = _diskProvider.GetDirectories(q.Substring(0, index + 1));
//return new SelectList(dirs, dirs.FirstOrDefault());
}
}
2011-06-19 20:43:47 +00:00
catch
{
//Swallow the exceptions so proper JSON is returned to the client (Empty results)
}
2011-06-30 06:15:06 +00:00
return Json(new string[]{}, JsonRequestBehavior.AllowGet);
}
}
}