mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-14 18:57:39 -07:00
Log files are viewable in the UI
This commit is contained in:
parent
a9ac2500d5
commit
4c536a077f
21 changed files with 325 additions and 40 deletions
29
NzbDrone.Api/Frontend/LogFileMapper.cs
Normal file
29
NzbDrone.Api/Frontend/LogFileMapper.cs
Normal file
|
@ -0,0 +1,29 @@
|
|||
using System.IO;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
|
||||
namespace NzbDrone.Api.Frontend
|
||||
{
|
||||
public class LogFileMapper : IMapHttpRequestsToDisk
|
||||
{
|
||||
private readonly IAppFolderInfo _appFolderInfo;
|
||||
|
||||
public LogFileMapper(IAppFolderInfo appFolderInfo)
|
||||
{
|
||||
_appFolderInfo = appFolderInfo;
|
||||
}
|
||||
|
||||
public string Map(string resourceUrl)
|
||||
{
|
||||
var path = resourceUrl.Replace('/', Path.DirectorySeparatorChar);
|
||||
path = Path.GetFileName(path);
|
||||
|
||||
return Path.Combine(_appFolderInfo.GetLogFolder(), path);
|
||||
}
|
||||
|
||||
public bool CanHandle(string resourceUrl)
|
||||
{
|
||||
return resourceUrl.StartsWith("/log");
|
||||
}
|
||||
}
|
||||
}
|
45
NzbDrone.Api/Logs/LogFileModule.cs
Normal file
45
NzbDrone.Api/Logs/LogFileModule.cs
Normal file
|
@ -0,0 +1,45 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
|
||||
namespace NzbDrone.Api.Logs
|
||||
{
|
||||
public class LogFileModule : NzbDroneRestModule<LogFileResource>
|
||||
{
|
||||
private readonly IAppFolderInfo _appFolderInfo;
|
||||
private readonly IDiskProvider _diskProvider;
|
||||
|
||||
public LogFileModule(IAppFolderInfo appFolderInfo,
|
||||
IDiskProvider diskProvider)
|
||||
: base("log/files")
|
||||
{
|
||||
_appFolderInfo = appFolderInfo;
|
||||
_diskProvider = diskProvider;
|
||||
GetResourceAll = GetLogFiles;
|
||||
}
|
||||
|
||||
private List<LogFileResource> GetLogFiles()
|
||||
{
|
||||
var result = new List<LogFileResource>();
|
||||
|
||||
var files = _diskProvider.GetFiles(_appFolderInfo.GetLogFolder(), SearchOption.TopDirectoryOnly);
|
||||
|
||||
for (int i = 0; i < files.Length; i++)
|
||||
{
|
||||
var file = files[i];
|
||||
|
||||
result.Add(new LogFileResource
|
||||
{
|
||||
Id = i + 1,
|
||||
Filename = Path.GetFileName(file),
|
||||
LastWriteTime = _diskProvider.GetLastFileWrite(file)
|
||||
});
|
||||
}
|
||||
|
||||
return result.OrderByDescending(l => l.LastWriteTime).ToList();
|
||||
}
|
||||
}
|
||||
}
|
11
NzbDrone.Api/Logs/LogFileResource.cs
Normal file
11
NzbDrone.Api/Logs/LogFileResource.cs
Normal file
|
@ -0,0 +1,11 @@
|
|||
using System;
|
||||
using NzbDrone.Api.REST;
|
||||
|
||||
namespace NzbDrone.Api.Logs
|
||||
{
|
||||
public class LogFileResource : RestResource
|
||||
{
|
||||
public String Filename { get; set; }
|
||||
public DateTime LastWriteTime { get; set; }
|
||||
}
|
||||
}
|
|
@ -1,5 +1,4 @@
|
|||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.History;
|
||||
using NzbDrone.Core.Instrumentation;
|
||||
using NzbDrone.Api.Mapping;
|
||||
|
||||
|
@ -8,7 +7,6 @@ namespace NzbDrone.Api.Logs
|
|||
public class LogModule : NzbDroneRestModule<LogResource>
|
||||
{
|
||||
private readonly ILogService _logService;
|
||||
private readonly IHistoryService _historyService;
|
||||
|
||||
public LogModule(ILogService logService)
|
||||
{
|
||||
|
|
|
@ -92,6 +92,7 @@
|
|||
<Compile Include="Extensions\CacheHeaderPipeline.cs" />
|
||||
<Compile Include="Extensions\GZipPipeline.cs" />
|
||||
<Compile Include="Extensions\NancyJsonSerializer.cs" />
|
||||
<Compile Include="Frontend\LogFileMapper.cs" />
|
||||
<Compile Include="Frontend\IAddCacheHeaders.cs" />
|
||||
<Compile Include="Frontend\MediaCoverMapper.cs" />
|
||||
<Compile Include="Frontend\IMapHttpRequestsToDisk.cs" />
|
||||
|
@ -106,6 +107,8 @@
|
|||
<Compile Include="Indexers\ReleaseModule.cs" />
|
||||
<Compile Include="Extensions\LazyExtensions.cs" />
|
||||
<Compile Include="Indexers\ReleaseResource.cs" />
|
||||
<Compile Include="Logs\LogFileResource.cs" />
|
||||
<Compile Include="Logs\LogFileModule.cs" />
|
||||
<Compile Include="Logs\LogModule.cs" />
|
||||
<Compile Include="Logs\LogResource.cs" />
|
||||
<Compile Include="Mapping\CloneInjection.cs" />
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue