From 65faa2a369f80692f030a66cbbe68bd2268cba5e Mon Sep 17 00:00:00 2001 From: zerratar Date: Thu, 27 Jul 2023 18:02:35 +0200 Subject: [PATCH] Add a delete ravenbot log --- src/RavenNest.Blazor.Services/ServerService.cs | 15 +++++++++++++++ .../Pages/Admin/RavenbotLogs.razor | 6 ++++++ 2 files changed, 21 insertions(+) diff --git a/src/RavenNest.Blazor.Services/ServerService.cs b/src/RavenNest.Blazor.Services/ServerService.cs index d298d47b..5d4dffd1 100644 --- a/src/RavenNest.Blazor.Services/ServerService.cs +++ b/src/RavenNest.Blazor.Services/ServerService.cs @@ -31,6 +31,21 @@ public ServerService( } public GameData GameData => gameData; + public async Task> DeleteLogFileAsync(RavenbotLogFile file) + { + + var currentDir = new DirectoryInfo(Directory.GetCurrentDirectory()); + var logsFolder = new DirectoryInfo(Path.Combine(currentDir.Parent.FullName, "logs")); + + var f = Path.Combine(logsFolder.FullName, file.FileName); + if (System.IO.File.Exists(f)) + { + System.IO.File.Delete(f); + } + + return await GetLogFilesAsync(); + } + public async Task> GetLogFilesAsync() { diff --git a/src/RavenNest.Blazor/Pages/Admin/RavenbotLogs.razor b/src/RavenNest.Blazor/Pages/Admin/RavenbotLogs.razor index 09f97882..2715fb14 100644 --- a/src/RavenNest.Blazor/Pages/Admin/RavenbotLogs.razor +++ b/src/RavenNest.Blazor/Pages/Admin/RavenbotLogs.razor @@ -36,6 +36,7 @@ @(FormatSize(item.FileSize)) + } @@ -61,6 +62,11 @@ { return input.ToString("yyyy-MM-dd"); } + + private async Task DeleteLog(RavenNest.Blazor.Services.RavenbotLogFile file) + { + logFiles = await ServerService.DeleteLogFileAsync(file); + } private string FormatSize(long bytes) {