feat: 新增文件库功能,支持局域网文件浏览与媒体播放

后端:
- 新增 ManagedLibraryRoot / ManagedFileRecord 数据模型及 SQLite 迁移
- 新增文件库服务、端点服务及定时扫描后台任务
- 新增 REST API: drives、directories、roots CRUD、files 分页搜索、文本预览
- 新增文件流端点支持视频/音频流式传输
- 数据库切换为 SQLite,Kestrel 绑定 0.0.0.0 支持局域网访问

前端:
- 管理端:磁盘浏览、目录选择、根目录添加/启用/删除/扫描
- 客户端:根目录选择、文件搜索/筛选/分页、音视频播放、文本预览
- 全新响应式 UI(桌面+移动端),CSS 变量设计系统
- HTTP 客户端支持 Vite 开发代理与生产同源自动切换
- 移除 HTTPS 强制重定向以提升移动端视频流兼容性
This commit is contained in:
2026-05-21 16:45:56 +08:00
parent e3fe965f10
commit a68bb6c4b3
31 changed files with 3162 additions and 85 deletions
@@ -0,0 +1,352 @@
// <auto-generated />
using System;
using Avalonia_EFCore.Database;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace Avalonia_EFCore.Migrations.SQLite
{
[DbContext(typeof(SqliteAppDataContext))]
[Migration("20260521080213_AddFileLibrary")]
partial class AddFileLibrary
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "10.0.7");
modelBuilder.Entity("Avalonia_EFCore.Models.ApiRefreshTokenEntity", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER")
.HasColumnName("id");
b.Property<DateTime>("CreatedAt")
.HasColumnType("TEXT")
.HasColumnName("created-at");
b.Property<string>("Device")
.HasMaxLength(200)
.HasColumnType("TEXT")
.HasColumnName("device");
b.Property<DateTime>("ExpiresAt")
.HasColumnType("TEXT")
.HasColumnName("expires-at");
b.Property<string>("IpAddress")
.HasMaxLength(64)
.HasColumnType("TEXT")
.HasColumnName("ip-address");
b.Property<string>("ReplacedByTokenHash")
.HasMaxLength(128)
.HasColumnType("TEXT")
.HasColumnName("replaced-by-token-hash");
b.Property<DateTime?>("RevokedAt")
.HasColumnType("TEXT")
.HasColumnName("revoked-at");
b.Property<string>("TokenHash")
.IsRequired()
.HasMaxLength(128)
.HasColumnType("TEXT")
.HasColumnName("token-hash");
b.Property<int>("UserId")
.HasColumnType("INTEGER")
.HasColumnName("user-id");
b.HasKey("Id")
.HasName("pk-api-refresh-token");
b.HasIndex("TokenHash")
.IsUnique()
.HasDatabaseName("idx-api-refresh-token-hash");
b.HasIndex("UserId")
.HasDatabaseName("idx-api-refresh-token-user-id");
b.ToTable("api-refresh-token", t =>
{
t.HasComment("API refresh token");
});
});
modelBuilder.Entity("Avalonia_EFCore.Models.ManagedFileRecord", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER")
.HasColumnName("id");
b.Property<string>("AbsolutePath")
.IsRequired()
.HasMaxLength(2048)
.HasColumnType("TEXT")
.HasColumnName("absolute-path");
b.Property<string>("ContentType")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("TEXT")
.HasColumnName("content-type");
b.Property<DateTime>("CreatedAt")
.HasColumnType("TEXT")
.HasColumnName("created-at");
b.Property<bool>("Exists")
.HasColumnType("INTEGER")
.HasColumnName("exists");
b.Property<string>("Extension")
.IsRequired()
.HasMaxLength(32)
.HasColumnType("TEXT")
.HasColumnName("extension");
b.Property<string>("FileName")
.IsRequired()
.HasMaxLength(260)
.HasColumnType("TEXT")
.HasColumnName("file-name");
b.Property<DateTime>("LastSeenAt")
.HasColumnType("TEXT")
.HasColumnName("last-seen-at");
b.Property<DateTime>("LastWriteTimeUtc")
.HasColumnType("TEXT")
.HasColumnName("last-write-time-utc");
b.Property<int>("LibraryRootId")
.HasColumnType("INTEGER")
.HasColumnName("library-root-id");
b.Property<string>("MediaType")
.IsRequired()
.HasMaxLength(20)
.HasColumnType("TEXT")
.HasColumnName("media-type");
b.Property<string>("RelativePath")
.IsRequired()
.HasMaxLength(1024)
.HasColumnType("TEXT")
.HasColumnName("relative-path");
b.Property<long>("SizeBytes")
.HasColumnType("INTEGER")
.HasColumnName("size-bytes");
b.Property<DateTime>("UpdatedAt")
.HasColumnType("TEXT")
.HasColumnName("updated-at");
b.HasKey("Id")
.HasName("pk-managed-file-record");
b.HasIndex("AbsolutePath")
.IsUnique()
.HasDatabaseName("idx-managed-file-record-absolute-path");
b.HasIndex("LibraryRootId")
.HasDatabaseName("idx-managed-file-record-root-id");
b.HasIndex("MediaType", "Exists")
.HasDatabaseName("idx-managed-file-record-media-type-exists");
b.ToTable("managed-file-record", t =>
{
t.HasComment("文件库文件记录");
});
});
modelBuilder.Entity("Avalonia_EFCore.Models.ManagedLibraryRoot", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER")
.HasColumnName("id");
b.Property<DateTime>("CreatedAt")
.HasColumnType("TEXT")
.HasColumnName("created-at");
b.Property<string>("DisplayName")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("TEXT")
.HasColumnName("display-name");
b.Property<bool>("IsAvailable")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER")
.HasDefaultValue(true)
.HasColumnName("is-available");
b.Property<bool>("IsEnabled")
.HasColumnType("INTEGER")
.HasColumnName("is-enabled");
b.Property<DateTime?>("LastScanCompletedAt")
.HasColumnType("TEXT")
.HasColumnName("last-scan-completed-at");
b.Property<string>("LastScanError")
.HasMaxLength(2000)
.HasColumnType("TEXT")
.HasColumnName("last-scan-error");
b.Property<DateTime?>("LastScanStartedAt")
.HasColumnType("TEXT")
.HasColumnName("last-scan-started-at");
b.Property<string>("Path")
.IsRequired()
.HasMaxLength(1024)
.HasColumnType("TEXT")
.HasColumnName("path");
b.Property<int>("ScanIntervalMinutes")
.HasColumnType("INTEGER")
.HasColumnName("scan-interval-minutes");
b.Property<DateTime>("UpdatedAt")
.HasColumnType("TEXT")
.HasColumnName("updated-at");
b.HasKey("Id")
.HasName("pk-managed-library-root");
b.HasIndex("Path")
.IsUnique()
.HasDatabaseName("idx-managed-library-root-path");
b.ToTable("managed-library-root", t =>
{
t.HasComment("文件库根目录");
});
});
modelBuilder.Entity("Avalonia_EFCore.Models.UserEntity", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER")
.HasColumnName("id")
.HasComment("用户主键");
b.Property<DateTime>("CreatedAt")
.HasColumnType("TEXT")
.HasColumnName("created-at")
.HasComment("创建时间");
b.Property<string>("Email")
.HasMaxLength(200)
.HasColumnType("TEXT")
.HasColumnName("email")
.HasComment("用户邮箱");
b.Property<string>("Name")
.HasMaxLength(100)
.HasColumnType("TEXT")
.HasColumnName("name")
.HasComment("用户名称");
b.Property<string>("PasswordHash")
.HasMaxLength(200)
.HasColumnType("TEXT")
.HasColumnName("password-hash")
.HasComment("密码哈希值");
b.Property<string>("PhoneNumber")
.HasMaxLength(50)
.HasColumnType("TEXT")
.HasColumnName("phone-number")
.HasComment("电话号码");
b.Property<DateTime>("UpdatedAt")
.HasColumnType("TEXT")
.HasColumnName("updated-at")
.HasComment("更新时间");
b.HasKey("Id")
.HasName("pk-user");
b.ToTable("user", t =>
{
t.HasComment("用户实体,演示数据库 CRUD 操作");
});
});
modelBuilder.Entity("Avalonia_EFCore.Models.WeatherForecastEntity", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER")
.HasColumnName("id")
.HasComment("天气预报主键");
b.Property<DateTime>("CreatedAt")
.HasColumnType("TEXT")
.HasColumnName("created-at")
.HasComment("创建时间");
b.Property<DateOnly>("Date")
.HasColumnType("TEXT")
.HasColumnName("date")
.HasComment("预报日期");
b.Property<string>("Summary")
.HasMaxLength(200)
.HasColumnType("TEXT")
.HasColumnName("summary")
.HasComment("天气摘要");
b.Property<int>("TemperatureC")
.HasColumnType("INTEGER")
.HasColumnName("temperature-c")
.HasComment("摄氏温度");
b.Property<DateTime>("UpdatedAt")
.HasColumnType("TEXT")
.HasColumnName("updated-at")
.HasComment("更新时间");
b.HasKey("Id")
.HasName("pk-weather-forecast");
b.ToTable("weather-forecast", t =>
{
t.HasComment("天气预报数据实体");
});
});
modelBuilder.Entity("Avalonia_EFCore.Models.ManagedFileRecord", b =>
{
b.HasOne("Avalonia_EFCore.Models.ManagedLibraryRoot", "LibraryRoot")
.WithMany("Files")
.HasForeignKey("LibraryRootId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("LibraryRoot");
});
modelBuilder.Entity("Avalonia_EFCore.Models.ManagedLibraryRoot", b =>
{
b.Navigation("Files");
});
#pragma warning restore 612, 618
}
}
}
@@ -0,0 +1,102 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Avalonia_EFCore.Migrations.SQLite
{
/// <inheritdoc />
public partial class AddFileLibrary : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "managed-library-root",
columns: table => new
{
id = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
path = table.Column<string>(type: "TEXT", maxLength: 1024, nullable: false),
displayname = table.Column<string>(name: "display-name", type: "TEXT", maxLength: 200, nullable: false),
isenabled = table.Column<bool>(name: "is-enabled", type: "INTEGER", nullable: false),
isavailable = table.Column<bool>(name: "is-available", type: "INTEGER", nullable: false, defaultValue: true),
scanintervalminutes = table.Column<int>(name: "scan-interval-minutes", type: "INTEGER", nullable: false),
lastscanstartedat = table.Column<DateTime>(name: "last-scan-started-at", type: "TEXT", nullable: true),
lastscancompletedat = table.Column<DateTime>(name: "last-scan-completed-at", type: "TEXT", nullable: true),
lastscanerror = table.Column<string>(name: "last-scan-error", type: "TEXT", maxLength: 2000, nullable: true),
createdat = table.Column<DateTime>(name: "created-at", type: "TEXT", nullable: false),
updatedat = table.Column<DateTime>(name: "updated-at", type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("pk-managed-library-root", x => x.id);
},
comment: "文件库根目录");
migrationBuilder.CreateTable(
name: "managed-file-record",
columns: table => new
{
id = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
libraryrootid = table.Column<int>(name: "library-root-id", type: "INTEGER", nullable: false),
filename = table.Column<string>(name: "file-name", type: "TEXT", maxLength: 260, nullable: false),
relativepath = table.Column<string>(name: "relative-path", type: "TEXT", maxLength: 1024, nullable: false),
absolutepath = table.Column<string>(name: "absolute-path", type: "TEXT", maxLength: 2048, nullable: false),
extension = table.Column<string>(type: "TEXT", maxLength: 32, nullable: false),
sizebytes = table.Column<long>(name: "size-bytes", type: "INTEGER", nullable: false),
lastwritetimeutc = table.Column<DateTime>(name: "last-write-time-utc", type: "TEXT", nullable: false),
mediatype = table.Column<string>(name: "media-type", type: "TEXT", maxLength: 20, nullable: false),
contenttype = table.Column<string>(name: "content-type", type: "TEXT", maxLength: 100, nullable: false),
exists = table.Column<bool>(type: "INTEGER", nullable: false),
lastseenat = table.Column<DateTime>(name: "last-seen-at", type: "TEXT", nullable: false),
createdat = table.Column<DateTime>(name: "created-at", type: "TEXT", nullable: false),
updatedat = table.Column<DateTime>(name: "updated-at", type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("pk-managed-file-record", x => x.id);
table.ForeignKey(
name: "FK_managed-file-record_managed-library-root_library-root-id",
column: x => x.libraryrootid,
principalTable: "managed-library-root",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
},
comment: "文件库文件记录");
migrationBuilder.CreateIndex(
name: "idx-managed-file-record-absolute-path",
table: "managed-file-record",
column: "absolute-path",
unique: true);
migrationBuilder.CreateIndex(
name: "idx-managed-file-record-media-type-exists",
table: "managed-file-record",
columns: new[] { "media-type", "exists" });
migrationBuilder.CreateIndex(
name: "idx-managed-file-record-root-id",
table: "managed-file-record",
column: "library-root-id");
migrationBuilder.CreateIndex(
name: "idx-managed-library-root-path",
table: "managed-library-root",
column: "path",
unique: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "managed-file-record");
migrationBuilder.DropTable(
name: "managed-library-root");
}
}
}
@@ -77,6 +77,163 @@ namespace Avalonia_EFCore.Migrations.SQLite
});
});
modelBuilder.Entity("Avalonia_EFCore.Models.ManagedFileRecord", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER")
.HasColumnName("id");
b.Property<string>("AbsolutePath")
.IsRequired()
.HasMaxLength(2048)
.HasColumnType("TEXT")
.HasColumnName("absolute-path");
b.Property<string>("ContentType")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("TEXT")
.HasColumnName("content-type");
b.Property<DateTime>("CreatedAt")
.HasColumnType("TEXT")
.HasColumnName("created-at");
b.Property<bool>("Exists")
.HasColumnType("INTEGER")
.HasColumnName("exists");
b.Property<string>("Extension")
.IsRequired()
.HasMaxLength(32)
.HasColumnType("TEXT")
.HasColumnName("extension");
b.Property<string>("FileName")
.IsRequired()
.HasMaxLength(260)
.HasColumnType("TEXT")
.HasColumnName("file-name");
b.Property<DateTime>("LastSeenAt")
.HasColumnType("TEXT")
.HasColumnName("last-seen-at");
b.Property<DateTime>("LastWriteTimeUtc")
.HasColumnType("TEXT")
.HasColumnName("last-write-time-utc");
b.Property<int>("LibraryRootId")
.HasColumnType("INTEGER")
.HasColumnName("library-root-id");
b.Property<string>("MediaType")
.IsRequired()
.HasMaxLength(20)
.HasColumnType("TEXT")
.HasColumnName("media-type");
b.Property<string>("RelativePath")
.IsRequired()
.HasMaxLength(1024)
.HasColumnType("TEXT")
.HasColumnName("relative-path");
b.Property<long>("SizeBytes")
.HasColumnType("INTEGER")
.HasColumnName("size-bytes");
b.Property<DateTime>("UpdatedAt")
.HasColumnType("TEXT")
.HasColumnName("updated-at");
b.HasKey("Id")
.HasName("pk-managed-file-record");
b.HasIndex("AbsolutePath")
.IsUnique()
.HasDatabaseName("idx-managed-file-record-absolute-path");
b.HasIndex("LibraryRootId")
.HasDatabaseName("idx-managed-file-record-root-id");
b.HasIndex("MediaType", "Exists")
.HasDatabaseName("idx-managed-file-record-media-type-exists");
b.ToTable("managed-file-record", t =>
{
t.HasComment("文件库文件记录");
});
});
modelBuilder.Entity("Avalonia_EFCore.Models.ManagedLibraryRoot", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER")
.HasColumnName("id");
b.Property<DateTime>("CreatedAt")
.HasColumnType("TEXT")
.HasColumnName("created-at");
b.Property<string>("DisplayName")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("TEXT")
.HasColumnName("display-name");
b.Property<bool>("IsAvailable")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER")
.HasDefaultValue(true)
.HasColumnName("is-available");
b.Property<bool>("IsEnabled")
.HasColumnType("INTEGER")
.HasColumnName("is-enabled");
b.Property<DateTime?>("LastScanCompletedAt")
.HasColumnType("TEXT")
.HasColumnName("last-scan-completed-at");
b.Property<string>("LastScanError")
.HasMaxLength(2000)
.HasColumnType("TEXT")
.HasColumnName("last-scan-error");
b.Property<DateTime?>("LastScanStartedAt")
.HasColumnType("TEXT")
.HasColumnName("last-scan-started-at");
b.Property<string>("Path")
.IsRequired()
.HasMaxLength(1024)
.HasColumnType("TEXT")
.HasColumnName("path");
b.Property<int>("ScanIntervalMinutes")
.HasColumnType("INTEGER")
.HasColumnName("scan-interval-minutes");
b.Property<DateTime>("UpdatedAt")
.HasColumnType("TEXT")
.HasColumnName("updated-at");
b.HasKey("Id")
.HasName("pk-managed-library-root");
b.HasIndex("Path")
.IsUnique()
.HasDatabaseName("idx-managed-library-root-path");
b.ToTable("managed-library-root", t =>
{
t.HasComment("文件库根目录");
});
});
modelBuilder.Entity("Avalonia_EFCore.Models.UserEntity", b =>
{
b.Property<int>("Id")
@@ -170,6 +327,22 @@ namespace Avalonia_EFCore.Migrations.SQLite
t.HasComment("天气预报数据实体");
});
});
modelBuilder.Entity("Avalonia_EFCore.Models.ManagedFileRecord", b =>
{
b.HasOne("Avalonia_EFCore.Models.ManagedLibraryRoot", "LibraryRoot")
.WithMany("Files")
.HasForeignKey("LibraryRootId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("LibraryRoot");
});
modelBuilder.Entity("Avalonia_EFCore.Models.ManagedLibraryRoot", b =>
{
b.Navigation("Files");
});
#pragma warning restore 612, 618
}
}