mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-14 10:47:08 -07:00
broke up EnvironmentProvider into different services
This commit is contained in:
parent
4d874829e8
commit
6b0a24e28e
54 changed files with 549 additions and 560 deletions
|
@ -5,6 +5,7 @@ using System.Linq;
|
|||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Common.Messaging;
|
||||
using NzbDrone.Common.Serializer;
|
||||
using NzbDrone.Core.Lifecycle;
|
||||
|
@ -13,24 +14,24 @@ namespace NzbDrone.Api.Client
|
|||
{
|
||||
public class ClientSettings : IHandle<ApplicationStartedEvent>
|
||||
{
|
||||
private readonly EnvironmentProvider _environmentProvider;
|
||||
private readonly IAppDirectoryInfo _appDirectoryInfo;
|
||||
|
||||
private static readonly Regex VersionRegex = new Regex(@"(?<=Version:\s')(.*)(?=')", RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
||||
private static readonly Regex BuildDateRegex = new Regex(@"(?<=BuildDate:\s)('.*')", RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
||||
|
||||
public ClientSettings(EnvironmentProvider environmentProvider)
|
||||
public ClientSettings(IAppDirectoryInfo appDirectoryInfo)
|
||||
{
|
||||
_environmentProvider = environmentProvider;
|
||||
_appDirectoryInfo = appDirectoryInfo;
|
||||
}
|
||||
|
||||
public void Handle(ApplicationStartedEvent message)
|
||||
{
|
||||
//TODO: Update the APIKey (when we have it)
|
||||
|
||||
var appFile = Path.Combine(_environmentProvider.StartUpPath, "UI", "app.js");
|
||||
var appFile = Path.Combine(_appDirectoryInfo.StartUpPath, "UI", "app.js");
|
||||
var contents = File.ReadAllText(appFile);
|
||||
var version = _environmentProvider.Version;
|
||||
var date = _environmentProvider.BuildDateTime;
|
||||
var version = BuildInfo.Version;
|
||||
var date = BuildInfo.BuildDateTime;
|
||||
|
||||
contents = VersionRegex.Replace(contents, version.ToString());
|
||||
contents = BuildDateRegex.Replace(contents, date.ToUniversalTime().ToJson());
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
using System.IO;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
|
||||
namespace NzbDrone.Api.Frontend
|
||||
{
|
||||
public class MediaCoverMapper : IMapHttpRequestsToDisk
|
||||
{
|
||||
private readonly IEnvironmentProvider _environmentProvider;
|
||||
private readonly IAppDirectoryInfo _appDirectoryInfo;
|
||||
|
||||
public MediaCoverMapper(IEnvironmentProvider environmentProvider)
|
||||
public MediaCoverMapper(IAppDirectoryInfo appDirectoryInfo)
|
||||
{
|
||||
_environmentProvider = environmentProvider;
|
||||
_appDirectoryInfo = appDirectoryInfo;
|
||||
}
|
||||
|
||||
public string Map(string resourceUrl)
|
||||
|
@ -17,7 +18,7 @@ namespace NzbDrone.Api.Frontend
|
|||
var path = resourceUrl.Replace('/', Path.DirectorySeparatorChar);
|
||||
path = path.Trim(Path.DirectorySeparatorChar).ToLower();
|
||||
|
||||
return Path.Combine(_environmentProvider.GetAppDataPath(), path);
|
||||
return Path.Combine(_appDirectoryInfo.GetAppDataPath(), path);
|
||||
}
|
||||
|
||||
public bool CanHandle(string resourceUrl)
|
||||
|
|
|
@ -2,12 +2,13 @@ using System;
|
|||
using System.IO;
|
||||
using System.Linq;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
|
||||
namespace NzbDrone.Api.Frontend
|
||||
{
|
||||
public class StaticResourceMapper : IMapHttpRequestsToDisk
|
||||
{
|
||||
private readonly IEnvironmentProvider _environmentProvider;
|
||||
private readonly IAppDirectoryInfo _appDirectoryInfo;
|
||||
private static readonly string[] Extensions = new[] {
|
||||
".css",
|
||||
".js",
|
||||
|
@ -24,9 +25,9 @@ namespace NzbDrone.Api.Frontend
|
|||
".eot"
|
||||
};
|
||||
|
||||
public StaticResourceMapper(IEnvironmentProvider environmentProvider)
|
||||
public StaticResourceMapper(IAppDirectoryInfo appDirectoryInfo)
|
||||
{
|
||||
_environmentProvider = environmentProvider;
|
||||
_appDirectoryInfo = appDirectoryInfo;
|
||||
}
|
||||
|
||||
public string Map(string resourceUrl)
|
||||
|
@ -35,7 +36,7 @@ namespace NzbDrone.Api.Frontend
|
|||
path = path.Trim(Path.DirectorySeparatorChar).ToLower();
|
||||
|
||||
|
||||
return Path.Combine(_environmentProvider.StartUpPath, "ui", path);
|
||||
return Path.Combine(_appDirectoryInfo.StartUpPath, "ui", path);
|
||||
}
|
||||
|
||||
public bool CanHandle(string resourceUrl)
|
||||
|
|
|
@ -2,19 +2,21 @@
|
|||
using Nancy.Routing;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Api.Extensions;
|
||||
using System.Linq;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
|
||||
namespace NzbDrone.Api.System
|
||||
{
|
||||
public class SystemModule : NzbDroneApiModule
|
||||
{
|
||||
private readonly IEnvironmentProvider _environmentProvider;
|
||||
private readonly IAppDirectoryInfo _appDirectoryInfo;
|
||||
private readonly IRuntimeInfo _runtimeInfo;
|
||||
private readonly IRouteCacheProvider _routeCacheProvider;
|
||||
|
||||
public SystemModule(IEnvironmentProvider environmentProvider, IRouteCacheProvider routeCacheProvider)
|
||||
public SystemModule(IAppDirectoryInfo appDirectoryInfo, IRuntimeInfo runtimeInfo, IRouteCacheProvider routeCacheProvider)
|
||||
: base("system")
|
||||
{
|
||||
_environmentProvider = environmentProvider;
|
||||
_appDirectoryInfo = appDirectoryInfo;
|
||||
_runtimeInfo = runtimeInfo;
|
||||
_routeCacheProvider = routeCacheProvider;
|
||||
Get["/status"] = x => GetStatus();
|
||||
Get["/routes"] = x => GetRoutes();
|
||||
|
@ -24,17 +26,17 @@ namespace NzbDrone.Api.System
|
|||
{
|
||||
return new
|
||||
{
|
||||
Version = _environmentProvider.Version.ToString(),
|
||||
AppData = _environmentProvider.GetAppDataPath(),
|
||||
IsAdmin = _environmentProvider.IsAdmin,
|
||||
IsUserInteractive = _environmentProvider.IsUserInteractive,
|
||||
BuildTime = _environmentProvider.BuildDateTime,
|
||||
StartupPath = _environmentProvider.StartUpPath,
|
||||
OsVersion = _environmentProvider.GetOsVersion().ToString(),
|
||||
IsMono = EnvironmentProvider.IsMono,
|
||||
IsProduction = EnvironmentProvider.IsProduction,
|
||||
IsDebug = EnvironmentProvider.IsDebug,
|
||||
IsLinux = EnvironmentProvider.IsLinux,
|
||||
Version = BuildInfo.Version.ToString(),
|
||||
BuildTime = BuildInfo.BuildDateTime,
|
||||
IsDebug = BuildInfo.IsDebug,
|
||||
IsProduction = RuntimeInfo.IsProduction,
|
||||
IsAdmin = _runtimeInfo.IsAdmin,
|
||||
IsUserInteractive = _runtimeInfo.IsUserInteractive,
|
||||
StartupPath = _appDirectoryInfo.StartUpPath,
|
||||
AppData = _appDirectoryInfo.GetAppDataPath(),
|
||||
OsVersion = OsInfo.Version.ToString(),
|
||||
IsMono = OsInfo.IsMono,
|
||||
IsLinux = OsInfo.IsLinux,
|
||||
}.AsResponse();
|
||||
|
||||
}
|
||||
|
|
|
@ -8,17 +8,17 @@ namespace NzbDrone.Api.Update
|
|||
{
|
||||
public class UpdateModule : NzbDroneRestModule<UpdateResource>
|
||||
{
|
||||
private readonly IUpdateService _updateService;
|
||||
private readonly ICheckUpdateService _checkUpdateService;
|
||||
|
||||
public UpdateModule(IUpdateService updateService)
|
||||
public UpdateModule(ICheckUpdateService checkUpdateService)
|
||||
{
|
||||
_updateService = updateService;
|
||||
_checkUpdateService = checkUpdateService;
|
||||
GetResourceAll = GetAvailableUpdate;
|
||||
}
|
||||
|
||||
private List<UpdateResource> GetAvailableUpdate()
|
||||
{
|
||||
var update = _updateService.AvailableUpdate();
|
||||
var update = _checkUpdateService.AvailableUpdate();
|
||||
var response = new List<UpdateResource>();
|
||||
|
||||
if (update != null)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue