Added a logs controller, so we have the ability to view and download logs from the API

pull/3895/head
Jamie Rees 5 years ago
parent 0c3e04e91c
commit f999b0d19f

@ -55,7 +55,8 @@
<button mat-menu-item [routerLink]="['/Settings/About']">About</button>
<button mat-menu-item [routerLink]="['/Settings/FailedRequests']">Failed Requests</button>
<button mat-menu-item [routerLink]="['/Settings/Update']">Update</button>
<button mat-menu-item [routerLink]="['/Settings/Jobs']">Background Jobs</button>
<button mat-menu-item [routerLink]="['/Settings/Jobs']">Scheduled Tasks</button>
<button mat-menu-item [routerLink]="['/Settings/Jobs']">Logs</button>
</mat-menu>
<hr/>

@ -9,10 +9,7 @@ using Ombi.Core.Models.Search.V2;
namespace Ombi.Controllers.V2
{
[ApiV2]
[Authorize]
[ApiController]
public class CalendarController : ControllerBase
public class CalendarController : V2Controller
{
public CalendarController(ICalendarEngine calendarEngine)
{

@ -10,10 +10,8 @@ using Ombi.Models;
namespace Ombi.Controllers.V2
{
[ApiV2]
[Admin]
[ApiController]
public class HubController : ControllerBase
public class HubController : V2Controller
{
public HubController(OmbiUserManager um)
{

@ -12,10 +12,7 @@ using Ombi.Store.Entities.Requests;
namespace Ombi.Controllers.V2
{
[ApiV2]
[Authorize]
[ApiController]
public class RequestsController : ControllerBase
public class RequestsController : V2Controller
{
public RequestsController(IMovieRequestEngine movieRequestEngine, ITvRequestEngine tvRequestEngine)
{

@ -16,10 +16,7 @@ using Ombi.Models;
namespace Ombi.Controllers.V2
{
[ApiV2]
[Authorize]
[ApiController]
public class SearchController : ControllerBase
public class SearchController : V2Controller
{
public SearchController(IMultiSearchEngine multiSearchEngine, ITvSearchEngine tvSearchEngine,
IMovieEngineV2 v2Movie, ITVSearchEngineV2 v2Tv, IMusicSearchEngineV2 musicEngine)

@ -0,0 +1,56 @@
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Ombi.Attributes;
namespace Ombi.Controllers.V2
{
[Admin]
public class SystemController : V2Controller
{
private readonly IHostingEnvironment _hosting;
public SystemController(IHostingEnvironment hosting)
{
_hosting = hosting;
}
[HttpGet("logs")]
public IActionResult GetLogFiles()
{
var logsFolder = Path.Combine(_hosting.ContentRootPath, "Logs");
var files = Directory
.EnumerateFiles(logsFolder, "*.txt", SearchOption.TopDirectoryOnly)
.Select(Path.GetFileName);
return Ok(files);
}
[HttpGet("logs/{logFileName}")]
public async Task<IActionResult> ReadLogFile(string logFileName, CancellationToken token)
{
var logFile = Path.Combine(_hosting.ContentRootPath, "Logs", logFileName);
using (var fs = new FileStream(logFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
using (StreamReader reader = new StreamReader(fs))
{
return Ok(await reader.ReadToEndAsync());
}
}
[HttpGet("logs/download/{logFileName}")]
public IActionResult Download(string logFileName, CancellationToken token)
{
var logFile = Path.Combine(_hosting.ContentRootPath, "Logs", logFileName);
using (var fs = new FileStream(logFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
using (StreamReader reader = new StreamReader(fs))
{
return File(reader.BaseStream, "application/octet-stream", logFileName);
}
}
}
}

@ -0,0 +1,14 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace Ombi.Controllers.V2
{
[ApiV2]
[Authorize]
[ApiController]
public class V2Controller : ControllerBase
{
}
}
Loading…
Cancel
Save