cdn download support on shards + clean up
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
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<ShardServerFilesController> logger,
|
||||
CDNDownloadsService cdnDownloadsService) : base(logger)
|
||||
{
|
||||
_cdnDownloadsService = cdnDownloadsService;
|
||||
}
|
||||
|
||||
[HttpGet(LightlessFiles.ServerFiles_DirectDownload + "/{hash}")]
|
||||
[AllowAnonymous]
|
||||
public async Task<IActionResult> 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()
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user