mirror of
https://github.com/Stone-Red-Code/EchoHub.git
synced 2026-09-04 00:56:05 +02:00
- Updated IrcBroadcaster to use constructor injection for IrcGatewayService. - Refactored JwtTokenService to initialize configuration values in the constructor. - Modified AuthController to use constructor injection for EchoHubDbContext and JwtTokenService. - Refactored ChannelsController to utilize constructor injection for dependencies. - Updated FilesController to use constructor injection for FileStorageService. - Refactored ServerController to initialize EchoHubDbContext and IConfiguration via constructor. - Modified UsersController to use constructor injection for EchoHubDbContext and ImageToAsciiService. - Updated EchoHubDbContext to use constructor for DbContextOptions. - Refactored ChatHub to use constructor injection for IChatService and ILogger. - Modified ChatService to utilize constructor injection for dependencies. - Refactored ServerDirectoryService to use constructor injection for IConfiguration, PresenceTracker, and ILogger.
47 lines
1.3 KiB
C#
47 lines
1.3 KiB
C#
using EchoHub.Core.DTOs;
|
|
using EchoHub.Server.Services;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.RateLimiting;
|
|
|
|
namespace EchoHub.Server.Controllers;
|
|
|
|
[ApiController]
|
|
[Route("api/files")]
|
|
[Authorize]
|
|
[EnableRateLimiting("general")]
|
|
public class FilesController : ControllerBase
|
|
{
|
|
private readonly FileStorageService _fileStorage;
|
|
|
|
public FilesController(FileStorageService fileStorage)
|
|
{
|
|
_fileStorage = fileStorage;
|
|
}
|
|
[HttpGet("{fileId}")]
|
|
public IActionResult GetFile(string fileId)
|
|
{
|
|
if (!Guid.TryParse(fileId, out _))
|
|
return BadRequest(new ErrorResponse("Invalid file identifier."));
|
|
|
|
var filePath = _fileStorage.GetFilePath(fileId);
|
|
|
|
if (filePath is null)
|
|
return NotFound(new ErrorResponse("File not found."));
|
|
|
|
var contentType = Path.GetExtension(filePath).ToLowerInvariant() switch
|
|
{
|
|
".jpg" or ".jpeg" => "image/jpeg",
|
|
".png" => "image/png",
|
|
".gif" => "image/gif",
|
|
".webp" => "image/webp",
|
|
".pdf" => "application/pdf",
|
|
".txt" => "text/plain",
|
|
_ => "application/octet-stream"
|
|
};
|
|
|
|
var fileName = Path.GetFileName(filePath);
|
|
return PhysicalFile(filePath, contentType, fileName);
|
|
}
|
|
}
|