2026-05-29 23:51:23 +08:00
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2026-05-29 18:16:34 +08:00
|
|
|
using MiGu.Server.Launcher;
|
|
|
|
|
|
|
|
|
|
namespace MiGu.Server.Controllers;
|
|
|
|
|
|
|
|
|
|
[ApiController]
|
|
|
|
|
[Route("api/health")]
|
|
|
|
|
public class HealthController : ControllerBase
|
|
|
|
|
{
|
|
|
|
|
private static readonly DateTimeOffset StartTime = DateTimeOffset.UtcNow;
|
|
|
|
|
private readonly SimpleLiteLauncher _launcher;
|
|
|
|
|
|
|
|
|
|
public HealthController(SimpleLiteLauncher launcher) => _launcher = launcher;
|
|
|
|
|
|
2026-06-12 23:00:47 +08:00
|
|
|
/// <summary>匿名存活探针:仅返回进程级状态,不暴露端口拓扑等部署细节。</summary>
|
2026-05-29 18:16:34 +08:00
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Get()
|
|
|
|
|
{
|
|
|
|
|
return Ok(new
|
|
|
|
|
{
|
|
|
|
|
status = "ok",
|
|
|
|
|
startTime = StartTime,
|
2026-06-12 23:00:47 +08:00
|
|
|
uptimeSec = (long)(DateTimeOffset.UtcNow - StartTime).TotalSeconds
|
2026-05-29 18:16:34 +08:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// SimpleLite 拉起配置诊断:查看当前 ExecutablePath、解析结果、端口是否已有服务。
|
|
|
|
|
/// 配置位置:<c>MiGu.Server/appsettings.json</c> → <c>SimpleLite</c> 节点。
|
2026-06-12 23:00:47 +08:00
|
|
|
/// 含服务器本地路径等敏感信息,要求登录。
|
2026-05-29 18:16:34 +08:00
|
|
|
/// </summary>
|
|
|
|
|
[HttpGet("simplelite")]
|
2026-06-12 23:00:47 +08:00
|
|
|
[Authorize]
|
2026-05-29 18:16:34 +08:00
|
|
|
public IActionResult GetSimpleLiteDiagnostics() => Ok(_launcher.GetDiagnostics());
|
2026-05-29 23:51:23 +08:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 关闭 SimpleLite、同步最新 DLL、重新拉起。用于「前往站点」API 缺失时一键更新。
|
2026-06-12 23:00:47 +08:00
|
|
|
/// 会终止本机全部 SimpleLite 进程并重启,仅 Platform 管理端可调。
|
2026-05-29 23:51:23 +08:00
|
|
|
/// </summary>
|
|
|
|
|
[HttpPost("simplelite/restart-for-update")]
|
2026-06-12 23:00:47 +08:00
|
|
|
[Authorize(Policy = "PlatformScope")]
|
2026-05-29 23:51:23 +08:00
|
|
|
public IActionResult RestartSimpleLiteForUpdate([FromQuery] string launchMode = "webonly")
|
|
|
|
|
{
|
|
|
|
|
var result = _launcher.RestartForUpdate(launchMode);
|
|
|
|
|
var diag = _launcher.GetDiagnostics();
|
|
|
|
|
return Ok(new { restart = result, diagnostics = diag });
|
|
|
|
|
}
|
2026-05-29 18:16:34 +08:00
|
|
|
}
|