Skip to content

Commit 326128c

Browse files
authored
Merge pull request #42 from helldivers-2/fix/41
Make raw endpoints future-proof by providing raw binary payloads instead of serialized. Update interval set to 20 seconds from 5 minutes. Guard against nullability with `_syncState`
2 parents b4d3cc1 + 85c6720 commit 326128c

File tree

17 files changed

+225
-312
lines changed

17 files changed

+225
-312
lines changed
Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using Helldivers.Core.Contracts;
2-
using Helldivers.Core.Contracts.Collections;
1+
using Helldivers.Core.Storage.ArrowHead;
32
using Helldivers.Models.ArrowHead;
43
using Microsoft.AspNetCore.Mvc;
54

@@ -14,66 +13,66 @@ public static class ArrowHeadController
1413
/// Returns the currently active war season ID.
1514
/// </summary>
1615
[ProducesResponseType<WarId>(StatusCodes.Status200OK)]
17-
public static async Task<IResult> WarId(HttpContext context, IStore<WarId> store)
16+
public static async Task<IResult> WarId(HttpContext context, ArrowHeadStore store)
1817
{
19-
var result = await store.Get(context.RequestAborted);
18+
var warId = await store.GetWarId(context.RequestAborted);
2019

21-
return Results.Ok(result);
20+
return Results.Bytes(warId, contentType: "application/json");
2221
}
2322

2423
/// <summary>
2524
/// Get a snapshot of the current war status.
2625
/// </summary>
2726
[ProducesResponseType<WarStatus>(StatusCodes.Status200OK)]
28-
public static async Task<IResult> Status(HttpContext context, IStore<WarStatus> store)
27+
public static async Task<IResult> Status(HttpContext context, ArrowHeadStore store)
2928
{
30-
var status = await store.Get(context.RequestAborted);
29+
var status = await store.GetWarStatus(context.RequestAborted);
3130

32-
return Results.Ok(status);
31+
return Results.Bytes(status, contentType: "application/json");
3332
}
3433

3534
/// <summary>
3635
/// Gets the current war info.
3736
/// </summary>
3837
[ProducesResponseType<WarInfo>(StatusCodes.Status200OK)]
39-
public static async Task<IResult> WarInfo(HttpContext context, IStore<WarInfo> store)
38+
public static async Task<IResult> WarInfo(HttpContext context, ArrowHeadStore store)
4039
{
41-
var info = await store.Get(context.RequestAborted);
40+
var info = await store.GetWarInfo(context.RequestAborted);
4241

43-
return Results.Ok(info);
42+
return Results.Bytes(info, contentType: "application/json");
4443
}
4544

4645
/// <summary>
4746
/// Gets the current war info.
4847
/// </summary>
4948
[ProducesResponseType<WarSummary>(StatusCodes.Status200OK)]
50-
public static async Task<IResult> Summary(HttpContext context, IStore<WarSummary> store)
49+
public static async Task<IResult> Summary(HttpContext context, ArrowHeadStore store)
5150
{
52-
var summary = await store.Get(context.RequestAborted);
51+
var summary = await store.GetWarSummary(context.RequestAborted);
5352

54-
return Results.Ok(summary);
53+
return Results.Bytes(summary, contentType: "application/json");
5554
}
5655

5756
/// <summary>
5857
/// Retrieves a list of news messages from Super Earth.
5958
/// </summary>
6059
[ProducesResponseType<List<NewsFeedItem>>(StatusCodes.Status200OK)]
61-
public static async Task<IResult> NewsFeed(HttpContext context, IStore<NewsFeedItem, int> store)
60+
public static async Task<IResult> NewsFeed(HttpContext context, ArrowHeadStore store)
6261
{
63-
var items = await store.AllAsync(context.RequestAborted);
62+
var items = await store.GetNewsFeeds(context.RequestAborted);
6463

65-
return Results.Ok(items);
64+
return Results.Bytes(items, contentType: "application/json");
6665
}
6766

