1
0
Fork 0
mirror of https://github.com/Jackett/Jackett synced 2025-02-23 14:51:01 +00:00

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();
}
public IWebIndexer GetWebIndexer(string name)
{
throw new NotImplementedException();
}
public void InitIndexers()
{
throw new NotImplementedException();

View file

@ -96,11 +96,25 @@ Global
$2.SpacesBeforeBrackets = False
$2.scope = text/x-csharp
$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.SpaceAfterMethodCallName = False
$2.SpaceBeforeOpenSquareBracket = False
$0.DotNetNamingPolicy = $3
$3.DirectoryNamespaceAssociation = PrefixedHierarchical
$0.StandardHeader = $4
$0.TextStylePolicy = $3
$3.FileWidth = 80
$3.TabsToSpaces = True
$3.scope = text/plain
EndGlobalSection
EndGlobal

View file

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

View file

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

View file

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