ProjectLighthouse/ProjectLighthouse.Servers.Website/Controllers/ResourcesController.cs
Josh f1c5ad4002
Major refactor and reorganization of types ()
* Start of reorganization and cleanup

* Remove duplicate title id

* Refactor types

* Fix Release building

* Move classes in /Types to a Types namespace

* Fix compilation error (RoomVisualizerPage strikes again)

* Fix bugs created from auto merge

* Fix auto-merge compilation error

* Changes from review/fix failed merge
2023-02-13 22:02:58 -06:00

29 lines
No EOL
957 B
C#

using LBPUnion.ProjectLighthouse.Files;
using LBPUnion.ProjectLighthouse.Types.Resources;
using Microsoft.AspNetCore.Mvc;
using IOFile = System.IO.File;
namespace LBPUnion.ProjectLighthouse.Servers.Website.Controllers;
[ApiController]
public class ResourcesController : ControllerBase
{
[ResponseCache(Duration = 86400)]
[HttpGet("/gameAssets/{hash}")]
public IActionResult GetGameImage(string hash)
{
string path = FileHelper.GetImagePath($"{hash}.png");
string fullPath = Path.GetFullPath(path);
// Prevent directory traversal attacks
if (!fullPath.StartsWith(FileHelper.FullImagePath)) return this.BadRequest();
if (IOFile.Exists(path)) return this.File(IOFile.OpenRead(path), "image/png");
LbpFile? file = LbpFile.FromHash(hash);
if (file != null && FileHelper.LbpFileToPNG(file)) return this.File(IOFile.OpenRead(path), "image/png");
return this.NotFound();
}
}