adds the ability for shards to sync with the main server regarding their caches, when pulling files from main server the shard can stream it to the client directly while downloading and add info for server to report to client regarding file locations across shards
This commit is contained in:
@@ -20,15 +20,30 @@ public class ShardServerFilesController : ControllerBase
|
||||
[AllowAnonymous]
|
||||
public async Task<IActionResult> DownloadFileDirect(string hash, [FromQuery] long expires, [FromQuery] string signature)
|
||||
{
|
||||
var result = await _cdnDownloadsService.GetDownloadAsync(hash, expires, signature).ConfigureAwait(false);
|
||||
var result = await _cdnDownloadsService.GetDownloadAsync(hash, expires, signature, HttpContext.RequestAborted).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"),
|
||||
CDNDownloadsService.ResultStatus.Success => BuildDirectDownloadResult(result),
|
||||
_ => NotFound()
|
||||
};
|
||||
}
|
||||
|
||||
private IActionResult BuildDirectDownloadResult(CDNDownloadsService.Result result)
|
||||
{
|
||||
if (result.Stream != null)
|
||||
{
|
||||
if (result.ContentLength.HasValue)
|
||||
{
|
||||
Response.ContentLength = result.ContentLength.Value;
|
||||
}
|
||||
|
||||
return new FileStreamResult(result.Stream, "application/octet-stream");
|
||||
}
|
||||
|
||||
return PhysicalFile(result.File!.FullName, "application/octet-stream");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user