Skip to content

Commit 3edb9da

Browse files
committed
Fix crashing on missing beatmaps
1 parent 5506dfd commit 3edb9da

File tree

4 files changed

+9
-8
lines changed

4 files changed

+9
-8
lines changed

Difficalcy.Tests/DummyCalculatorServiceTest.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ protected override DummyCalculation CalculatePerformance(DummyScore score, objec
4545
protected override object DeserialiseDifficultyAttributes(string difficultyAttributesJson) =>
4646
double.Parse(difficultyAttributesJson);
4747

48-
protected override Task<bool> EnsureBeatmap(string beatmapId) =>
48+
protected override Task EnsureBeatmap(string beatmapId) =>
4949
Task.FromResult(true);
5050
}
5151

Difficalcy/Services/IBeatmapProvider.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace Difficalcy.Services
55
{
66
public interface IBeatmapProvider
77
{
8-
public Task<bool> EnsureBeatmap(string beatmapId);
8+
public Task EnsureBeatmap(string beatmapId);
99

1010
public Stream GetBeatmapStream(string beatmapId);
1111
}

Difficalcy/Services/TestBeatmapProvider.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Difficalcy.Services
77
{
88
public class TestBeatmapProvider(string resourceAssemblyName) : IBeatmapProvider
99
{
10-
public Task<bool> EnsureBeatmap(string beatmapId)
10+
public Task EnsureBeatmap(string beatmapId)
1111
{
1212
var resourceName = $"{resourceAssemblyName}.Resources.{beatmapId}";
1313
var info = ResourceAssembly.GetManifestResourceInfo(resourceName);

Difficalcy/Services/WebBeatmapProvider.cs

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.IO;
22
using System.Net.Http;
33
using System.Threading.Tasks;
4+
using Microsoft.AspNetCore.Http;
45
using Microsoft.Extensions.Configuration;
56

67
namespace Difficalcy.Services
@@ -10,21 +11,21 @@ public class WebBeatmapProvider(IConfiguration configuration) : IBeatmapProvider
1011
private readonly string _beatmapDirectory = configuration["BEATMAP_DIRECTORY"];
1112
private readonly HttpClient _httpClient = new();
1213

13-
public async Task<bool> EnsureBeatmap(string beatmapId)
14+
public async Task EnsureBeatmap(string beatmapId)
1415
{
1516
var beatmapPath = GetBeatmapPath(beatmapId);
1617
if (!File.Exists(beatmapPath))
1718
{
1819
using var response = await _httpClient.GetAsync($"https://osu.ppy.sh/osu/{beatmapId}");
1920
if (!response.IsSuccessStatusCode)
20-
{
21-
return false;
22-
}
21+
throw new BadHttpRequestException("Beatmap not found");
2322

2423
using var fs = new FileStream(beatmapPath, FileMode.CreateNew);
24+
if (fs.Length == 0)
25+
throw new BadHttpRequestException("Beatmap not found");
26+
2527
await response.Content.CopyToAsync(fs);
2628
}
27-
return true;
2829
}
2930

3031
public Stream GetBeatmapStream(string beatmapId)

0 commit comments

Comments
 (0)