mirror of
https://github.com/Jackett/Jackett.git
synced 2025-09-17 17:34:09 +02:00
.NET Core preparation: Access ServerConfig without using JackettModule
This commit is contained in:
@@ -94,61 +94,14 @@ namespace Jackett.Common.Plumbing
|
|||||||
private ServerConfig BuildServerConfig(IComponentContext ctx)
|
private ServerConfig BuildServerConfig(IComponentContext ctx)
|
||||||
{
|
{
|
||||||
var configService = ctx.Resolve<IConfigurationService>();
|
var configService = ctx.Resolve<IConfigurationService>();
|
||||||
// Load config
|
return configService.BuildServerConfig(_runtimeSettings);
|
||||||
var config = configService.GetConfig<ServerConfig>();
|
|
||||||
if (config == null)
|
|
||||||
{
|
|
||||||
config = new ServerConfig(_runtimeSettings);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//We don't load these out of the config files as it could get confusing to users who accidently save.
|
|
||||||
//In future we could flatten the serverconfig, and use command line parameters to override any configuration.
|
|
||||||
config.RuntimeSettings = _runtimeSettings;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(config.APIKey))
|
|
||||||
{
|
|
||||||
// Check for legacy key config
|
|
||||||
var apiKeyFile = Path.Combine(configService.GetAppDataFolder(), "api_key.txt");
|
|
||||||
if (File.Exists(apiKeyFile))
|
|
||||||
{
|
|
||||||
config.APIKey = File.ReadAllText(apiKeyFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for legacy settings
|
|
||||||
|
|
||||||
var path = Path.Combine(configService.GetAppDataFolder(), "config.json"); ;
|
|
||||||
var jsonReply = new JObject();
|
|
||||||
if (File.Exists(path))
|
|
||||||
{
|
|
||||||
jsonReply = JObject.Parse(File.ReadAllText(path));
|
|
||||||
config.Port = (int)jsonReply["port"];
|
|
||||||
config.AllowExternal = (bool)jsonReply["public"];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(config.APIKey))
|
|
||||||
config.APIKey = StringUtil.GenerateRandom(32);
|
|
||||||
|
|
||||||
configService.SaveConfig(config);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(config.InstanceId))
|
|
||||||
{
|
|
||||||
config.InstanceId = StringUtil.GenerateRandom(64);
|
|
||||||
configService.SaveConfig(config);
|
|
||||||
}
|
|
||||||
config.ConfigChanged();
|
|
||||||
return config;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private static bool DetectMonoCompatabilityWithHttpClient()
|
private static bool DetectMonoCompatabilityWithHttpClient()
|
||||||
{
|
{
|
||||||
bool usehttpclient = false;
|
bool usehttpclient = false;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Type monotype = Type.GetType("Mono.Runtime");
|
Type monotype = Type.GetType("Mono.Runtime");
|
||||||
if (monotype != null)
|
if (monotype != null)
|
||||||
{
|
{
|
||||||
|
@@ -7,6 +7,7 @@ using System.Security.Principal;
|
|||||||
using Jackett.Common.Models.Config;
|
using Jackett.Common.Models.Config;
|
||||||
using Jackett.Common.Services.Interfaces;
|
using Jackett.Common.Services.Interfaces;
|
||||||
using Jackett.Common.Utils;
|
using Jackett.Common.Utils;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
using NLog;
|
using NLog;
|
||||||
|
|
||||||
namespace Jackett.Common.Services
|
namespace Jackett.Common.Services
|
||||||
@@ -48,8 +49,6 @@ namespace Jackett.Common.Services
|
|||||||
dir.SetAccessControl(directorySecurity);
|
dir.SetAccessControl(directorySecurity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Info("App config/log directory: " + GetAppDataFolder());
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -240,5 +239,56 @@ namespace Jackett.Common.Services
|
|||||||
{
|
{
|
||||||
return EnvironmentUtil.JackettVersion;
|
return EnvironmentUtil.JackettVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ServerConfig BuildServerConfig(RuntimeSettings runtimeSettings)
|
||||||
|
{
|
||||||
|
// Load config
|
||||||
|
var config = GetConfig<ServerConfig>();
|
||||||
|
if (config == null)
|
||||||
|
{
|
||||||
|
config = new ServerConfig(runtimeSettings);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//We don't load these out of the config files as it could get confusing to users who accidently save.
|
||||||
|
//In future we could flatten the serverconfig, and use command line parameters to override any configuration.
|
||||||
|
config.RuntimeSettings = runtimeSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(config.APIKey))
|
||||||
|
{
|
||||||
|
// Check for legacy key config
|
||||||
|
var apiKeyFile = Path.Combine(GetAppDataFolder(), "api_key.txt");
|
||||||
|
if (File.Exists(apiKeyFile))
|
||||||
|
{
|
||||||
|
config.APIKey = File.ReadAllText(apiKeyFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for legacy settings
|
||||||
|
|
||||||
|
var path = Path.Combine(GetAppDataFolder(), "config.json"); ;
|
||||||
|
var jsonReply = new JObject();
|
||||||
|
if (File.Exists(path))
|
||||||
|
{
|
||||||
|
jsonReply = JObject.Parse(File.ReadAllText(path));
|
||||||
|
config.Port = (int)jsonReply["port"];
|
||||||
|
config.AllowExternal = (bool)jsonReply["public"];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(config.APIKey))
|
||||||
|
config.APIKey = StringUtil.GenerateRandom(32);
|
||||||
|
|
||||||
|
SaveConfig(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(config.InstanceId))
|
||||||
|
{
|
||||||
|
config.InstanceId = StringUtil.GenerateRandom(64);
|
||||||
|
SaveConfig(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
config.ConfigChanged();
|
||||||
|
return config;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using Jackett.Common.Models.Config;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Jackett.Common.Services.Interfaces
|
namespace Jackett.Common.Services.Interfaces
|
||||||
{
|
{
|
||||||
@@ -15,5 +16,6 @@ namespace Jackett.Common.Services.Interfaces
|
|||||||
List<string> GetCardigannDefinitionsFolders();
|
List<string> GetCardigannDefinitionsFolders();
|
||||||
void CreateOrMigrateSettings();
|
void CreateOrMigrateSettings();
|
||||||
void PerformMigration();
|
void PerformMigration();
|
||||||
|
ServerConfig BuildServerConfig(RuntimeSettings runtimeSettings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -4,7 +4,7 @@ using Newtonsoft.Json;
|
|||||||
namespace Jackett.Common.Services
|
namespace Jackett.Common.Services
|
||||||
{
|
{
|
||||||
|
|
||||||
class SerializeService : ISerializeService
|
public class SerializeService : ISerializeService
|
||||||
{
|
{
|
||||||
public string Serialise(object obj)
|
public string Serialise(object obj)
|
||||||
{
|
{
|
||||||
|
@@ -111,6 +111,8 @@ namespace Jackett.Services
|
|||||||
logger.Error("Error while getting MaxThreads details: " + e);
|
logger.Error("Error while getting MaxThreads details: " + e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.Info("App config/log directory: " + configService.GetAppDataFolder());
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var issuefile = "/etc/issue";
|
var issuefile = "/etc/issue";
|
||||||
|
Reference in New Issue
Block a user