mirror of
https://github.com/JogmansonReal/Radicade.git
synced 2026-10-25 15:09:26 -07:00
45 lines
1.2 KiB
C#
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);
|
|
}
|
|
}
|
|
}
|