mirror of
https://github.com/Jackett/Jackett
synced 2025-03-10 06:03:09 +00:00
More robust testing/verification for indexers
This commit is contained in:
parent
c351cebdfc
commit
ac003e7a78
9 changed files with 10 additions and 56 deletions
|
@ -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
|
||||
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
|
||||
event Action<IndexerInterface, JToken> OnSaveConfigurationRequested;
|
||||
|
||||
|
|
|
@ -85,5 +85,13 @@ namespace Jackett
|
|||
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 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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
cookies.FillFromJson(new Uri(BaseUrl), (JArray)jsonConfig["cookies"]);
|
||||
|
|
|
@ -111,19 +111,6 @@ namespace Jackett.Indexers
|
|||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
cookies.FillFromJson(new Uri(BaseUrl), (JArray)jsonConfig["cookies"]);
|
||||
|
|
|
@ -95,12 +95,6 @@ namespace Jackett.Indexers
|
|||
IsConfigured = true;
|
||||
}
|
||||
|
||||
public async Task VerifyConnection()
|
||||
{
|
||||
await TestBrowse(BaseUrl);
|
||||
}
|
||||
|
||||
|
||||
async Task TestBrowse(string url)
|
||||
{
|
||||
var result = await client.GetStringAsync(new Uri(url) + BrowserUrl);
|
||||
|
|
|
@ -228,7 +228,7 @@ namespace Jackett
|
|||
var indexer = indexerManager.GetIndexer(indexerString);
|
||||
jsonReply["name"] = indexer.DisplayName;
|
||||
await indexer.ApplyConfiguration(postData["config"]);
|
||||
await indexer.VerifyConnection();
|
||||
await indexerManager.TestIndexer(indexer);
|
||||
jsonReply["result"] = "success";
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -281,7 +281,7 @@ namespace Jackett
|
|||
string indexerString = (string)postData["indexer"];
|
||||
var indexer = indexerManager.GetIndexer(indexerString);
|
||||
jsonReply["name"] = indexer.DisplayName;
|
||||
await indexer.VerifyConnection();
|
||||
await indexerManager.TestIndexer(indexer);
|
||||
jsonReply["result"] = "success";
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
Loading…
Add table
Reference in a new issue