using Microsoft.AspNetCore.Mvc; using SixLabors.ImageSharp; namespace RadicadeServer.CDN { [Route("cdn/room/")] [Route("room/")] [Route("unity/")] [Route("unity_assets/")] [Route("roomserver/unity_assets/")] public class RoomsCDN : Controller { [HttpGet] public IActionResult Index() => Ok(new { status = "ok" }); [HttpGet("{datablob}")] public IActionResult GetDataBlob(string datablob) { if (!CdnStorageNames.IsServable(datablob)) return BadRequest(); 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); } [HttpGet("{assetId}/{target}/{version}")] [HttpGet("{assetId}/{target}")] public IActionResult GetUnityAssetRaw(string assetId, int? target, int? version) { // The bytes half of the two-step download, for a client that asks by id rather than by // the Filename the metadata route handed it: /unity/{id} is the id with no extension, // while an imported bundle is stored as .assetbundle, so both spellings resolve. if (!CdnStorageNames.IsServable(assetId)) return BadRequest(); var name = CdnStorageNames.Resolve(assetId); if (name == null) return NotFound(); CdnCaching.Apply(this, CdnCaching.Immutable); return PhysicalFile(Path.Join(DBConfig.CDNStorage, name), "application/octet-stream", enableRangeProcessing: true); } } }