mirror of
https://github.com/Megghy/MegghysAPI.git
synced 2025-12-06 22:26:56 +08:00
74 lines
2.8 KiB
C#
74 lines
2.8 KiB
C#
using System.Text.Encodings.Web;
|
|
using System.Text.Json;
|
|
using System.Text.Unicode;
|
|
|
|
namespace MegghysAPI
|
|
{
|
|
public class Config
|
|
{
|
|
public static readonly JsonSerializerOptions DefaultSerializerOptions = new()
|
|
{
|
|
WriteIndented = true,
|
|
Encoder = JavaScriptEncoder.Create(UnicodeRanges.All),
|
|
};
|
|
private static Config _oldInstance = new();
|
|
private static Config? _instance;
|
|
public static Config Instance { get { _instance ??= Load(); return _instance; } }
|
|
public static string ConfigPath => Path.Combine(Datas.DataPath, "Config.json");
|
|
static bool _first = true;
|
|
public static Config Load()
|
|
{
|
|
if (File.Exists(ConfigPath))
|
|
{
|
|
try
|
|
{
|
|
var config = Newtonsoft.Json.JsonConvert.DeserializeObject<Config>(File.ReadAllText(ConfigPath))!;
|
|
_oldInstance = config;
|
|
if (_first)
|
|
config.Save();
|
|
return _oldInstance;
|
|
}
|
|
catch
|
|
{
|
|
Console.WriteLine($"配置文件读取失败");
|
|
return _oldInstance!;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
var config = new Config();
|
|
config.Save();
|
|
return config;
|
|
}
|
|
}
|
|
public static void Reload()
|
|
{
|
|
_oldInstance = _instance;
|
|
_instance = null;
|
|
}
|
|
public void Save()
|
|
{
|
|
if (!Directory.Exists(Datas.DataPath))
|
|
Directory.CreateDirectory(Datas.DataPath);
|
|
File.WriteAllText(ConfigPath, JsonSerializer.Serialize(this, DefaultSerializerOptions));
|
|
}
|
|
|
|
|
|
public bool LogDanmakuError { get; set; } = false;
|
|
public string ListenHost { get; set; } = "*";
|
|
public int ListenPort { get; set; } = 4050;
|
|
public string DBConnectString { get; set; } = $"Host=localhost;Port=5432;Username=postgres;Password=!Hzy05152484; Database=MegghysAPI;";
|
|
public string MinIOEndpoint { get; set; } = "eternalland.top:9000";
|
|
public string MinIOAccessKey { get; set; } = "RBzbElm21lf7sy7wK7wG";
|
|
public string MinIOSecretKey { get; set; } = "Nko5azOSUiYgOUeLsj8hLxGz4cKC8XOcH0VS7lWq";
|
|
public string MinIORegion { get; set; } = "cn-main";
|
|
public string MinIOBucket { get; set; } = "general";
|
|
|
|
// DNS解析配置
|
|
public string DnsResolverAccountId { get; set; } = "720341";
|
|
public string DnsResolverAkId { get; set; } = "720341_30798028364391424";
|
|
public string DnsResolverAkSecret { get; set; } = "0739b7584ab54c1b9585f10594af0cd0";
|
|
public string DnsResolverEndpoint { get; set; } = "https://223.5.5.5/resolve";
|
|
}
|
|
}
|