You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Ombi/src/Ombi/Controllers/V2/SystemController.cs

55 lines
1.9 KiB

using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Ombi.Attributes;
namespace Ombi.Controllers.V2
{
[Admin]
public class SystemController : V2Controller
{
5 years ago
private readonly IWebHostEnvironment _hosting;
5 years ago
public SystemController(IWebHostEnvironment 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)
.OrderByDescending(name => name);
return Ok(files);
}
[HttpGet("logs/{logFileName}")]
public async Task<IActionResult> ReadLogFile(string logFileName, CancellationToken token)
{
var logFile = Path.Combine(_hosting.ContentRootPath, "Logs", logFileName);
5 years ago
using (var fs = new FileStream(logFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
using (StreamReader reader = new StreamReader(fs))
{
return Ok(await reader.ReadToEndAsync());
}
}
5 years ago
[HttpGet("logs/download/{logFileName}")]
public IActionResult Download(string logFileName, CancellationToken token)
{
var logFile = Path.Combine(_hosting.ContentRootPath, "Logs", logFileName);
5 years ago
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);
}
}
}
}