2012-01-19 06:01:47 +01:00
|
|
|
|
using System.Web.Mvc;
|
2011-12-02 02:33:17 +01:00
|
|
|
|
using NzbDrone.Core.Jobs;
|
2011-08-26 19:45:59 +02:00
|
|
|
|
using NzbDrone.Core.Providers;
|
2012-02-07 06:08:07 +01:00
|
|
|
|
using NzbDrone.Core.Providers.DownloadClients;
|
2012-01-19 06:01:47 +01:00
|
|
|
|
using NzbDrone.Web.Filters;
|
2011-08-26 19:45:59 +02:00
|
|
|
|
using NzbDrone.Web.Models;
|
2012-02-07 09:12:37 +01:00
|
|
|
|
using System;
|
2011-08-06 04:04:35 +02:00
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Web.Controllers
|
|
|
|
|
{
|
|
|
|
|
public class CommandController : Controller
|
|
|
|
|
{
|
|
|
|
|
private readonly JobProvider _jobProvider;
|
2011-08-26 19:45:59 +02:00
|
|
|
|
private readonly SabProvider _sabProvider;
|
2011-10-27 07:46:54 +02:00
|
|
|
|
private readonly SmtpProvider _smtpProvider;
|
2011-10-28 09:57:00 +02:00
|
|
|
|
private readonly TwitterProvider _twitterProvider;
|
2012-02-04 23:05:56 +01:00
|
|
|
|
private readonly EpisodeProvider _episodeProvider;
|
2012-02-07 09:12:37 +01:00
|
|
|
|
private readonly GrowlProvider _growlProvider;
|
2011-08-06 04:04:35 +02:00
|
|
|
|
|
2011-10-27 07:46:54 +02:00
|
|
|
|
public CommandController(JobProvider jobProvider, SabProvider sabProvider,
|
2012-02-04 23:05:56 +01:00
|
|
|
|
SmtpProvider smtpProvider, TwitterProvider twitterProvider,
|
2012-02-07 09:12:37 +01:00
|
|
|
|
EpisodeProvider episodeProvider, GrowlProvider growlProvider)
|
2011-08-06 04:04:35 +02:00
|
|
|
|
{
|
|
|
|
|
_jobProvider = jobProvider;
|
2011-08-26 19:45:59 +02:00
|
|
|
|
_sabProvider = sabProvider;
|
2011-10-27 07:46:54 +02:00
|
|
|
|
_smtpProvider = smtpProvider;
|
2011-10-28 09:57:00 +02:00
|
|
|
|
_twitterProvider = twitterProvider;
|
2012-02-04 23:05:56 +01:00
|
|
|
|
_episodeProvider = episodeProvider;
|
2012-02-07 09:12:37 +01:00
|
|
|
|
_growlProvider = growlProvider;
|
2011-08-06 04:04:35 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public JsonResult RssSync()
|
|
|
|
|
{
|
|
|
|
|
_jobProvider.QueueJob(typeof(RssSyncJob));
|
2012-01-19 06:01:47 +01:00
|
|
|
|
return JsonNotificationResult.Info("Queued");
|
2011-08-06 04:04:35 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-10-22 01:33:54 +02:00
|
|
|
|
public JsonResult BacklogSearch()
|
|
|
|
|
{
|
|
|
|
|
_jobProvider.QueueJob(typeof(BacklogSearchJob));
|
2012-01-19 06:01:47 +01:00
|
|
|
|
return JsonNotificationResult.Info("Queued");
|
2011-10-22 01:33:54 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-25 02:21:20 +01:00
|
|
|
|
public JsonResult RecentBacklogSearch()
|
|
|
|
|
{
|
|
|
|
|
_jobProvider.QueueJob(typeof(RecentBacklogSearchJob));
|
|
|
|
|
return JsonNotificationResult.Info("Queued");
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-26 08:53:16 +01:00
|
|
|
|
public JsonResult ScanDisk(int seriesId)
|
2011-08-06 04:04:35 +02:00
|
|
|
|
{
|
|
|
|
|
_jobProvider.QueueJob(typeof(DiskScanJob), seriesId);
|
2012-01-19 06:01:47 +01:00
|
|
|
|
return JsonNotificationResult.Info("Queued");
|
2011-08-06 04:04:35 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public JsonResult UpdateInfo(int seriesId)
|
|
|
|
|
{
|
|
|
|
|
_jobProvider.QueueJob(typeof(UpdateInfoJob), seriesId);
|
2012-01-19 06:01:47 +01:00
|
|
|
|
return JsonNotificationResult.Info("Queued");
|
2011-08-06 04:04:35 +02:00
|
|
|
|
}
|
2011-08-26 19:45:59 +02:00
|
|
|
|
|
|
|
|
|
[HttpPost]
|
2012-01-19 06:01:47 +01:00
|
|
|
|
[JsonErrorFilter]
|
2011-08-26 19:45:59 +02:00
|
|
|
|
public JsonResult GetSabnzbdCategories(string host, int port, string apiKey, string username, string password)
|
|
|
|
|
{
|
2012-01-19 06:01:47 +01:00
|
|
|
|
return new JsonResult { Data = _sabProvider.GetCategories(host, port, apiKey, username, password) };
|
2011-08-26 19:45:59 +02:00
|
|
|
|
}
|
2011-10-27 07:46:54 +02:00
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public JsonResult SendTestEmail(string server, int port, bool ssl, string username, string password, string fromAddress, string toAddresses)
|
|
|
|
|
{
|
|
|
|
|
if (_smtpProvider.SendTestEmail(server, port, ssl, username, password, fromAddress, toAddresses))
|
2012-01-19 06:01:47 +01:00
|
|
|
|
JsonNotificationResult.Info("Successfull", "Test email sent.");
|
2011-10-27 07:46:54 +02:00
|
|
|
|
|
2012-02-23 23:31:50 +01:00
|
|
|
|
return JsonNotificationResult.Oops("Couldn't send Email, please check your settings");
|
2011-10-27 07:46:54 +02:00
|
|
|
|
}
|
2011-10-28 09:57:00 +02:00
|
|
|
|
|
|
|
|
|
public JsonResult GetTwitterAuthorization()
|
|
|
|
|
{
|
|
|
|
|
var result = _twitterProvider.GetAuthorization();
|
|
|
|
|
|
|
|
|
|
if (result == null)
|
2012-02-23 23:31:50 +01:00
|
|
|
|
JsonNotificationResult.Oops("Couldn't get Twitter Authorization");
|
2011-10-28 09:57:00 +02:00
|
|
|
|
|
|
|
|
|
return new JsonResult { Data = result, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public JsonResult VerifyTwitterAuthorization(string token, string verifier)
|
|
|
|
|
{
|
|
|
|
|
var result = _twitterProvider.GetAndSaveAccessToken(token, verifier);
|
|
|
|
|
|
|
|
|
|
if (!result)
|
2012-02-23 23:31:50 +01:00
|
|
|
|
JsonNotificationResult.Oops("Couldn't verify Twitter Authorization");
|
2012-01-19 06:01:47 +01:00
|
|
|
|
|
|
|
|
|
return JsonNotificationResult.Info("Good News!", "Successfully verified Twitter Authorization.");
|
2011-10-28 09:57:00 +02:00
|
|
|
|
|
|
|
|
|
}
|
2012-02-04 23:05:56 +01:00
|
|
|
|
|
2012-02-07 09:12:37 +01:00
|
|
|
|
public JsonResult RegisterGrowl(string host, string password)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var split = host.Split(':');
|
|
|
|
|
var hostname = split[0];
|
|
|
|
|
var port = Convert.ToInt32(split[1]);
|
|
|
|
|
|
|
|
|
|
_growlProvider.Register(hostname, port, password);
|
|
|
|
|
_growlProvider.TestNotification(hostname, port, password);
|
|
|
|
|
|
|
|
|
|
return JsonNotificationResult.Info("Good News!", "Registered and tested growl successfully");
|
|
|
|
|
}
|
|
|
|
|
catch(Exception ex)
|
|
|
|
|
{
|
2012-02-23 23:31:50 +01:00
|
|
|
|
return JsonNotificationResult.Oops("Couldn't register and test Growl");
|
2012-02-07 09:12:37 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-04 23:05:56 +01:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public EmptyResult SaveSeasonIgnore(int seriesId, int seasonNumber, bool ignored)
|
|
|
|
|
{
|
|
|
|
|
_episodeProvider.SetSeasonIgnore(seriesId, seasonNumber, ignored);
|
|
|
|
|
return new EmptyResult();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public EmptyResult SaveEpisodeIgnore(int episodeId, bool ignored)
|
|
|
|
|
{
|
|
|
|
|
_episodeProvider.SetEpisodeIgnore(episodeId, ignored);
|
|
|
|
|
return new EmptyResult();
|
|
|
|
|
}
|
2011-08-06 04:04:35 +02:00
|
|
|
|
}
|
|
|
|
|
}
|