first commit -push

This commit is contained in:
dungtt
2025-10-15 15:15:53 +07:00
parent 674ae395be
commit a9577c5756
885 changed files with 74595 additions and 0 deletions

View File

@@ -0,0 +1,66 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using RobotNet.MapManager.Services;
namespace RobotNet.MapManager.Controllers;
[Route("api/[controller]")]
[ApiController]
[AllowAnonymous]
public class ImagesController(MapEditorStorageRepository StorageRepo, IHttpClientFactory HttpClientFactory, LoggerController<ImagesController> Logger) : ControllerBase
{
[HttpGet]
[Route("map/{id}")]
public async Task<IActionResult> GetMapImage(Guid id)
{
try
{
var (usingLocal, url) = StorageRepo.GetUrl("MapImages", $"{id}");
if (!usingLocal)
{
var http = HttpClientFactory.CreateClient();
var imageBytes = await http.GetByteArrayAsync(url);
if (imageBytes != null && imageBytes.Length > 0) return File(imageBytes, "image/png");
else return NotFound("Không thể lấy được ảnh map.");
}
if (System.IO.File.Exists(url)) return File(System.IO.File.ReadAllBytes(url), "image/png");
else return NotFound();
}
catch(Exception ex)
{
Logger.Warning($"GetMapImage {id}: Hệ thống có lỗi xảy ra - {ex.Message}");
return NotFound();
}
}
[HttpGet]
[Route("elementModel/{id}")]
public async Task<IActionResult> GetElementModelImage(Guid id, [FromQuery] bool IsOpen)
{
try
{
var (usingLocal, url) = StorageRepo.GetUrl(IsOpen ? "ElementOpenModels" : "ElementCloseModels", id.ToString());
if (!usingLocal)
{
var http = HttpClientFactory.CreateClient();
var imageBytes = await http.GetByteArrayAsync(url);
if (imageBytes != null && imageBytes.Length > 0)
{
return File(imageBytes, "image/png");
}
else
{
return NotFound("Không thể lấy được ảnh element model.");
}
}
if (System.IO.File.Exists(url)) return File(System.IO.File.ReadAllBytes(url), "image/png");
else return NotFound();
}
catch (Exception ex)
{
Logger.Warning($"GetElementModelImage {id}: Hệ thống có lỗi xảy ra - {ex.Message}");
return NotFound();
}
}
}