changed the diagnose to be easier to use
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
using System.IO.Compression;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using MoonCore.Helpers;
|
||||
using Moonlight.ApiServer.Configuration;
|
||||
using Moonlight.ApiServer.Extensions;
|
||||
using Moonlight.ApiServer.Interfaces;
|
||||
using Moonlight.ApiServer.Models.Diagnose;
|
||||
|
||||
namespace Moonlight.ApiServer.Implementations.Diagnose;
|
||||
|
||||
public class CoreConfigDiagnoseProvider : IDiagnoseProvider
|
||||
{
|
||||
private readonly AppConfiguration Config;
|
||||
|
||||
public CoreConfigDiagnoseProvider(AppConfiguration config)
|
||||
{
|
||||
Config = config;
|
||||
}
|
||||
|
||||
private string CheckForNullOrEmpty(string? content)
|
||||
{
|
||||
return string.IsNullOrEmpty(content)
|
||||
? "ISEMPTY"
|
||||
: "ISNOTEMPTY";
|
||||
}
|
||||
|
||||
public async Task ModifyZipArchive(ZipArchive archive)
|
||||
{
|
||||
|
||||
var json = JsonSerializer.Serialize(Config);
|
||||
var config = JsonSerializer.Deserialize<AppConfiguration>(json);
|
||||
|
||||
if (config == null)
|
||||
{
|
||||
await archive.AddText("core/config.txt","Could not fetch config.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
config.Database.Password = CheckForNullOrEmpty(config.Database.Password);
|
||||
|
||||
config.Authentication.OAuth2.ClientSecret = CheckForNullOrEmpty(config.Authentication.OAuth2.ClientSecret);
|
||||
|
||||
config.Authentication.OAuth2.Secret = CheckForNullOrEmpty(config.Authentication.OAuth2.Secret);
|
||||
|
||||
config.Authentication.Secret = CheckForNullOrEmpty(config.Authentication.Secret);
|
||||
|
||||
await archive.AddText("core/config.txt",
|
||||
JsonSerializer.Serialize(config, new JsonSerializerOptions() { WriteIndented = true }));
|
||||
}
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using MoonCore.Helpers;
|
||||
using Moonlight.ApiServer.Configuration;
|
||||
using Moonlight.ApiServer.Interfaces;
|
||||
using Moonlight.ApiServer.Models.Diagnose;
|
||||
|
||||
namespace Moonlight.ApiServer.Implementations.Diagnose;
|
||||
|
||||
public class CoreDiagnoseProvider : IDiagnoseProvider
|
||||
{
|
||||
private readonly AppConfiguration Config;
|
||||
|
||||
public CoreDiagnoseProvider(AppConfiguration config)
|
||||
{
|
||||
Config = config;
|
||||
}
|
||||
|
||||
public DiagnoseEntry[] GetFiles()
|
||||
{
|
||||
return
|
||||
[
|
||||
new DiagnoseDirectory()
|
||||
{
|
||||
Name = "core",
|
||||
Children = [
|
||||
|
||||
new DiagnoseFile()
|
||||
{
|
||||
Name = "logs.txt",
|
||||
GetContent = () =>
|
||||
{
|
||||
var logs = File.ReadAllText(PathBuilder.File("storage", "logs", "latest.log"));
|
||||
|
||||
if (string.IsNullOrEmpty(logs))
|
||||
return Encoding.UTF8.GetBytes("Could not get the latest logs.");
|
||||
|
||||
return Encoding.UTF8.GetBytes(logs);
|
||||
}
|
||||
},
|
||||
|
||||
new DiagnoseFile()
|
||||
{
|
||||
Name = "config.txt",
|
||||
GetContent = () =>
|
||||
{
|
||||
var json = JsonSerializer.Serialize(Config);
|
||||
var config = JsonSerializer.Deserialize<AppConfiguration>(json);
|
||||
|
||||
if (config == null)
|
||||
{
|
||||
return Encoding.UTF8.GetBytes("Could not fetch config.");
|
||||
}
|
||||
|
||||
config.Database.Password = CheckForNullOrEmpty(config.Database.Password);
|
||||
|
||||
config.Authentication.OAuth2.ClientSecret = CheckForNullOrEmpty(config.Authentication.OAuth2.ClientSecret);
|
||||
|
||||
config.Authentication.OAuth2.Secret = CheckForNullOrEmpty(config.Authentication.OAuth2.Secret);
|
||||
|
||||
config.Authentication.Secret = CheckForNullOrEmpty(config.Authentication.Secret);
|
||||
|
||||
return Encoding.UTF8.GetBytes(JsonSerializer.Serialize(config, new JsonSerializerOptions() { WriteIndented = true}));
|
||||
}
|
||||
}
|
||||
|
||||
]
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
private string CheckForNullOrEmpty(string? content)
|
||||
{
|
||||
return string.IsNullOrEmpty(content)
|
||||
? "ISEMPTY"
|
||||
: "ISNOTEMPTY";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using System.IO.Compression;
|
||||
using System.Text;
|
||||
using MoonCore.Helpers;
|
||||
using Moonlight.ApiServer.Extensions;
|
||||
using Moonlight.ApiServer.Interfaces;
|
||||
|
||||
namespace Moonlight.ApiServer.Implementations.Diagnose;
|
||||
|
||||
public class LogsDiagnoseProvider : IDiagnoseProvider
|
||||
{
|
||||
public async Task ModifyZipArchive(ZipArchive archive)
|
||||
{
|
||||
|
||||
var logs = await File.ReadAllTextAsync(PathBuilder.File("storage", "logs", "latest.log"));
|
||||
|
||||
if (string.IsNullOrEmpty(logs))
|
||||
{
|
||||
await archive.AddText("logs.txt", "Could not read the logs");
|
||||
return;
|
||||
}
|
||||
|
||||
await archive.AddText("logs.txt", logs);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user