后端: - 新增 ManagedLibraryRoot / ManagedFileRecord 数据模型及 SQLite 迁移 - 新增文件库服务、端点服务及定时扫描后台任务 - 新增 REST API: drives、directories、roots CRUD、files 分页搜索、文本预览 - 新增文件流端点支持视频/音频流式传输 - 数据库切换为 SQLite,Kestrel 绑定 0.0.0.0 支持局域网访问 前端: - 管理端:磁盘浏览、目录选择、根目录添加/启用/删除/扫描 - 客户端:根目录选择、文件搜索/筛选/分页、音视频播放、文本预览 - 全新响应式 UI(桌面+移动端),CSS 变量设计系统 - HTTP 客户端支持 Vite 开发代理与生产同源自动切换 - 移除 HTTPS 强制重定向以提升移动端视频流兼容性
39 lines
1.3 KiB
C#
39 lines
1.3 KiB
C#
using Avalonia_Services.Services.FileLibrary;
|
|
|
|
namespace Avalonia_API.Services
|
|
{
|
|
public sealed class FileLibraryScanHostedService(IServiceScopeFactory scopeFactory, ILogger<FileLibraryScanHostedService> logger)
|
|
: BackgroundService
|
|
{
|
|
private static readonly TimeSpan Interval = TimeSpan.FromMinutes(1);
|
|
|
|
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
|
{
|
|
await ScanAsync(stoppingToken);
|
|
|
|
using var timer = new PeriodicTimer(Interval);
|
|
while (await timer.WaitForNextTickAsync(stoppingToken))
|
|
{
|
|
await ScanAsync(stoppingToken);
|
|
}
|
|
}
|
|
|
|
private async Task ScanAsync(CancellationToken cancellationToken)
|
|
{
|
|
try
|
|
{
|
|
await using var scope = scopeFactory.CreateAsyncScope();
|
|
var scanner = scope.ServiceProvider.GetRequiredService<IFileLibraryService>();
|
|
await scanner.ScanDueRootsAsync(cancellationToken);
|
|
}
|
|
catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested)
|
|
{
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logger.LogWarning(ex, "文件库定时扫描失败。");
|
|
}
|
|
}
|
|
}
|
|
}
|