Skip to content

Commit

Permalink
Soe error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
halgari committed Oct 20, 2023
1 parent 798b07c commit 25dd5a0
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions Wabbajack.Server/Controllers/Proxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,8 @@ public Proxy(ILogger<Proxy> logger, DownloadDispatcher dispatcher, TemporaryFile
public async Task<IActionResult> ProxyHead(CancellationToken token, [FromQuery] Uri uri, [FromQuery] string? name,
[FromQuery] string? hash)
{
var shouldMatch = hash != null ? Hash.FromHex(hash) : default;
_logger.LogInformation("Got proxy head request for {Uri}", uri);
var state = _dispatcher.Parse(uri);
var cacheName = (await Encoding.UTF8.GetBytes(uri.ToString()).Hash()).ToHex();
var cacheFile = _appSettings.ProxyPath.Combine(cacheName);

if (!cacheFile.FileExists())
return NotFound();

if (shouldMatch != default)
if (await _hashCache.FileHashCachedAsync(cacheFile, token) != shouldMatch)
return NotFound();

return Ok();

return new RedirectResult(_redirectUrl + cacheName);
}

[HttpGet]
Expand Down Expand Up @@ -164,11 +151,20 @@ public async Task<IActionResult> ProxyGet(CancellationToken token, [FromQuery] U

private async Task<CacheStatus?> GetCacheEntry(string name)
{
var info = await _s3.GetObjectMetadataAsync(new GetObjectMetadataRequest()
GetObjectMetadataResponse info;
try
{
BucketName = _bucket,
Key = name
});
info = await _s3.GetObjectMetadataAsync(new GetObjectMetadataRequest()
{
BucketName = _bucket,
Key = name,
});
}
catch (Exception _)
{
return null;
}

if (info.HttpStatusCode == System.Net.HttpStatusCode.NotFound)
return null;

Expand Down

0 comments on commit 25dd5a0

Please sign in to comment.