mirror of
https://github.com/Govor-team/Govor.git
synced 2026-07-21 11:44:56 +00:00
66819a015a
This commit introduces the MediaFile entity and updates the media attachments model, repositories, and related logic to reference MediaFile instead of storing file metadata directly in MediaAttachments. Controller, service, and SignalR request/response contracts are updated to support the new structure. Database configurations and validators are also adjusted accordingly. This refactor improves media management and normalization in the data model.
41 lines
1.2 KiB
C#
41 lines
1.2 KiB
C#
using Govor.Application.Interfaces;
|
|
using Govor.Application.Interfaces.Medias;
|
|
using Govor.Contracts.Requests;
|
|
using Govor.Core.Models;
|
|
using Govor.Core.Repositories.MediasAttachments;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace Govor.API.Controllers;
|
|
|
|
[ApiController]
|
|
[Route("api/media")]
|
|
[Authorize(Roles = "User,Admin")]
|
|
public class MediaController : Controller
|
|
{
|
|
private readonly ILogger<MediaController> _logger;
|
|
private readonly IMediaService _mediaService;
|
|
|
|
public MediaController(ILogger<MediaController> logger, IMediaService mediaService)
|
|
{
|
|
_logger = logger;
|
|
_mediaService = mediaService;
|
|
}
|
|
|
|
[HttpPost("upload")]
|
|
[RequestSizeLimit(100_000_000)]// ~100MB
|
|
public async Task<IActionResult> Upload([FromForm] MediaUploadRequest request)
|
|
{
|
|
try
|
|
{
|
|
var result = await _mediaService.UploadMediaAsync(new Media(request.Data, request.FileName, request.Type,
|
|
request.MimeType, request.EncryptedKey));
|
|
|
|
return Ok(result);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return StatusCode(500, ex);
|
|
}
|
|
}
|
|
} |