具备界面基础功能
This commit is contained in:
@@ -326,6 +326,64 @@ public class CamerasController : ControllerBase
|
||||
});
|
||||
}
|
||||
|
||||
[HttpGet("{id}/subscriptions")]
|
||||
public IActionResult GetSubscriptions(long id)
|
||||
{
|
||||
// 1. 检查设备是否存在
|
||||
var camera = _manager.GetDevice(id);
|
||||
if (camera == null)
|
||||
{
|
||||
return NotFound(new { error = $"Camera {id} not found." });
|
||||
}
|
||||
|
||||
// 2. 从设备的 FrameController 获取当前活跃的订阅
|
||||
// 注意:FrameController.GetCurrentRequirements() 返回的是 List<FrameRequirement>
|
||||
// 它可以直接被序列化为 JSON
|
||||
var subs = camera.Controller.GetCurrentRequirements();
|
||||
|
||||
return Ok(subs);
|
||||
}
|
||||
|
||||
// =============================================================
|
||||
// 6. 新增:彻底删除/注销订阅 (RESTful DELETE)
|
||||
// URL: DELETE /api/cameras/{id}/subscriptions/{appId}
|
||||
// =============================================================
|
||||
[HttpDelete("{id}/subscriptions/{appId}")]
|
||||
public IActionResult RemoveSubscription(long id, string appId)
|
||||
{
|
||||
// 1. 检查设备是否存在
|
||||
var device = _manager.GetDevice(id);
|
||||
if (device == null)
|
||||
{
|
||||
return NotFound(new { error = $"Camera {id} not found." });
|
||||
}
|
||||
|
||||
// 2. 获取流控控制器
|
||||
var controller = device.Controller;
|
||||
if (controller == null)
|
||||
{
|
||||
// 如果设备本身没有控制器(比如离线或不支持),也算删除成功
|
||||
return Ok(new { success = true, message = "Device has no controller, nothing to remove." });
|
||||
}
|
||||
|
||||
// 3. 执行注销逻辑 (核心)
|
||||
// 从 FrameController 的分发列表中移除
|
||||
controller.Unregister(appId);
|
||||
|
||||
// 4. 清理显示资源 (重要!)
|
||||
// 参考您 UpdateSubscription 中的逻辑,必须同时停止 DisplayManager,否则窗口关不掉
|
||||
_displayManager.StopDisplay(appId);
|
||||
|
||||
// 5. 记录审计日志
|
||||
device.AddAuditLog($"用户指令:彻底注销订阅 [{appId}]");
|
||||
|
||||
return Ok(new
|
||||
{
|
||||
success = true,
|
||||
message = $"Subscription {appId} has been removed and display stopped."
|
||||
});
|
||||
}
|
||||
|
||||
// 1. 获取单个设备详情(用于编辑回填)
|
||||
[HttpGet("{id}")]
|
||||
public IActionResult GetDevice(int id)
|
||||
|
||||
Reference in New Issue
Block a user