mirror of
https://github.com/Jackett/Jackett.git
synced 2025-09-17 17:34:09 +02:00
More robust testing/verification for indexers
This commit is contained in:
@@ -20,9 +20,6 @@ namespace Jackett
|
|||||||
// Called when web API wants to apply setup configuration via web API, usually this is where login and storing cookie happens
|
// Called when web API wants to apply setup configuration via web API, usually this is where login and storing cookie happens
|
||||||
Task ApplyConfiguration(JToken configJson);
|
Task ApplyConfiguration(JToken configJson);
|
||||||
|
|
||||||
// Called to check if configuration (cookie) is correct and indexer connection works
|
|
||||||
Task VerifyConnection();
|
|
||||||
|
|
||||||
// Invoked when the indexer configuration has been applied and verified so the cookie needs to be saved
|
// Invoked when the indexer configuration has been applied and verified so the cookie needs to be saved
|
||||||
event Action<IndexerInterface, JToken> OnSaveConfigurationRequested;
|
event Action<IndexerInterface, JToken> OnSaveConfigurationRequested;
|
||||||
|
|
||||||
|
@@ -85,5 +85,13 @@ namespace Jackett
|
|||||||
LoadMissingIndexers();
|
LoadMissingIndexers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task TestIndexer(IndexerInterface indexer)
|
||||||
|
{
|
||||||
|
var browseQuery = new TorznabQuery();
|
||||||
|
var results = await indexer.PerformQuery(browseQuery);
|
||||||
|
if (results.Length == 0)
|
||||||
|
throw new Exception("Found no results while trying to browse this tracker");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -97,14 +97,6 @@ namespace Jackett.Indexers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task VerifyConnection()
|
|
||||||
{
|
|
||||||
var browseQuery = new TorznabQuery();
|
|
||||||
var results = await PerformQuery(browseQuery);
|
|
||||||
if (results.Length == 0)
|
|
||||||
throw new Exception("Found no results while trying to browse this tracker");
|
|
||||||
}
|
|
||||||
|
|
||||||
public event Action<IndexerInterface, JToken> OnSaveConfigurationRequested;
|
public event Action<IndexerInterface, JToken> OnSaveConfigurationRequested;
|
||||||
|
|
||||||
public bool IsConfigured { get; private set; }
|
public bool IsConfigured { get; private set; }
|
||||||
|
@@ -118,13 +118,6 @@ namespace Jackett
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task VerifyConnection()
|
|
||||||
{
|
|
||||||
var result = await client.GetStringAsync(new Uri(SearchUrl));
|
|
||||||
if (result.Contains("<h1>Not logged in!</h1>"))
|
|
||||||
throw new Exception("Detected as not logged in");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void LoadFromSavedConfiguration(JToken jsonConfig)
|
public void LoadFromSavedConfiguration(JToken jsonConfig)
|
||||||
{
|
{
|
||||||
cookies.FillFromJson(new Uri(BaseUrl), (JArray)jsonConfig["cookies"]);
|
cookies.FillFromJson(new Uri(BaseUrl), (JArray)jsonConfig["cookies"]);
|
||||||
|
@@ -102,16 +102,6 @@ namespace Jackett
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task VerifyConnection()
|
|
||||||
{
|
|
||||||
var message = CreateHttpRequest(new Uri(SearchUrl));
|
|
||||||
|
|
||||||
var response = await client.SendAsync(message);
|
|
||||||
var result = await response.Content.ReadAsStringAsync();
|
|
||||||
if (!result.Contains("/logout.php"))
|
|
||||||
throw new Exception("Detected as not logged in");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void LoadFromSavedConfiguration(JToken jsonConfig)
|
public void LoadFromSavedConfiguration(JToken jsonConfig)
|
||||||
{
|
{
|
||||||
cookies.FillFromJson(new Uri(BaseUrl), (JArray)jsonConfig["cookies"]);
|
cookies.FillFromJson(new Uri(BaseUrl), (JArray)jsonConfig["cookies"]);
|
||||||
|
@@ -111,19 +111,6 @@ namespace Jackett.Indexers
|
|||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task VerifyConnection()
|
|
||||||
{
|
|
||||||
return Task.Run(async () =>
|
|
||||||
{
|
|
||||||
var message = CreateHttpRequest(new Uri(BaseUrl));
|
|
||||||
|
|
||||||
var response = await client.SendAsync(message);
|
|
||||||
var result = await response.Content.ReadAsStringAsync();
|
|
||||||
if (!result.Contains("/my.php"))
|
|
||||||
throw new Exception("Detected as not logged in");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public void LoadFromSavedConfiguration(Newtonsoft.Json.Linq.JToken jsonConfig)
|
public void LoadFromSavedConfiguration(Newtonsoft.Json.Linq.JToken jsonConfig)
|
||||||
{
|
{
|
||||||
cookies.FillFromJson(new Uri(BaseUrl), (JArray)jsonConfig["cookies"]);
|
cookies.FillFromJson(new Uri(BaseUrl), (JArray)jsonConfig["cookies"]);
|
||||||
|
@@ -107,13 +107,6 @@ namespace Jackett.Indexers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task VerifyConnection()
|
|
||||||
{
|
|
||||||
var response = await client.GetStringAsync(BaseUrl);
|
|
||||||
if (!response.Contains("logout.php?"))
|
|
||||||
throw new Exception("Detected as not logged in");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void LoadFromSavedConfiguration(Newtonsoft.Json.Linq.JToken jsonConfig)
|
public void LoadFromSavedConfiguration(Newtonsoft.Json.Linq.JToken jsonConfig)
|
||||||
{
|
{
|
||||||
cookies.FillFromJson(new Uri(BaseUrl), (JArray)jsonConfig["cookies"]);
|
cookies.FillFromJson(new Uri(BaseUrl), (JArray)jsonConfig["cookies"]);
|
||||||
|
@@ -95,12 +95,6 @@ namespace Jackett.Indexers
|
|||||||
IsConfigured = true;
|
IsConfigured = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task VerifyConnection()
|
|
||||||
{
|
|
||||||
await TestBrowse(BaseUrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
async Task TestBrowse(string url)
|
async Task TestBrowse(string url)
|
||||||
{
|
{
|
||||||
var result = await client.GetStringAsync(new Uri(url) + BrowserUrl);
|
var result = await client.GetStringAsync(new Uri(url) + BrowserUrl);
|
||||||
|
@@ -228,7 +228,7 @@ namespace Jackett
|
|||||||
var indexer = indexerManager.GetIndexer(indexerString);
|
var indexer = indexerManager.GetIndexer(indexerString);
|
||||||
jsonReply["name"] = indexer.DisplayName;
|
jsonReply["name"] = indexer.DisplayName;
|
||||||
await indexer.ApplyConfiguration(postData["config"]);
|
await indexer.ApplyConfiguration(postData["config"]);
|
||||||
await indexer.VerifyConnection();
|
await indexerManager.TestIndexer(indexer);
|
||||||
jsonReply["result"] = "success";
|
jsonReply["result"] = "success";
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@@ -281,7 +281,7 @@ namespace Jackett
|
|||||||
string indexerString = (string)postData["indexer"];
|
string indexerString = (string)postData["indexer"];
|
||||||
var indexer = indexerManager.GetIndexer(indexerString);
|
var indexer = indexerManager.GetIndexer(indexerString);
|
||||||
jsonReply["name"] = indexer.DisplayName;
|
jsonReply["name"] = indexer.DisplayName;
|
||||||
await indexer.VerifyConnection();
|
await indexerManager.TestIndexer(indexer);
|
||||||
jsonReply["result"] = "success";
|
jsonReply["result"] = "success";
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
Reference in New Issue
Block a user