You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Prowlarr/NzbDrone.Web/Controllers/DirectoryController.cs

64 lines
1.6 KiB

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