6867
/// <summary>
6968
/// Retrieves a list of currently active assignments (like Major Orders).
7069
/// </summary>
7170
[ProducesResponseType<List<Assignment>>(StatusCodes.Status200OK)]
7271
[ProducesResponseType(StatusCodes.Status503ServiceUnavailable)]
73-
public static async Task<IResult> Assignments(HttpContext context, IStore<Assignment, int> store)
72+
public static async Task<IResult> Assignments(HttpContext context, ArrowHeadStore store)
7473
{
75-
var assignments = await store.AllAsync(context.RequestAborted);
74+
var assignments = await store.GetAssignments(context.RequestAborted);
7675

77-
return Results.Ok(assignments);
76+
return Results.Bytes(assignments, contentType: "application/json");
7877
}
7978
}

src/Helldivers-2-API/appsettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"AllowedHosts": "*",
1111
"Helldivers": {
1212
"Synchronization": {
13-
"IntervalSeconds": 300,
13+
"IntervalSeconds": 20,
1414
"DefaultLanguage": "en-US",
1515
"Languages": [
1616
"en-US",

src/Helldivers-2-API/wwwroot/Helldivers-2-API.json

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
},
1616
{
1717
"url": "/",
18-
"description": "The dotnet helldivers server"
18+
"description": "The development server"
1919
}
2020
],
2121
"get": {
@@ -46,7 +46,7 @@
4646
},
4747
{
4848
"url": "/",
49-
"description": "The dotnet helldivers server"
49+
"description": "The development server"
5050
}
5151
],
5252
"get": {
@@ -77,7 +77,7 @@
7777
},
7878
{
7979
"url": "/",
80-
"description": "The dotnet helldivers server"
80+
"description": "The development server"
8181
}
8282
],
8383
"get": {
@@ -108,7 +108,7 @@
108108
},
109109
{
110110
"url": "/",
111-
"description": "The dotnet helldivers server"
111+
"description": "The development server"
112112
}
113113
],
114114
"get": {
@@ -139,7 +139,7 @@
139139
},
140140
{
141141
"url": "/",
142-
"description": "The dotnet helldivers server"
142+
"description": "The development server"
143143
}
144144
],
145145
"get": {
@@ -173,7 +173,7 @@
173173
},
174174
{
175175
"url": "/",
176-
"description": "The dotnet helldivers server"
176+
"description": "The development server"
177177
}
178178
],
179179
"get": {
@@ -210,7 +210,7 @@
210210
},
211211
{
212212
"url": "/",
213-
"description": "The dotnet helldivers server"
213+
"description": "The development server"
214214
}
215215
],
216216
"get": {
@@ -241,7 +241,7 @@
241241
},
242242
{
243243
"url": "/",
244-
"description": "The dotnet helldivers server"
244+
"description": "The development server"
245245
}
246246
],
247247
"get": {
@@ -275,7 +275,7 @@
275275
},
276276
{
277277
"url": "/",
278-
"description": "The dotnet helldivers server"
278+
"description": "The development server"
279279
}
280280
],
281281
"get": {
@@ -318,7 +318,7 @@
318318
},
319319
{
320320
"url": "/",
321-
"description": "The dotnet helldivers server"
321+
"description": "The development server"
322322
}
323323
],
324324
"get": {
@@ -352,7 +352,7 @@
352352
},
353353
{
354354
"url": "/",
355-
"description": "The dotnet helldivers server"
355+
"description": "The development server"
356356
}
357357
],
358358
"get": {
@@ -395,7 +395,7 @@
395395
},
396396
{
397397
"url": "/",
398-
"description": "The dotnet helldivers server"
398+
"description": "The development server"
399399
}
400400
],
401401
"get": {
@@ -429,7 +429,7 @@
429429
},
430430
{
431431
"url": "/",
432-
"description": "The dotnet helldivers server"
432+
"description": "The development server"
433433
}
434434
],
435435
"get": {
@@ -472,7 +472,7 @@
472472
},
473473
{
474474
"url": "/",
475-
"description": "The dotnet helldivers server"
475+
"description": "The development server"
476476
}
477477
],
478478
"get": {
@@ -506,7 +506,7 @@
506506
},
507507
{
508508
"url": "/",
509-
"description": "The dotnet helldivers server"
509+
"description": "The development server"
510510
}
511511
],
512512
"get": {
@@ -549,7 +549,7 @@
549549
},
550550
{
551551
"url": "/",
552-
"description": "The dotnet helldivers server"
552+
"description": "The development server"
553553
}
554554
],
555555
"get": {
@@ -583,7 +583,7 @@
583583
},
584584
{
585585
"url": "/",
586-
"description": "The dotnet helldivers server"
586+
"description": "The development server"
587587
}
588588
],
589589
"get": {
@@ -618,7 +618,7 @@
618618
},
619619
{
620620
"url": "/",
621-
"description": "The dotnet helldivers server"
621+
"description": "The development server"
622622
}
623623
],
624624
"get": {
@@ -1801,4 +1801,4 @@
18011801
}
18021802
}
18031803
}
1804-
}
1804+
}

