Add LastError to indexer API (#802)

This commit is contained in:
kaso17 2016-12-05 11:43:07 +01:00 committed by GitHub
parent 82ae611c81
commit bb6f56bfa6
4 changed files with 20 additions and 2 deletions

View File

@ -233,6 +233,7 @@ namespace Jackett.Controllers
item["configured"] = indexer.IsConfigured; item["configured"] = indexer.IsConfigured;
item["site_link"] = indexer.SiteLink; item["site_link"] = indexer.SiteLink;
item["language"] = indexer.Language; item["language"] = indexer.Language;
item["last_error"] = indexer.LastError;
item["potatoenabled"] = indexer.TorznabCaps.Categories.Select(c => c.ID).Any(i => PotatoController.MOVIE_CATS.Contains(i)); item["potatoenabled"] = indexer.TorznabCaps.Categories.Select(c => c.ID).Any(i => PotatoController.MOVIE_CATS.Contains(i));
var caps = new JObject(); var caps = new JObject();
@ -257,19 +258,24 @@ namespace Jackett.Controllers
public async Task<IHttpActionResult> Test() public async Task<IHttpActionResult> Test()
{ {
JToken jsonReply = new JObject(); JToken jsonReply = new JObject();
IIndexer indexer = null;
try try
{ {
var postData = await ReadPostDataJson(); var postData = await ReadPostDataJson();
string indexerString = (string)postData["indexer"]; string indexerString = (string)postData["indexer"];
indexer = indexerService.GetIndexer(indexerString);
await indexerService.TestIndexer(indexerString); await indexerService.TestIndexer(indexerString);
jsonReply["name"] = indexerService.GetIndexer(indexerString).DisplayName; jsonReply["name"] = indexer.DisplayName;
jsonReply["result"] = "success"; jsonReply["result"] = "success";
indexer.LastError = null;
} }
catch (Exception ex) catch (Exception ex)
{ {
logger.Error(ex, "Exception in test_indexer"); logger.Error(ex, "Exception in test_indexer");
jsonReply["result"] = "error"; jsonReply["result"] = "error";
jsonReply["error"] = ex.Message; jsonReply["error"] = ex.Message;
if (indexer != null)
indexer.LastError = ex.Message;
} }
return Json(jsonReply); return Json(jsonReply);
} }

View File

@ -39,7 +39,17 @@ namespace Jackett.Indexers
set { configData.CookieHeader.Value = value; } set { configData.CookieHeader.Value = value; }
} }
public string LastError
{
get { return configData.LastError.Value; }
set
{
bool SaveNeeded = configData.LastError.Value != value && IsConfigured;
configData.LastError.Value = value;
if (SaveNeeded)
SaveConfig();
}
}
protected ConfigurationData configData; protected ConfigurationData configData;

View File

@ -17,6 +17,7 @@ namespace Jackett.Indexers
string DisplayName { get; } string DisplayName { get; }
string DisplayDescription { get; } string DisplayDescription { get; }
string Language { get; } string Language { get; }
string LastError { get; set; }
string ID { get; } string ID { get; }
TorznabCapabilities TorznabCaps { get; } TorznabCapabilities TorznabCaps { get; }

View File

@ -26,6 +26,7 @@ namespace Jackett.Models.IndexerConfig
} }
public HiddenItem CookieHeader { get; private set; } = new HiddenItem { Name = "CookieHeader" }; public HiddenItem CookieHeader { get; private set; } = new HiddenItem { Name = "CookieHeader" };
public HiddenItem LastError { get; private set; } = new HiddenItem { Name = "LastError" };
public ConfigurationData() public ConfigurationData()
{ {