Add S3 file storage support

This commit is contained in:
Kieran
2022-03-01 16:48:42 +00:00
parent dfeb4d41de
commit c2c6b92ce6
18 changed files with 318 additions and 208 deletions

View File

@@ -15,7 +15,8 @@ public class DownloadController : Controller
private readonly IPaywallStore _paywall;
private readonly ILogger<DownloadController> _logger;
public DownloadController(IFileStore storage, ILogger<DownloadController> logger, IFileInfoManager fileInfo, IPaywallStore paywall)
public DownloadController(IFileStore storage, ILogger<DownloadController> logger, IFileInfoManager fileInfo,
IPaywallStore paywall)
{
_storage = storage;
_logger = logger;
@@ -40,7 +41,7 @@ public class DownloadController : Controller
var voidFile = await SetupDownload(gid);
if (voidFile == default) return;
var egressReq = new EgressRequest(gid, GetRanges(Request, (long)voidFile!.Metadata!.Size));
var egressReq = new EgressRequest(gid, GetRanges(Request, (long) voidFile!.Metadata!.Size));
if (egressReq.Ranges.Count() > 1)
{
_logger.LogWarning("Multi-range request not supported!");
@@ -52,10 +53,10 @@ public class DownloadController : Controller
}
else if (egressReq.Ranges.Count() == 1)
{
Response.StatusCode = (int)HttpStatusCode.PartialContent;
Response.StatusCode = (int) HttpStatusCode.PartialContent;
if (egressReq.Ranges.Sum(a => a.Size) == 0)
{
Response.StatusCode = (int)HttpStatusCode.RequestedRangeNotSatisfiable;
Response.StatusCode = (int) HttpStatusCode.RequestedRangeNotSatisfiable;
return;
}
}
@@ -91,7 +92,7 @@ public class DownloadController : Controller
var orderId = Request.Headers.GetHeader("V-OrderId") ?? Request.Query["orderId"];
if (!await IsOrderPaid(orderId))
{
Response.StatusCode = (int)HttpStatusCode.PaymentRequired;
Response.StatusCode = (int) HttpStatusCode.PaymentRequired;
return default;
}
}
@@ -126,20 +127,10 @@ public class DownloadController : Controller
continue;
}
var ranges = rangeHeader.Replace("bytes=", string.Empty).Split(",");
foreach (var range in ranges)
foreach (var h in RangeRequest.Parse(rangeHeader, totalSize))
{
var rangeValues = range.Split("-");
long? endByte = null, startByte = 0;
if (long.TryParse(rangeValues[1], out var endParsed))
endByte = endParsed;
if (long.TryParse(rangeValues[0], out var startParsed))
startByte = startParsed;
yield return new(totalSize, startByte, endByte);
yield return h;
}
}
}
}
}