- 新增 VideoThumbnailService,基于 ffmpeg 截取视频缩略图,ffprobe 提取时长
- 新增 ManagedThumbnailMap 模型及多数据库迁移,存储缩略图元数据
- 新增 /api/thumbnails/{id} 缩略图流端点
- 新增最近添加/最近播放 API 与前端面板,支持列表/网格双视图切换
- FileRecordDto 扩展 thumbnailUrl、videoDuration、lastPlayedAt 字段
- 前端新增文件库 Tab 导航、卡片网格视图、视频海报与时长信息栏
- 添加文件库目录不再同步全量扫描,改为后台异步自动扫描
39 lines
1.2 KiB
C#
39 lines
1.2 KiB
C#
using FileShare_EFCore.Database;
|
|
using FileShare_Services.Core;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace FileShare_Services.Services.FileLibrary
|
|
{
|
|
public interface IThumbnailStreamService
|
|
{
|
|
Task<FileStreamResponse?> GetThumbnailAsync(int id, CancellationToken cancellationToken = default);
|
|
}
|
|
|
|
public sealed class ThumbnailStreamService(AppDataContext db, IVideoThumbnailService thumbnails) : IThumbnailStreamService
|
|
{
|
|
public async Task<FileStreamResponse?> GetThumbnailAsync(int id, CancellationToken cancellationToken = default)
|
|
{
|
|
var thumbnail = await db.ManagedThumbnailMaps
|
|
.AsNoTracking()
|
|
.FirstOrDefaultAsync(item => item.Id == id, cancellationToken);
|
|
|
|
if (thumbnail is null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
var absolutePath = thumbnails.GetAbsolutePath(thumbnail.RelativePath);
|
|
if (!File.Exists(absolutePath))
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return new FileStreamResponse(
|
|
absolutePath,
|
|
Path.GetFileName(absolutePath),
|
|
thumbnail.ContentType,
|
|
File.GetLastWriteTimeUtc(absolutePath));
|
|
}
|
|
}
|
|
}
|