27 lines
954 B
C#
27 lines
954 B
C#
using Manager.App.Services.System;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace Manager.App.Controllers;
|
|
|
|
[ApiController]
|
|
[Route("api/v1/[controller]")]
|
|
public class CacheController(ILogger<CacheController> logger, CacheService cacheService) : ControllerBase
|
|
{
|
|
[HttpGet]
|
|
public async Task<IActionResult> Cache([FromQuery(Name = "url")] string url, CancellationToken cancellationToken)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(url))
|
|
{
|
|
return BadRequest("No url given.");
|
|
}
|
|
|
|
var cacheResult = await cacheService.CacheFromUrl(url, cancellationToken);
|
|
if (!cacheResult.IsSuccess)
|
|
{
|
|
logger.LogError("Cache request failed. {ErrorMessage}", cacheResult.Error?.Description);
|
|
return StatusCode(500, cacheResult.Error?.Description);
|
|
}
|
|
|
|
return File(cacheResult.Value.Data, cacheResult.Value.ContentType ?? string.Empty, cacheResult.Value.OriginalFileName);
|
|
}
|
|
} |