refactor: 重构数据库相关操作

This commit is contained in:
2025-08-10 20:13:44 +08:00
parent 079004c17d
commit b95a61c532
20 changed files with 2252 additions and 2065 deletions

View File

@@ -3,7 +3,6 @@ using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using System.Security.Claims;
using Database;
using DotNext;
/// <summary>
@@ -15,44 +14,21 @@ using DotNext;
public class VideoStreamController : ControllerBase
{
private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
private readonly server.Services.HttpVideoStreamService _videoStreamService;
/// <summary>
/// 分辨率配置请求模型
/// </summary>
public class ResolutionConfigRequest
{
/// <summary>
/// 宽度
/// </summary>
[Required]
[Range(640, 1920, ErrorMessage = "宽度必须在640-1920范围内")]
public int Width { get; set; }
/// <summary>
/// 高度
/// </summary>
[Required]
[Range(480, 1080, ErrorMessage = "高度必须在480-1080范围内")]
public int Height { get; set; }
}
public class AvailableResolutionsResponse
{
public int Width { get; set; }
public int Height { get; set; }
public string Name { get; set; } = string.Empty;
public string Value => $"{Width}x{Height}";
}
private readonly Database.UserManager _userManager;
/// <summary>
/// 初始化HTTP视频流控制器
/// </summary>
/// <param name="videoStreamService">HTTP视频流服务</param>
public VideoStreamController(server.Services.HttpVideoStreamService videoStreamService)
/// <param name="userManager">用户管理服务</param>
public VideoStreamController(
server.Services.HttpVideoStreamService videoStreamService, Database.UserManager userManager)
{
logger.Info("创建VideoStreamController命名空间{Namespace}", this.GetType().Namespace);
_videoStreamService = videoStreamService;
_userManager = userManager;
}
private Optional<string> TryGetBoardId()
@@ -64,14 +40,7 @@ public class VideoStreamController : ControllerBase
return Optional<string>.None;
}
var db = new AppDataConnection();
if (db == null)
{
logger.Error("Database connection failed.");
return Optional<string>.None;
}
var userRet = db.GetUserByName(userName);
var userRet = _userManager.GetUserByName(userName);
if (!userRet.IsSuccessful || !userRet.Value.HasValue)
{
logger.Error("User not found.");
@@ -349,4 +318,32 @@ public class VideoStreamController : ControllerBase
return TypedResults.InternalServerError($"执行自动对焦失败: {ex.Message}");
}
}
/// <summary>
/// 分辨率配置请求模型
/// </summary>
public class ResolutionConfigRequest
{
/// <summary>
/// 宽度
/// </summary>
[Required]
[Range(640, 1920, ErrorMessage = "宽度必须在640-1920范围内")]
public int Width { get; set; }
/// <summary>
/// 高度
/// </summary>
[Required]
[Range(480, 1080, ErrorMessage = "高度必须在480-1080范围内")]
public int Height { get; set; }
}
public class AvailableResolutionsResponse
{
public int Width { get; set; }
public int Height { get; set; }
public string Name { get; set; } = string.Empty;
public string Value => $"{Width}x{Height}";
}
}