- 新增 VideoThumbnailService,基于 ffmpeg 截取视频缩略图,ffprobe 提取时长
- 新增 ManagedThumbnailMap 模型及多数据库迁移,存储缩略图元数据
- 新增 /api/thumbnails/{id} 缩略图流端点
- 新增最近添加/最近播放 API 与前端面板,支持列表/网格双视图切换
- FileRecordDto 扩展 thumbnailUrl、videoDuration、lastPlayedAt 字段
- 前端新增文件库 Tab 导航、卡片网格视图、视频海报与时长信息栏
- 添加文件库目录不再同步全量扫描,改为后台异步自动扫描
120 lines
4.4 KiB
C#
120 lines
4.4 KiB
C#
using FileShare_Common.Core;
|
|
using FileShare_Services.Core;
|
|
|
|
namespace FileShare_Services.Services.FileLibrary
|
|
{
|
|
/// <summary>
|
|
/// 文件库 HTTP 端点服务,将请求适配到 <see cref="IFileLibraryService"/> 并包装为 <see cref="IApiResponse"/>。
|
|
/// </summary>
|
|
public sealed class FileLibraryEndpointService(IFileLibraryService fileLibrary) : IFileLibraryEndpointService
|
|
{
|
|
/// <inheritdoc />
|
|
public async Task<IApiResponse> GetDrivesAsync(ServiceEndpointContext ctx)
|
|
{
|
|
return ResponseHelper.Ok(await fileLibrary.GetDrivesAsync());
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async Task<IApiResponse> GetDirectoriesAsync(DirectoryQueryRequest request)
|
|
{
|
|
return ResponseHelper.Ok(await fileLibrary.GetDirectoriesAsync(request.Path));
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async Task<IApiResponse> GetRootsAsync(ServiceEndpointContext ctx)
|
|
{
|
|
return ResponseHelper.Ok(await fileLibrary.GetRootsAsync());
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async Task<IApiResponse> AddRootAsync(AddLibraryRootRequest request)
|
|
{
|
|
return ResponseHelper.Ok(await fileLibrary.AddRootAsync(request), "文件库目录已添加,后续扫描将自动入库。");
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async Task<IApiResponse> SetRootEnabledAsync(UpdateLibraryRootRequest request)
|
|
{
|
|
return ResponseHelper.Ok(await fileLibrary.SetRootEnabledAsync(request), "文件库目录状态已更新。");
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async Task<IApiResponse> DeleteRootAsync(DeleteLibraryRootRequest request)
|
|
{
|
|
await fileLibrary.DeleteRootAsync(request);
|
|
return ResponseHelper.Succeed("文件库目录已删除。");
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async Task<IApiResponse> ScanRootAsync(ScanLibraryRootRequest request)
|
|
{
|
|
return ResponseHelper.Ok(await fileLibrary.ScanRootAsync(request.Id), "文件库目录扫描完成。");
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async Task<IApiResponse> SearchFilesAsync(SearchFilesRequest request)
|
|
{
|
|
return await fileLibrary.SearchFilesAsync(request);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async Task<IApiResponse> GetFileAsync(FileQueryRequest request)
|
|
{
|
|
ValidateFileId(request.Id);
|
|
var file = await fileLibrary.GetFileAsync(request.Id);
|
|
return file is null
|
|
? ResponseHelper.Failure(404, "文件不存在或尚未扫描入库。")
|
|
: ResponseHelper.Ok(file);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async Task<IApiResponse> GetTextPreviewAsync(FileQueryRequest request)
|
|
{
|
|
ValidateFileId(request.Id);
|
|
var preview = await fileLibrary.GetTextPreviewAsync(request.Id);
|
|
return preview is null
|
|
? ResponseHelper.Failure(404, "文本文件不存在或无法预览。")
|
|
: ResponseHelper.Ok(preview);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async Task<IApiResponse> BrowseDirectoryAsync(BrowseDirectoryRequest request)
|
|
{
|
|
if (request.RootId <= 0)
|
|
return ResponseHelper.Failure(400, "rootId 参数无效。");
|
|
|
|
var result = await fileLibrary.BrowseDirectoryAsync(request);
|
|
return ResponseHelper.Ok(result);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async Task<IApiResponse> GetRecentFilesAsync(RecentFilesRequest request)
|
|
{
|
|
var items = await fileLibrary.GetRecentFilesAsync(request.Type, request.Count);
|
|
return ResponseHelper.Ok(items);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async Task<IApiResponse> MarkFilePlayedAsync(MarkFilePlayedRequest request)
|
|
{
|
|
await fileLibrary.MarkFilePlayedAsync(request.Id);
|
|
return ResponseHelper.Succeed();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 验证文件 ID 是否有效,无效时抛出 <see cref="ArgumentException"/>。
|
|
/// </summary>
|
|
/// <param name="id">文件记录 ID。</param>
|
|
/// <exception cref="ArgumentException">ID 小于等于 0 时抛出。</exception>
|
|
private static void ValidateFileId(int id)
|
|
{
|
|
if (id > 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
throw new ArgumentException("id 参数无效。");
|
|
}
|
|
}
|
|
}
|