- 新增二维码生成端点,自动检测局域网 IP,前端扫一扫即可打开网站 - 提取 IApiResponse 接口,ServiceRequestBinder 支持强类型请求 DTO 绑定 - FileStream 端点迁移至 AppEndpoints 统一注册,管道支持 FileStreamResponse 原始文件返回 - 文件库端点全面使用 MapGet<TService, TRequest> 泛型注册 - 移除 Avalonia-API/Extensions 中的业务端点文件,统一由 Services 层管理
38 lines
1.2 KiB
C#
38 lines
1.2 KiB
C#
using Avalonia_EFCore.Database;
|
|
using Avalonia_EFCore.Models;
|
|
using Avalonia_Services.Core;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Avalonia_Services.Services.FileLibrary
|
|
{
|
|
public interface IFileStreamService
|
|
{
|
|
Task<FileStreamResponse?> GetFileStreamAsync(int id, CancellationToken cancellationToken = default);
|
|
}
|
|
|
|
public sealed class FileStreamService(AppDataContext db) : IFileStreamService
|
|
{
|
|
public async Task<FileStreamResponse?> GetFileStreamAsync(int id, CancellationToken cancellationToken = default)
|
|
{
|
|
var file = await db.ManagedFileRecords
|
|
.AsNoTracking()
|
|
.Include(item => item.LibraryRoot)
|
|
.FirstOrDefaultAsync(item =>
|
|
item.Id == id
|
|
&& item.Exists
|
|
&& item.LibraryRoot != null
|
|
&& item.LibraryRoot.IsAvailable,
|
|
cancellationToken);
|
|
|
|
if (file is null || !System.IO.File.Exists(file.AbsolutePath))
|
|
return null;
|
|
|
|
return new FileStreamResponse(
|
|
file.AbsolutePath,
|
|
file.FileName,
|
|
file.ContentType,
|
|
file.LastWriteTimeUtc);
|
|
}
|
|
}
|
|
}
|