using LightlessSync.API.Routes; using LightlessSyncStaticFilesServer.Services; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; namespace LightlessSyncStaticFilesServer.Controllers; [Route(LightlessFiles.ServerFiles)] public class ShardServerFilesController : ControllerBase { private readonly CDNDownloadsService _cdnDownloadsService; public ShardServerFilesController(ILogger logger, CDNDownloadsService cdnDownloadsService) : base(logger) { _cdnDownloadsService = cdnDownloadsService; } [HttpGet(LightlessFiles.ServerFiles_DirectDownload + "/{hash}")] [AllowAnonymous] public async Task DownloadFileDirect(string hash, [FromQuery] long expires, [FromQuery] string signature) { var result = await _cdnDownloadsService.GetDownloadAsync(hash, expires, signature).ConfigureAwait(false); return result.Status switch { CDNDownloadsService.ResultStatus.Disabled => NotFound(), CDNDownloadsService.ResultStatus.Unauthorized => Unauthorized(), CDNDownloadsService.ResultStatus.NotFound => NotFound(), CDNDownloadsService.ResultStatus.Success => PhysicalFile(result.File!.FullName, "application/octet-stream"), _ => NotFound() }; } }