1
0
Fork 0
mirror of https://github.com/Sonarr/Sonarr synced 2024-12-30 11:46:09 +00:00
Sonarr/NzbDrone.Web/Controllers/DirectoryController.cs
2011-06-29 23:15:06 -07:00

64 lines
1.8 KiB
C#

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