为 14 个项目中缺少 XML 注释的类、接口、方法、属性、字段、record、 枚举等成员补全中文文档注释。接口方法在接口层定义完整注释,实现类 使用 <inheritdoc /> 引用。私有辅助方法结合业务语义编写注释。 扫描结果:missing-csharp-docs.txt 缺失项归零。 构建结果:0 警告,0 错误。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
106 lines
3.9 KiB
C#
106 lines
3.9 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);
|
|
}
|
|
|
|
/// <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 参数无效。");
|
|
}
|
|
}
|
|
}
|