Refactor media storage and management functionalities: enhance IMediaStorage interface with manual inbox handling, update FileSystemMediaStorage to support manual file imports, and improve MediaPathResolver for better path management. Extend MediaEndpoints to include new manual inbox features and update frontend components for improved media management experience.
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
using LiteCqrs;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using TeleWave.Application.Common.Interfaces;
|
||||
using TeleWave.Domain.Media;
|
||||
|
||||
namespace TeleWave.Application.Media.ManualInbox;
|
||||
|
||||
public sealed class ListManualInboxQueryHandler(IAppDbContext dbContext, IMediaStorage storage)
|
||||
: IQueryHandler<ListManualInboxQuery, ManualInboxListDto>
|
||||
{
|
||||
/// <summary>Потолок выдачи: каталог наполняет человек, и он может оказаться огромным.</summary>
|
||||
private const int MaxFiles = 500;
|
||||
|
||||
public async Task<ManualInboxListDto> Handle(
|
||||
ListManualInboxQuery query,
|
||||
CancellationToken cancellationToken
|
||||
)
|
||||
{
|
||||
// Просим на один больше лимита — так видно, что каталог не поместился целиком.
|
||||
var files = storage.ListManualInbox(MaxFiles + 1);
|
||||
var truncated = files.Count > MaxFiles;
|
||||
var page = truncated ? files.Take(MaxFiles).ToList() : files;
|
||||
if (page.Count == 0)
|
||||
return new ManualInboxListDto([], false);
|
||||
|
||||
// Дедуп — по имени файла, тем же правилом, что и при регистрации ассета.
|
||||
var names = page.Select(f => f.Name).Distinct().ToList();
|
||||
var taken = await dbContext
|
||||
.MediaAssets.AsNoTracking()
|
||||
.Where(a => names.Contains(a.OriginalFileName) && a.Status != MediaAssetStatus.Failed)
|
||||
.Select(a => a.OriginalFileName)
|
||||
.ToListAsync(cancellationToken);
|
||||
var takenSet = taken.ToHashSet(StringComparer.Ordinal);
|
||||
|
||||
return new ManualInboxListDto(
|
||||
page.Select(f => new ManualInboxFileDto(
|
||||
f.RelativePath,
|
||||
f.Name,
|
||||
f.SizeBytes,
|
||||
MediaFormats.IsAllowed(f.Name),
|
||||
takenSet.Contains(f.Name)
|
||||
))
|
||||
.ToList(),
|
||||
truncated
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user