Fix merge conflict

This commit is contained in:
KZ 2015-07-19 21:16:31 +01:00
commit d79dd7e73e
8 changed files with 51 additions and 17 deletions

View File

@ -20,7 +20,7 @@ namespace Jackett.Controllers
private IIndexerManagerService indexerService;
private IServerService serverService;
public AdminController(IConfigurationService config, IIndexerManagerService i, IServerService ss)
public AdminController(IConfigurationService config, IIndexerManagerService i, IServerService ss)
{
this.config = config;
indexerService = i;
@ -67,7 +67,7 @@ namespace Jackett.Controllers
var indexer = indexerService.GetIndexer((string)postData["indexer"]);
jsonReply["name"] = indexer.DisplayName;
await indexer.ApplyConfiguration(postData["config"]);
indexerService.TestIndexer((string)postData["indexer"]);
await indexerService.TestIndexer((string)postData["indexer"]);
jsonReply["result"] = "success";
}
catch (Exception ex)
@ -99,7 +99,7 @@ namespace Jackett.Controllers
foreach (var indexer in indexerService.GetAllIndexers())
{
var item = new JObject();
item["id"] = indexer.GetType().Name;
item["id"] = indexer.ID;
item["name"] = indexer.DisplayName;
item["description"] = indexer.DisplayDescription;
item["configured"] = indexer.IsConfigured;
@ -125,7 +125,7 @@ namespace Jackett.Controllers
{
var postData = await ReadPostDataJson();
string indexerString = (string)postData["indexer"];
indexerService.TestIndexer(indexerString);
await indexerService.TestIndexer(indexerString);
jsonReply["name"] = indexerService.GetIndexer(indexerString).DisplayName;
jsonReply["result"] = "success";
}
@ -187,9 +187,9 @@ namespace Jackett.Controllers
try
{
var postData = await ReadPostDataJson();
// int port = await WebServer.ApplyPortConfiguration(postData);
// int port = await WebServer.ApplyPortConfiguration(postData);
jsonReply["result"] = "success";
// jsonReply["port"] = port;
// jsonReply["port"] = port;
}
catch (Exception ex)
{

View File

@ -7,6 +7,7 @@ using Jackett.Models;
using Newtonsoft.Json.Linq;
using NLog;
using Jackett.Services;
using Jackett.Utils;
namespace Jackett.Indexers
{
@ -14,6 +15,7 @@ namespace Jackett.Indexers
{
public string DisplayDescription { get; private set; }
public string DisplayName { get; private set; }
public string ID { get { return GetIndexerID(GetType()); } }
public bool IsConfigured { get; protected set; }
public Uri SiteLink { get; private set; }
public bool RequiresRageIDLookupDisabled { get; private set; }
@ -24,6 +26,10 @@ namespace Jackett.Indexers
protected static List<CachedResult> cache = new List<CachedResult>();
protected static readonly TimeSpan cacheTime = new TimeSpan(0, 9, 0);
public static string GetIndexerID(Type type)
{
return StringUtil.StripNonAlphaNumeric(type.Name.ToLowerInvariant());
}
public BaseIndexer(string name, string description, bool rageid, Uri link, IIndexerManagerService manager, Logger logger)
{

View File

@ -17,7 +17,7 @@ using System.Threading.Tasks;
using System.Web;
using System.Web.UI.WebControls;
namespace Jackett
namespace Jackett.Indexers
{
public class Freshon : BaseIndexer, IIndexer
{

View File

@ -13,6 +13,8 @@ namespace Jackett.Indexers
{
string DisplayName { get; }
string DisplayDescription { get; }
string ID { get; }
Uri SiteLink { get; }
bool RequiresRageIDLookupDisabled { get; }

View File

@ -197,6 +197,7 @@
<Compile Include="Models\TorznabQuery.cs" />
<Compile Include="CurlHelper.cs" />
<Compile Include="Indexers\AlphaRatio.cs" />
<Compile Include="Utils\StringUtil.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />

View File

@ -9,7 +9,7 @@ using Jackett.Indexers;
namespace Jackett
{
public class JackettModule: Module
public class JackettModule : Module
{
protected override void Load(ContainerBuilder builder)
{
@ -19,12 +19,11 @@ namespace Jackett
builder.RegisterApiControllers(thisAssembly).InstancePerRequest();
// Register indexers
foreach(var indexer in thisAssembly.GetTypes()
foreach (var indexer in thisAssembly.GetTypes()
.Where(p => typeof(IIndexer).IsAssignableFrom(p) && !p.IsInterface)
.ToArray())
{
builder.RegisterType(indexer).Named<IIndexer>(indexer.Name);
builder.RegisterType(indexer).Named<IIndexer>(BaseIndexer.GetIndexerID(indexer));
}
}
}

View File

@ -1,6 +1,7 @@
using Autofac;
using Jackett.Indexers;
using Jackett.Models;
using Jackett.Utils;
using Newtonsoft.Json.Linq;
using NLog;
using System;
@ -14,7 +15,7 @@ namespace Jackett.Services
{
public interface IIndexerManagerService
{
void TestIndexer(string name);
Task TestIndexer(string name);
void DeleteIndexer(string name);
IIndexer GetIndexer(string name);
IEnumerable<IIndexer> GetAllIndexers();
@ -40,7 +41,7 @@ namespace Jackett.Services
{
foreach (var idx in container.Resolve<IEnumerable<IIndexer>>().OrderBy(_ => _.DisplayName))
{
indexers.Add(idx.DisplayName, idx);
indexers.Add(idx.ID, idx);
var configFilePath = GetIndexerConfigFilePath(idx);
if (File.Exists(configFilePath))
{
@ -52,7 +53,7 @@ namespace Jackett.Services
public IIndexer GetIndexer(string name)
{
var indexer = indexers.Values.Where(i => string.Equals(i.DisplayName, name, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();
var indexer = indexers.Values.Where(i => string.Equals(StringUtil.StripNonAlphaNumeric(i.DisplayName), name, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();
if (indexer != null)
{
return indexer;
@ -69,7 +70,7 @@ namespace Jackett.Services
return indexers.Values;
}
public async void TestIndexer(string name)
public async Task TestIndexer(string name)
{
var indexer = GetIndexer(name);
var browseQuery = new TorznabQuery();
@ -84,12 +85,12 @@ namespace Jackett.Services
var indexer = GetIndexer(name);
var configPath = GetIndexerConfigFilePath(indexer);
File.Delete(configPath);
indexers[name] = container.ResolveNamed<IIndexer>(name);
indexers[name] = container.ResolveNamed<IIndexer>(indexer.ID);
}
private string GetIndexerConfigFilePath(IIndexer indexer)
{
return Path.Combine(configService.GetIndexerConfigDir(), indexer.GetType().Name.ToLower() + ".json");
return Path.Combine(configService.GetIndexerConfigDir(), indexer.ID + ".json");
}
public void SaveConfig(IIndexer indexer, JToken obj)

View File

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace Jackett.Utils
{
public static class StringUtil
{
public static string StripNonAlphaNumeric(string str)
{
Regex rgx = new Regex("[^a-zA-Z0-9 -]");
str = rgx.Replace(str, "");
return str;
}
public static string FromBase64(string str)
{
return Encoding.UTF8.GetString(Convert.FromBase64String(str));
}
}
}