- 新增 VideoThumbnailService,基于 ffmpeg 截取视频缩略图,ffprobe 提取时长
- 新增 ManagedThumbnailMap 模型及多数据库迁移,存储缩略图元数据
- 新增 /api/thumbnails/{id} 缩略图流端点
- 新增最近添加/最近播放 API 与前端面板,支持列表/网格双视图切换
- FileRecordDto 扩展 thumbnailUrl、videoDuration、lastPlayedAt 字段
- 前端新增文件库 Tab 导航、卡片网格视图、视频海报与时长信息栏
- 添加文件库目录不再同步全量扫描,改为后台异步自动扫描
79 lines
3.2 KiB
C#
79 lines
3.2 KiB
C#
using FileShare_Services.Services.FileLibrary;
|
|
|
|
namespace FileShare_API.Extensions
|
|
{
|
|
/// <summary>
|
|
/// API-only raw file stream endpoints used by browser media elements.
|
|
/// </summary>
|
|
public static class FileStreamEndpointExtensions
|
|
{
|
|
/// <summary>
|
|
/// Map the media URL emitted by <see cref="FileRecordDto"/>.
|
|
/// </summary>
|
|
public static IEndpointRouteBuilder MapFileStreamEndpoints(this IEndpointRouteBuilder app)
|
|
{
|
|
app.MapMethods(
|
|
"/api/files/{id:int}/stream",
|
|
["GET", "HEAD"],
|
|
async (int id, IFileStreamService fileStreamService, HttpContext httpContext) =>
|
|
{
|
|
var fileResponse = await fileStreamService.GetFileStreamAsync(id);
|
|
if (fileResponse is null)
|
|
{
|
|
return Results.NotFound();
|
|
}
|
|
|
|
var stream = System.IO.File.Open(
|
|
fileResponse.FilePath,
|
|
FileMode.Open,
|
|
FileAccess.Read,
|
|
FileShare.ReadWrite);
|
|
|
|
httpContext.Response.Headers.ContentDisposition =
|
|
$"inline; filename=\"{Uri.EscapeDataString(fileResponse.FileName)}\"";
|
|
httpContext.Response.Headers.AcceptRanges = "bytes";
|
|
httpContext.Response.Headers.CacheControl = "public, max-age=3600";
|
|
|
|
return Results.File(
|
|
stream,
|
|
contentType: fileResponse.ContentType,
|
|
lastModified: fileResponse.LastModified,
|
|
enableRangeProcessing: true);
|
|
})
|
|
.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;
|
|
}
|
|
}
|
|
}
|