- Introduced `MediaImage` entity to manage images for markdown in instructions and news. - Updated `IAppDbContext` and `AppDbContext` to include `MediaImages` DbSet. - Implemented `DeleteMediaImageFilesAsync` method in `FactoryResetCommandHandler` to remove media images during factory reset. - Added new API endpoints for uploading and retrieving media images, enhancing markdown support. - Updated frontend components to utilize the new `MarkdownEditor` for image uploads in instructions and news. - Enhanced documentation to reflect the new media handling features and API specifications.
30 lines
1.0 KiB
C#
30 lines
1.0 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using LiteCqrs;
|
|
using PnvPanel.Application.Common.Interfaces;
|
|
using PnvPanel.Application.Common.Models;
|
|
|
|
namespace PnvPanel.Application.Media.GetImage;
|
|
|
|
public sealed class GetMediaImageQueryHandler(IAppDbContext dbContext, IFileStorage fileStorage)
|
|
: IQueryHandler<GetMediaImageQuery, Result<MediaImageContent>>
|
|
{
|
|
public async Task<Result<MediaImageContent>> Handle(
|
|
GetMediaImageQuery query,
|
|
CancellationToken cancellationToken
|
|
)
|
|
{
|
|
var image = await dbContext
|
|
.MediaImages.AsNoTracking()
|
|
.FirstOrDefaultAsync(i => i.Id == query.ImageId, cancellationToken);
|
|
|
|
if (image is null)
|
|
return Result.Failure<MediaImageContent>(MediaErrors.NotFound);
|
|
|
|
var stream = await fileStorage.OpenReadAsync(image.StoredFileName, cancellationToken);
|
|
if (stream is null)
|
|
return Result.Failure<MediaImageContent>(MediaErrors.NotFound);
|
|
|
|
return Result.Success(new MediaImageContent(stream, image.ContentType, image.FileName));
|
|
}
|
|
}
|