Files
Radicade/Server/CDN/DataCDN.cs
T
2026-10-16 23:33:13 -07:00

45 lines
1.2 KiB
C#

using Microsoft.AspNetCore.Mvc;
using SixLabors.ImageSharp;
namespace RadicadeServer.CDN
{
[Route("cdn/data/")]
[Route("data/")]
public class DataCDN : Controller
{
[HttpGet]
public IActionResult Index()
{
try
{
using var entries = Directory.EnumerateFileSystemEntries(DBConfig.CDNStorage).GetEnumerator();
_ = entries.MoveNext();
return Ok(new { service = "data", status = "ok" });
}
catch
{
return StatusCode(StatusCodes.Status503ServiceUnavailable,
new { service = "data", status = "DATA_STORAGE_UNAVAILABLE" });
}
}
[HttpGet("{datablob}")]
public IActionResult GetDataBlob(string datablob)
{
if (!CdnStorageNames.IsServable(datablob)) return BadRequest();
// This is the URL the client's bundle downloader ranges over, so the name has to be
// one that may be served at all and it may arrive with or without the .assetbundle
// suffix the import appends.
var name = CdnStorageNames.Resolve(datablob);
if (name == null) return NotFound();
CdnCaching.Apply(this, CdnCaching.ForBlob(name));
return PhysicalFile(Path.Join(DBConfig.CDNStorage, name), "application/octet-stream", enableRangeProcessing: true);
}
}
}