mirror of
https://github.com/RedWizardsLab/EchoHub.git
synced 2026-09-04 08:36:11 +02:00
feat: enhance file upload and URL sending with optional size parameter
This commit is contained in:
@@ -154,7 +154,7 @@ public class ChannelsController : ControllerBase
|
||||
|
||||
[HttpPost("{channel}/upload")]
|
||||
[EnableRateLimiting("upload")]
|
||||
public async Task<IActionResult> Upload(string channel)
|
||||
public async Task<IActionResult> Upload(string channel, [FromQuery] string? size = null)
|
||||
{
|
||||
var userIdClaim = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
var usernameClaim = User.FindFirstValue("username");
|
||||
@@ -190,8 +190,9 @@ public class ChannelsController : ControllerBase
|
||||
|
||||
if (isImage)
|
||||
{
|
||||
var (w, h) = ImageToAsciiService.GetDimensions(size);
|
||||
using var imageStream = System.IO.File.OpenRead(filePath);
|
||||
content = _asciiService.ConvertToAscii(imageStream);
|
||||
content = _asciiService.ConvertToAscii(imageStream, w, h);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -235,7 +236,7 @@ public class ChannelsController : ControllerBase
|
||||
|
||||
[HttpPost("{channel}/send-url")]
|
||||
[EnableRateLimiting("upload")]
|
||||
public async Task<IActionResult> SendUrl(string channel, [FromBody] SendUrlRequest request)
|
||||
public async Task<IActionResult> SendUrl(string channel, [FromBody] SendUrlRequest request, [FromQuery] string? size = null)
|
||||
{
|
||||
var userIdClaim = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
var usernameClaim = User.FindFirstValue("username");
|
||||
@@ -310,9 +311,10 @@ public class ChannelsController : ControllerBase
|
||||
var (fileId, filePath) = await _fileStorage.SaveFileAsync(memoryStream, fileName);
|
||||
|
||||
string content;
|
||||
var (w, h) = ImageToAsciiService.GetDimensions(size);
|
||||
using (var imageStream = System.IO.File.OpenRead(filePath))
|
||||
{
|
||||
content = _asciiService.ConvertToAscii(imageStream);
|
||||
content = _asciiService.ConvertToAscii(imageStream, w, h);
|
||||
}
|
||||
|
||||
var attachmentUrl = $"/api/files/{fileId}";
|
||||
|
||||
@@ -8,6 +8,17 @@ namespace EchoHub.Server.Services;
|
||||
|
||||
public class ImageToAsciiService
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns (width, height) dimensions for the given size code.
|
||||
/// s = small (40x40), m = medium/default (80x80), l = large (120x120).
|
||||
/// </summary>
|
||||
public static (int Width, int Height) GetDimensions(string? size) => size?.ToLowerInvariant() switch
|
||||
{
|
||||
"s" => (40, 40),
|
||||
"l" => (120, 120),
|
||||
_ => (HubConstants.AsciiArtWidth, HubConstants.AsciiArtHeightHalfBlock),
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Converts an image to ASCII art using half-block characters (▀▄█) with
|
||||
/// 24-bit ANSI foreground and background colors for 2x vertical resolution.
|
||||
|
||||
Reference in New Issue
Block a user