@ -1,7 +1,9 @@
using System.IO ;
using System.Linq ;
using System.Net.Http ;
using System.Threading ;
using System.Threading.Tasks ;
using Markdig ;
using Microsoft.AspNetCore.Hosting ;
using Microsoft.AspNetCore.Mvc ;
using Ombi.Attributes ;
@ -12,16 +14,27 @@ namespace Ombi.Controllers.V2
public class SystemController : V2Controller
{
private readonly IWebHostEnvironment _hosting ;
private readonly HttpClient _client ;
public SystemController ( IWebHostEnvironment hosting )
public SystemController ( IWebHostEnvironment hosting , IHttpClientFactory httpClientFactory )
{
_hosting = hosting ;
_client = httpClientFactory . CreateClient ( ) ;
}
[HttpGet("news")]
public async Task < IActionResult > GetNews ( )
{
var result = await _client . GetAsync ( "https://raw.githubusercontent.com/tidusjar/Ombi.News/main/README.md" ) ;
var content = await result . Content . ReadAsStringAsync ( ) ;
var md = Markdown . ToHtml ( content ) ;
return Ok ( md ) ;
}
[HttpGet("logs")]
public IActionResult GetLogFiles ( )
{
var logsFolder = Path . Combine ( _hosting . ContentRootPath , "Logs" ) ;
var logsFolder = Path . Combine ( string . IsNullOrEmpty ( Ombi . Helpers . StartupSingleton . Instance . StoragePath ) ? _hosting . ContentRoot Path : Helpers . StartupSingleton . Instance . Storage Path, "Logs" ) ;
var files = Directory
. EnumerateFiles ( logsFolder , "*.txt" , SearchOption . TopDirectoryOnly )
. Select ( Path . GetFileName )
@ -33,7 +46,7 @@ namespace Ombi.Controllers.V2
[HttpGet("logs/{logFileName}")]
public async Task < IActionResult > ReadLogFile ( string logFileName , CancellationToken token )
{
var logFile = Path . Combine ( _hosting . ContentRoot Path, "Logs" , logFileName ) ;
var logFile = Path . Combine ( string . IsNullOrEmpty ( Ombi . Helpers . StartupSingleton . Instance . StoragePath ) ? _hosting . ContentRoot Path : Helpers . StartupSingleton . Instance . Storage Path, "Logs" , logFileName ) ;
using ( var fs = new FileStream ( logFile , FileMode . Open , FileAccess . Read , FileShare . ReadWrite ) )
using ( StreamReader reader = new StreamReader ( fs ) )
{
@ -44,7 +57,7 @@ namespace Ombi.Controllers.V2
[HttpGet("logs/download/{logFileName}")]
public IActionResult Download ( string logFileName , CancellationToken token )
{
var logFile = Path . Combine ( _hosting . ContentRoot Path, "Logs" , logFileName ) ;
var logFile = Path . Combine ( string . IsNullOrEmpty ( Ombi . Helpers . StartupSingleton . Instance . StoragePath ) ? _hosting . ContentRoot Path : Helpers . StartupSingleton . Instance . Storage Path, "Logs" , logFileName ) ;
using ( var fs = new FileStream ( logFile , FileMode . Open , FileAccess . Read , FileShare . ReadWrite ) )
using ( StreamReader reader = new StreamReader ( fs ) )
{