Files
FlyShotHost/src/Flyshot.Server.Host/Controllers/StatusController.cs
yunxiao.zhu c38faddbf0 feat(server): 添加静态状态页与调试入口
- 将状态页、调试页改为 `wwwroot` 静态资源
  - 补充调试配置接口与前端脚本
  - 为兼容层、规划层和运行时补充日志
  - 更新集成测试覆盖新入口
2026-04-29 14:05:02 +08:00

73 lines
2.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Flyshot.ControllerClientCompat;
using Microsoft.AspNetCore.Mvc;
namespace Flyshot.Server.Host.Controllers;
/// <summary>
/// 提供控制器状态快照 API状态监控页面由 wwwroot 静态资源承载。
/// </summary>
[ApiController]
[Tags("基础与状态")]
public sealed class StatusController : ControllerBase
{
private readonly IControllerClientCompatService _compatService;
/// <summary>
/// 初始化状态监控控制器。
/// </summary>
/// <param name="compatService">ControllerClient 兼容层服务。</param>
public StatusController(IControllerClientCompatService compatService)
{
_compatService = compatService ?? throw new ArgumentNullException(nameof(compatService));
}
/// <summary>
/// 提供短路由 `/status`,跳转到静态状态页。
/// </summary>
/// <returns>重定向到 <c>/status.html</c>。</returns>
[HttpGet("/status")]
public IActionResult StatusPage()
{
return Redirect("/status.html");
}
/// <summary>
/// 提供短路由 `/debug`,跳转到静态调试页。
/// </summary>
/// <returns>重定向到 <c>/debug.html</c>。</returns>
[HttpGet("/debug")]
public IActionResult DebugPage()
{
return Redirect("/debug.html");
}
/// <summary>
/// 返回当前 ControllerClient 兼容层与控制器运行时状态快照。
/// </summary>
/// <returns>面向状态页和外部诊断的 JSON 快照。</returns>
[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<string>();
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
});
}
}