using Flyshot.ControllerClientCompat; using Microsoft.AspNetCore.Mvc; namespace Flyshot.Server.Host.Controllers; /// /// 提供控制器状态快照 API,状态监控页面由 wwwroot 静态资源承载。 /// [ApiController] [Tags("基础与状态")] public sealed class StatusController : ControllerBase { private readonly IControllerClientCompatService _compatService; /// /// 初始化状态监控控制器。 /// /// ControllerClient 兼容层服务。 public StatusController(IControllerClientCompatService compatService) { _compatService = compatService ?? throw new ArgumentNullException(nameof(compatService)); } /// /// 提供短路由 `/status`,跳转到静态状态页。 /// /// 重定向到 /status.html [HttpGet("/status")] public IActionResult StatusPage() { return Redirect("/status.html"); } /// /// 提供短路由 `/debug`,跳转到静态调试页。 /// /// 重定向到 /debug.html [HttpGet("/debug")] public IActionResult DebugPage() { return Redirect("/debug.html"); } /// /// 返回当前 ControllerClient 兼容层与控制器运行时状态快照。 /// /// 面向状态页和外部诊断的 JSON 快照。 [HttpGet("/api/status/snapshot")] public IActionResult GetSnapshot() { var snapshot = _compatService.GetControllerSnapshot(); var isSetup = _compatService.IsSetUp; // 状态页需要在机器人未初始化时仍能打开,因此只有初始化后才读取机器人元数据。 var robotName = isSetup ? _compatService.GetRobotName() : null; var degreesOfFreedom = isSetup ? _compatService.GetDegreesOfFreedom() : 0; var uploadedTrajectories = isSetup ? _compatService.ListTrajectoryNames() : Array.Empty(); return Ok(new { Status = "ok", Service = "flyshot-server-host", ServerVersion = _compatService.GetServerVersion(), ClientVersion = _compatService.GetClientVersion(), IsSetup = isSetup, RobotName = robotName, DegreesOfFreedom = degreesOfFreedom, UploadedTrajectories = uploadedTrajectories, Snapshot = snapshot }); } }