src/Helldivers-2-API/wwwroot/Helldivers-2-API_arrowhead.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,4 +869,4 @@
869869
}
870870
}
871871
}
872-
}
872+
}

src/Helldivers-2-Core/Extensions/ServiceCollectionExtensions.cs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using Helldivers.Core.Storage.ArrowHead;
77
using Helldivers.Core.Storage.Steam;
88
using Helldivers.Core.Storage.V1;
9-
using Helldivers.Models.ArrowHead;
109
using Helldivers.Models.V1;
1110
using Microsoft.Extensions.DependencyInjection;
1211

@@ -35,20 +34,8 @@ public static IServiceCollection AddHelldivers(this IServiceCollection services)
3534
/// </summary>
3635
public static IServiceCollection AddArrowHeadStores(this IServiceCollection services)
3736
{
38-
// Register facade for all stores below
39-
services.AddSingleton<ArrowHeadFacade>();
40-
4137
// Register all stores
42-
services.AddSingleton<IStore<WarInfo>, WarInfoStore>();
43-
services.AddSingleton<WarStatusStore>();
44-
services.AddSingleton<IStore<WarStatus>>(provider => provider.GetRequiredService<WarStatusStore>());
45-
services.AddSingleton<IStore<WarSummary>, WarSummaryStore>();
46-
services.AddSingleton<Storage.ArrowHead.AssignmentStore>();
47-
services.AddSingleton<IStore<Models.ArrowHead.Assignment, int>>(provider =>
48-
provider.GetRequiredService<Storage.ArrowHead.AssignmentStore>());
49-
services.AddSingleton<NewsFeedStore>();
50-
services.AddSingleton<IStore<NewsFeedItem, int>>(provider => provider.GetRequiredService<NewsFeedStore>());
51-
services.AddSingleton<IStore<WarId>, WarIdStore>();
38+
services.AddSingleton<ArrowHeadStore>();
5239

5340
return services;
5441
}

src/Helldivers-2-Core/Facades/ArrowHeadFacade.cs

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/Helldivers-2-Core/Localization/CultureDictionary.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace Helldivers.Core.Localization;
66
/// Specialized version of <see cref="Dictionary{TKey,TValue}" /> that intelligently maps <see cref="CultureInfo" /> as
77
/// keys (eg, if "en-UK" does not exist but "en-US" it'll match).
88
/// </summary>
9-
public class CultureDictionary<T> where T : class
9+
public class CultureDictionary<T>
1010
{
1111
private readonly Dictionary<CultureInfo, T> _items;
1212

0 commit comments

Comments
 (0)