Bugfix/1532 1539 fix manual search circular reference (#1543)

* Line endings...

* Encoding Encoding in a reasonable way

Sadly Encoding contains a self-reference somewhere, which makes it
really hard for the json serializer to automatically encode it...
Probably there's no value in sending it over especially since no one is
using it, however just for the sake of the argument, let's just
serialize it in a reasonable way. Maybe someday there will be someone
expecting this. Or we clearly separate DTOs and models...

- Fixes Jackett/Jackett#1532
- Fixes Jackett/Jackett#1539

* Seriously... Please port this to dotnet Core so that I can use something other than @drunkvs on my MacBook

* Fix autofac registration after merge

* "Implement" new function of interface in test project
This commit is contained in:
chibidev
2017-07-11 22:32:56 +02:00
committed by kaso17
parent fb59e84def
commit 17f544be36
6 changed files with 164 additions and 85 deletions

View File

@@ -28,6 +28,11 @@ namespace JackettTest
throw new NotImplementedException(); throw new NotImplementedException();
} }
public IWebIndexer GetWebIndexer(string name)
{
throw new NotImplementedException();
}
public void InitIndexers() public void InitIndexers()
{ {
throw new NotImplementedException(); throw new NotImplementedException();

View File

@@ -96,11 +96,25 @@ Global
$2.SpacesBeforeBrackets = False $2.SpacesBeforeBrackets = False
$2.scope = text/x-csharp $2.scope = text/x-csharp
$2.IndentSwitchSection = True $2.IndentSwitchSection = True
$2.NewLinesForBracesInProperties = True
$2.NewLinesForBracesInAccessors = True
$2.NewLinesForBracesInAnonymousMethods = True
$2.NewLinesForBracesInControlBlocks = True
$2.NewLinesForBracesInAnonymousTypes = True
$2.NewLinesForBracesInObjectCollectionArrayInitializers = True
$2.NewLinesForBracesInLambdaExpressionBody = True
$2.NewLineForElse = True
$2.NewLineForCatch = True
$2.NewLineForFinally = True
$2.NewLineForMembersInObjectInit = True
$2.NewLineForMembersInAnonymousTypes = True
$2.NewLineForClausesInQuery = True
$2.SpacingAfterMethodDeclarationName = False $2.SpacingAfterMethodDeclarationName = False
$2.SpaceAfterMethodCallName = False $2.SpaceAfterMethodCallName = False
$2.SpaceBeforeOpenSquareBracket = False $2.SpaceBeforeOpenSquareBracket = False
$0.DotNetNamingPolicy = $3 $0.TextStylePolicy = $3
$3.DirectoryNamespaceAssociation = PrefixedHierarchical $3.FileWidth = 80
$0.StandardHeader = $4 $3.TabsToSpaces = True
$3.scope = text/plain
EndGlobalSection EndGlobalSection
EndGlobal EndGlobal

View File

@@ -12,6 +12,7 @@ using Jackett.Utils.Clients;
using AutoMapper; using AutoMapper;
using Jackett.Models.IndexerConfig; using Jackett.Models.IndexerConfig;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Newtonsoft.Json;
namespace Jackett.Indexers namespace Jackett.Indexers
{ {
@@ -691,6 +692,8 @@ namespace Jackett.Indexers
} }
public override TorznabCapabilities TorznabCaps { get; protected set; } public override TorznabCapabilities TorznabCaps { get; protected set; }
[JsonConverter(typeof(EncodingJsonConverter))]
public Encoding Encoding { get; protected set; } public Encoding Encoding { get; protected set; }
private List<CategoryMapping> categoryMapping = new List<CategoryMapping>(); private List<CategoryMapping> categoryMapping = new List<CategoryMapping>();

View File

@@ -377,6 +377,7 @@
<Compile Include="Indexers\Meta\ResultFilters.cs" /> <Compile Include="Indexers\Meta\ResultFilters.cs" />
<Compile Include="Services\ImdbResolver.cs" /> <Compile Include="Services\ImdbResolver.cs" />
<Compile Include="Utils\Extensions.cs" /> <Compile Include="Utils\Extensions.cs" />
<Compile Include="Utils\JsonUtil.cs" />
<Compile Include="Services\IndexerConfigurationService.cs" /> <Compile Include="Services\IndexerConfigurationService.cs" />
<Compile Include="Models\IndexerDefinition.cs" /> <Compile Include="Models\IndexerDefinition.cs" />
</ItemGroup> </ItemGroup>

View File

@@ -18,68 +18,79 @@ namespace Jackett
{ {
public class JackettModule : Autofac.Module public class JackettModule : Autofac.Module
{ {
protected override void Load (ContainerBuilder builder) protected override void Load(ContainerBuilder builder)
{ {
// Just register everything! // Just register everything!
var thisAssembly = typeof (JackettModule).Assembly; var thisAssembly = typeof(JackettModule).Assembly;
builder.RegisterAssemblyTypes (thisAssembly) builder.RegisterAssemblyTypes(thisAssembly)
.Except<IIndexer> () .Except<IIndexer>()
.Except<IImdbResolver> () .Except<IImdbResolver>()
.Except<OmdbResolver> () .Except<OmdbResolver>()
.Except<IFallbackStrategyProvider> () .Except<IFallbackStrategyProvider>()
.Except<ImdbFallbackStrategyProvider> () .Except<ImdbFallbackStrategyProvider>()
.Except<IFallbackStrategy> () .Except<IFallbackStrategy>()
.Except<ImdbFallbackStrategy> () .Except<ImdbFallbackStrategy>()
.Except<IResultFilterProvider> () .Except<IResultFilterProvider>()
.Except<ImdbTitleResultFilterProvider> () .Except<ImdbTitleResultFilterProvider>()
.Except<IResultFilter> () .Except<IResultFilter>()
.Except<ImdbTitleResultFilterProvider> () .Except<ImdbTitleResultFilterProvider>()
.Except<BaseMetaIndexer> () .Except<BaseMetaIndexer>()
.Except<AggregateIndexer> () .Except<AggregateIndexer>()
.Except<CardigannIndexer>() .Except<CardigannIndexer>()
.AsImplementedInterfaces ().SingleInstance (); .AsImplementedInterfaces().SingleInstance();
builder.RegisterApiControllers (thisAssembly).InstancePerRequest (); builder.RegisterApiControllers(thisAssembly).InstancePerRequest();
builder.RegisterType<HttpWebClient> (); builder.RegisterType<HttpWebClient>();
// Register the best web client for the platform or the override // Register the best web client for the platform or the override
switch (Startup.ClientOverride) { switch (Startup.ClientOverride)
case "httpclient": {
builder.RegisterType<HttpWebClient> ().As<IWebClient> (); case "httpclient":
break; builder.RegisterType<HttpWebClient>().As<IWebClient>();
case "httpclient2": break;
builder.RegisterType<HttpWebClient2> ().As<IWebClient> (); case "httpclient2":
break; builder.RegisterType<HttpWebClient2>().As<IWebClient>();
case "safecurl": break;
builder.RegisterType<UnixSafeCurlWebClient> ().As<IWebClient> (); case "safecurl":
break; builder.RegisterType<UnixSafeCurlWebClient>().As<IWebClient>();
case "libcurl": break;
builder.RegisterType<UnixLibCurlWebClient> ().As<IWebClient> (); case "libcurl":
break; builder.RegisterType<UnixLibCurlWebClient>().As<IWebClient>();
case "automatic": break;
default: case "automatic":
if (System.Environment.OSVersion.Platform == PlatformID.Unix) { default:
var usehttpclient = false; if (System.Environment.OSVersion.Platform == PlatformID.Unix)
try { {
Type monotype = Type.GetType ("Mono.Runtime"); var usehttpclient = false;
if (monotype != null) { try
MethodInfo displayName = monotype.GetMethod ("GetDisplayName", BindingFlags.NonPublic | BindingFlags.Static); {
if (displayName != null) { Type monotype = Type.GetType("Mono.Runtime");
var monoVersion = displayName.Invoke (null, null).ToString (); if (monotype != null)
var monoVersionO = new Version (monoVersion.Split (' ') [0]); {
if ((monoVersionO.Major >= 4 && monoVersionO.Minor >= 8) || monoVersionO.Major >= 5) { MethodInfo displayName = monotype.GetMethod("GetDisplayName", BindingFlags.NonPublic | BindingFlags.Static);
// check if btls is supported if (displayName != null)
var monoSecurity = Assembly.Load ("Mono.Security"); {
Type monoTlsProviderFactory = monoSecurity.GetType ("Mono.Security.Interface.MonoTlsProviderFactory"); var monoVersion = displayName.Invoke(null, null).ToString();
if (monoTlsProviderFactory != null) { var monoVersionO = new Version(monoVersion.Split(' ')[0]);
MethodInfo isProviderSupported = monoTlsProviderFactory.GetMethod ("IsProviderSupported"); if ((monoVersionO.Major >= 4 && monoVersionO.Minor >= 8) || monoVersionO.Major >= 5)
if (isProviderSupported != null) { {
var btlsSupported = (bool)isProviderSupported.Invoke (null, new string [] { "btls" }); // check if btls is supported
if (btlsSupported) { var monoSecurity = Assembly.Load("Mono.Security");
// initialize btls Type monoTlsProviderFactory = monoSecurity.GetType("Mono.Security.Interface.MonoTlsProviderFactory");
MethodInfo initialize = monoTlsProviderFactory.GetMethod ("Initialize", new [] { typeof (string) }); if (monoTlsProviderFactory != null)
if (initialize != null) { {
initialize.Invoke (null, new string [] { "btls" }); MethodInfo isProviderSupported = monoTlsProviderFactory.GetMethod("IsProviderSupported");
usehttpclient = true; if (isProviderSupported != null)
{
var btlsSupported = (bool)isProviderSupported.Invoke(null, new string[] { "btls" });
if (btlsSupported)
{
// initialize btls
MethodInfo initialize = monoTlsProviderFactory.GetMethod("Initialize", new[] { typeof(string) });
if (initialize != null)
{
initialize.Invoke(null, new string[] { "btls" });
usehttpclient = true;
}
} }
} }
} }
@@ -87,45 +98,60 @@ namespace Jackett
} }
} }
} }
} catch (Exception e) { catch (Exception e)
Console.Out.WriteLine ("Error while deciding which HttpWebClient to use: " + e); {
} Console.Out.WriteLine("Error while deciding which HttpWebClient to use: " + e);
}
if (usehttpclient) if (usehttpclient)
builder.RegisterType<HttpWebClient> ().As<IWebClient> (); builder.RegisterType<HttpWebClient>().As<IWebClient>();
else
builder.RegisterType<UnixLibCurlWebClient>().As<IWebClient>();
}
else else
builder.RegisterType<UnixLibCurlWebClient> ().As<IWebClient> (); {
} else { builder.RegisterType<HttpWebClient>().As<IWebClient>();
builder.RegisterType<HttpWebClient> ().As<IWebClient> (); }
} break;
break;
} }
// Register indexers // Register indexers
var indexerTypes = thisAssembly.GetTypes ().Where (p => typeof (IIndexer).IsAssignableFrom (p) && !p.IsInterface && !p.IsInNamespace ("Jackett.Indexers.Meta")); var allTypes = thisAssembly.GetTypes();
foreach (var indexer in indexerTypes) { var allIndexerTypes = allTypes.Where(p => typeof(IIndexer).IsAssignableFrom(p));
builder.RegisterType (indexer).Named<IIndexer> (BaseIndexer.GetIndexerID (indexer)); var allInstantiatableIndexerTypes = allIndexerTypes.Where(p => !p.IsInterface && !p.IsAbstract);
var allNonMetaInstantiatableIndexerTypes = allInstantiatableIndexerTypes.Where(p => !typeof(BaseMetaIndexer).IsAssignableFrom(p));
var indexerTypes = allNonMetaInstantiatableIndexerTypes.Where(p => p.Name != "CardigannIndexer");
foreach (var indexer in indexerTypes)
{
builder.RegisterType(indexer).Named<IIndexer>(BaseIndexer.GetIndexerID(indexer));
} }
Mapper.CreateMap<WebClientByteResult, WebClientStringResult> ().ForMember (x => x.Content, opt => opt.Ignore ()).AfterMap ((be, str) => { Mapper.CreateMap<WebClientByteResult, WebClientStringResult>().ForMember(x => x.Content, opt => opt.Ignore()).AfterMap((be, str) =>
str.Content = Encoding.UTF8.GetString (be.Content); {
str.Content = Encoding.UTF8.GetString(be.Content);
}); });
Mapper.CreateMap<WebClientStringResult, WebClientByteResult> ().ForMember (x => x.Content, opt => opt.Ignore ()).AfterMap ((str, be) => { Mapper.CreateMap<WebClientStringResult, WebClientByteResult>().ForMember(x => x.Content, opt => opt.Ignore()).AfterMap((str, be) =>
if (!string.IsNullOrEmpty (str.Content)) { {
be.Content = Encoding.UTF8.GetBytes (str.Content); if (!string.IsNullOrEmpty(str.Content))
{
be.Content = Encoding.UTF8.GetBytes(str.Content);
} }
}); });
Mapper.CreateMap<WebClientStringResult, WebClientStringResult> (); Mapper.CreateMap<WebClientStringResult, WebClientStringResult>();
Mapper.CreateMap<WebClientByteResult, WebClientByteResult> (); Mapper.CreateMap<WebClientByteResult, WebClientByteResult>();
Mapper.CreateMap<ReleaseInfo, ReleaseInfo> (); Mapper.CreateMap<ReleaseInfo, ReleaseInfo>();
Mapper.CreateMap<ReleaseInfo, TrackerCacheResult> ().AfterMap ((r, t) => { Mapper.CreateMap<ReleaseInfo, TrackerCacheResult>().AfterMap((r, t) =>
if (r.Category != null) { {
var CategoryDesc = string.Join (", ", r.Category.Select (x => TorznabCatType.GetCatDesc (x)).Where (x => !string.IsNullOrEmpty (x))); if (r.Category != null)
{
var CategoryDesc = string.Join(", ", r.Category.Select(x => TorznabCatType.GetCatDesc(x)).Where(x => !string.IsNullOrEmpty(x)));
t.CategoryDesc = CategoryDesc; t.CategoryDesc = CategoryDesc;
} else { }
else
{
t.CategoryDesc = ""; t.CategoryDesc = "";
} }
}); });

View File

@@ -0,0 +1,30 @@
using System;
using System.Text;
using Newtonsoft.Json;
namespace Jackett.Utils
{
public class EncodingJsonConverter : JsonConverter
{
public override bool CanConvert(Type objectType)
{
return true;
}
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var obj = value as Encoding;
writer.WriteValue(obj.WebName);
}
public override bool CanRead
{
get { return false; }
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
throw new NotImplementedException();
}
}
}