From 25dd5a047487f5de015d84bed99708d31bb0c117 Mon Sep 17 00:00:00 2001 From: Timothy Baldridge Date: Fri, 20 Oct 2023 23:04:47 +0100 Subject: [PATCH] Soe error handling --- Wabbajack.Server/Controllers/Proxy.cs | 32 ++++++++++++--------------- 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/Wabbajack.Server/Controllers/Proxy.cs b/Wabbajack.Server/Controllers/Proxy.cs index 155cfc97..6f10a637 100644 --- a/Wabbajack.Server/Controllers/Proxy.cs +++ b/Wabbajack.Server/Controllers/Proxy.cs @@ -52,21 +52,8 @@ public class Proxy : ControllerBase public async Task 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] @@ -164,11 +151,20 @@ public class Proxy : ControllerBase private async Task 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;