feat: 视频缩略图生成、最近文件面板与前端视图重构

- 新增 VideoThumbnailService,基于 ffmpeg 截取视频缩略图,ffprobe 提取时长
  - 新增 ManagedThumbnailMap 模型及多数据库迁移,存储缩略图元数据
  - 新增 /api/thumbnails/{id} 缩略图流端点
  - 新增最近添加/最近播放 API 与前端面板,支持列表/网格双视图切换
  - FileRecordDto 扩展 thumbnailUrl、videoDuration、lastPlayedAt 字段
  - 前端新增文件库 Tab 导航、卡片网格视图、视频海报与时长信息栏
  - 添加文件库目录不再同步全量扫描,改为后台异步自动扫描
This commit is contained in:
2026-05-22 17:01:49 +08:00
parent 6acc92ca27
commit 2c20f9bb54
47 changed files with 5975 additions and 64 deletions
@@ -40,6 +40,14 @@ namespace FileShare_API.Configuration
// ---- 业务服务 ----
services.AddScoped<WeatherForecastService>();
var thumbnailOptions = configuration
.GetSection(nameof(ThumbnailStorageOptions))
.Get<ThumbnailStorageOptions>()
?? new ThumbnailStorageOptions();
services.AddSingleton(thumbnailOptions);
services.AddSingleton<IVideoThumbnailService>(sp =>
new VideoThumbnailService(sp.GetRequiredService<ThumbnailStorageOptions>()));
services.AddScoped<IThumbnailStreamService, ThumbnailStreamService>();
services.AddScoped<IFileLibraryService, FileLibraryService>();
services.AddScoped<IFileLibraryEndpointService, FileLibraryEndpointService>();
services.AddScoped<IFileStreamService, FileStreamService>();
@@ -43,6 +43,35 @@ namespace FileShare_API.Extensions
.WithName("StreamManagedFileById")
.WithTags("FileLibrary");
app.MapMethods(
"/api/thumbnails/{id:int}",
["GET", "HEAD"],
async (int id, IThumbnailStreamService thumbnailStreamService, HttpContext httpContext) =>
{
var thumbnail = await thumbnailStreamService.GetThumbnailAsync(id);
if (thumbnail is null)
{
return Results.NotFound();
}
var stream = System.IO.File.Open(
thumbnail.FilePath,
FileMode.Open,
FileAccess.Read,
FileShare.ReadWrite);
httpContext.Response.Headers.ContentDisposition =
$"inline; filename=\"{Uri.EscapeDataString(thumbnail.FileName)}\"";
httpContext.Response.Headers.CacheControl = "public, max-age=3600";
return Results.File(
stream,
contentType: thumbnail.ContentType,
lastModified: thumbnail.LastModified);
})
.WithName("StreamManagedThumbnailById")
.WithTags("FileLibrary");
return app;
}
}
+2
View File
@@ -26,6 +26,8 @@
<ItemGroup>
<Folder Include="Controllers\" />
<Content Include="..\tools\ffmpeg\bin\ffmpeg.exe" Link="tools\ffmpeg\bin\ffmpeg.exe" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="PreserveNewest" />
<Content Include="..\tools\ffmpeg\bin\ffprobe.exe" Link="tools\ffmpeg\bin\ffprobe.exe" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="PreserveNewest" />
</ItemGroup>
<Target Name="RestoreFrontendPackages" BeforeTargets="Build" Condition="'$(SkipFrontendBuild)' != 'true' And Exists('..\FileShare-Web-VUE\package.json') And !Exists('..\FileShare-Web-VUE\node_modules')">
+5
View File
@@ -24,5 +24,10 @@
"RecreateDatabase": false,
"EnableDetailedLog": false,
"Timeout": 30
},
"ThumbnailStorageOptions": {
"RootPath": "thumbnails",
"FfmpegPath": "tools/ffmpeg/bin/ffmpeg.exe",
"FfprobePath": "tools/ffmpeg/bin/ffprobe.exe"
}
}