1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-14 06:52:36 +01:00
Radarr/NzbDrone.Web/Controllers/DirectoryController.cs

63 lines
1.6 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Web;
2011-06-30 08:15:06 +02: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 08:15:06 +02:00
[HttpGet]
public JsonResult GetDirectories(string term)
{
2011-07-01 22:59:25 +02:00
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 22:59:25 +02:00
}
//Unix
var index = term.LastIndexOf('/');
if (index > -1)
{
dirs = _diskProvider.GetDirectories(term.Substring(0, index + 1));
}
}
2011-06-19 22:43:47 +02:00
catch
{
//Swallow the exceptions so proper JSON is returned to the client (Empty results)
}
2011-07-01 22:59:25 +02:00
return Json(dirs, JsonRequestBehavior.AllowGet);
}
}
}