lvfengfree 9e3b1f3c03 feat: 添加远程桌面Token分享功能
- 新增 WindowsCredential 模型和控制器,用于管理 Windows 凭据
- 新增 RemoteAccessToken 模型,支持生成可分享的远程访问链接
- 更新 RemoteDesktopController,添加 Token 生成、验证、撤销等 API
- 更新前端 RemoteDesktopModal,支持4种连接方式:快速连接、生成分享链接、手动输入、链接管理
- 新增 WindowsCredentialManager 组件用于管理 Windows 凭据
- 新增 RemoteAccessPage 用于通过 Token 访问远程桌面
- 添加 Vue Router 支持 /remote/:token 路由
- 更新数据库迁移,添加 WindowsCredentials 和 RemoteAccessTokens 表
2026-01-20 15:00:44 +08:00

97 lines
3.2 KiB
C#

using AmtScanner.Api.Models;
using Microsoft.EntityFrameworkCore;
namespace AmtScanner.Api.Data;
public class AppDbContext : DbContext
{
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options)
{
}
public DbSet<AmtDevice> AmtDevices { get; set; }
public DbSet<AmtCredential> AmtCredentials { get; set; }
public DbSet<HardwareInfo> HardwareInfos { get; set; }
public DbSet<MemoryModule> MemoryModules { get; set; }
public DbSet<StorageDevice> StorageDevices { get; set; }
public DbSet<WindowsCredential> WindowsCredentials { get; set; }
public DbSet<RemoteAccessToken> RemoteAccessTokens { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
// 限制索引字段长度以适应 MySQL
modelBuilder.Entity<AmtDevice>()
.Property(d => d.IpAddress)
.HasMaxLength(50);
modelBuilder.Entity<AmtDevice>()
.HasIndex(d => d.IpAddress)
.IsUnique();
modelBuilder.Entity<AmtCredential>()
.Property(c => c.Name)
.HasMaxLength(200);
modelBuilder.Entity<AmtCredential>()
.HasIndex(c => c.Name);
// HardwareInfo 配置
modelBuilder.Entity<HardwareInfo>()
.HasOne(h => h.Device)
.WithMany()
.HasForeignKey(h => h.DeviceId)
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<HardwareInfo>()
.HasIndex(h => h.DeviceId);
modelBuilder.Entity<HardwareInfo>()
.HasIndex(h => h.LastUpdated);
// MemoryModule 配置
modelBuilder.Entity<MemoryModule>()
.HasOne(m => m.HardwareInfo)
.WithMany(h => h.MemoryModules)
.HasForeignKey(m => m.HardwareInfoId)
.OnDelete(DeleteBehavior.Cascade);
// StorageDevice 配置
modelBuilder.Entity<StorageDevice>()
.HasOne(s => s.HardwareInfo)
.WithMany(h => h.StorageDevices)
.HasForeignKey(s => s.HardwareInfoId)
.OnDelete(DeleteBehavior.Cascade);
// WindowsCredential 配置
modelBuilder.Entity<WindowsCredential>()
.Property(w => w.Name)
.HasMaxLength(200);
modelBuilder.Entity<WindowsCredential>()
.HasIndex(w => w.Name);
// RemoteAccessToken 配置
modelBuilder.Entity<RemoteAccessToken>()
.Property(t => t.Token)
.HasMaxLength(64);
modelBuilder.Entity<RemoteAccessToken>()
.HasIndex(t => t.Token)
.IsUnique();
modelBuilder.Entity<RemoteAccessToken>()
.HasOne(t => t.Device)
.WithMany()
.HasForeignKey(t => t.DeviceId)
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<RemoteAccessToken>()
.HasOne(t => t.WindowsCredential)
.WithMany()
.HasForeignKey(t => t.WindowsCredentialId)
.OnDelete(DeleteBehavior.SetNull);
}
}