Revised Authentication logic for api and logfiles.

This commit is contained in:
Taloth Saldono 2014-03-27 23:13:31 +01:00 committed by Taloth
parent 9645fb07db
commit f92aded4f0
4 changed files with 23 additions and 24 deletions

View file

@ -4,11 +4,15 @@ using System.Linq;
using NzbDrone.Common;
using NzbDrone.Common.Disk;
using NzbDrone.Common.EnvironmentInfo;
using Nancy;
using Nancy.Responses;
namespace NzbDrone.Api.Logs
{
public class LogFileModule : NzbDroneRestModule<LogFileResource>
{
private const string LOGFILE_ROUTE = @"/(?<filename>nzbdrone(?:\.\d+)?\.txt)";
private readonly IAppFolderInfo _appFolderInfo;
private readonly IDiskProvider _diskProvider;
@ -19,6 +23,8 @@ namespace NzbDrone.Api.Logs
_appFolderInfo = appFolderInfo;
_diskProvider = diskProvider;
GetResourceAll = GetLogFiles;
Get[LOGFILE_ROUTE] = options => GetLogFile(options.filename);
}
private List<LogFileResource> GetLogFiles()
@ -41,5 +47,17 @@ namespace NzbDrone.Api.Logs
return result.OrderByDescending(l => l.LastWriteTime).ToList();
}
private Response GetLogFile(string filename)
{
var filePath = Path.Combine(_appFolderInfo.GetLogFolder(), filename);
if (!_diskProvider.FileExists(filePath))
return new NotFoundResponse();
var data = _diskProvider.ReadAllText(filePath);
return new TextResponse(data);
}
}
}