Skip to content

Commit 3ff19c8

Browse files
committed
fetch CurseForge Last-Modified header
1 parent 8ab05d0 commit 3ff19c8

3 files changed

Lines changed: 15 additions & 9 deletions

File tree

src/SMAPI.Toolkit/Framework/Clients/CurseForgeExport/CurseForgeExportApiClient.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Threading.Tasks;
23
using Pathoschild.Http.Client;
34
using StardewModdingAPI.Toolkit.Framework.Clients.CurseForgeExport.ResponseModels;
@@ -28,9 +29,12 @@ public CurseForgeExportApiClient(string userAgent, string baseUrl)
2829
/// <inheritdoc />
2930
public async Task<CurseForgeFullExport> FetchExportAsync()
3031
{
31-
return await this.Client
32-
.GetAsync("")
33-
.As<CurseForgeFullExport>();
32+
IResponse response = await this.Client.GetAsync("");
33+
34+
CurseForgeFullExport export = await response.As<CurseForgeFullExport>();
35+
export.LastModified = response.Message.Content.Headers.LastModified ?? throw new InvalidOperationException("Can't fetch from CurseForge export API: expected Last-Modified header wasn't set.");
36+
37+
return export;
3438
}
3539

3640
/// <inheritdoc />

src/SMAPI.Toolkit/Framework/Clients/CurseForgeExport/ResponseModels/CurseForgeFullExport.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Collections.Generic;
23

34
namespace StardewModdingAPI.Toolkit.Framework.Clients.CurseForgeExport.ResponseModels
@@ -7,5 +8,8 @@ public class CurseForgeFullExport
78
{
89
/// <summary>The mod data indexed by public mod ID.</summary>
910
public Dictionary<uint, CurseForgeModExport> Mods { get; set; } = new();
11+
12+
/// <summary>When the data was last updated.</summary>
13+
public DateTimeOffset LastModified { get; set; }
1014
}
1115
}

src/SMAPI.Web/Framework/Caching/CurseForgeExport/CurseForgeExportCacheMemoryRepository.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ internal class CurseForgeExportCacheMemoryRepository : BaseCacheRepository, ICur
1313
/// <summary>The cached mod data from the CurseForge export API.</summary>
1414
private CurseForgeFullExport? Data;
1515

16-
/// <summary>When the data was last updated.</summary>
17-
private DateTimeOffset LastRefreshed;
18-
1916

2017
/*********
2118
** Public methods
@@ -29,7 +26,7 @@ public bool IsLoaded()
2926
/// <inheritdoc />
3027
public DateTimeOffset? GetLastRefreshed()
3128
{
32-
return this.LastRefreshed;
29+
return this.Data?.LastModified;
3330
}
3431

3532
/// <inheritdoc />
@@ -50,13 +47,14 @@ public bool TryGetMod(uint id, [NotNullWhen(true)] out CurseForgeModExport? mod)
5047
public void SetData(CurseForgeFullExport? export)
5148
{
5249
this.Data = export;
53-
this.LastRefreshed = DateTimeOffset.UtcNow;
5450
}
5551

5652
/// <inheritdoc />
5753
public bool IsStale(int staleMinutes)
5854
{
59-
return this.IsStale(this.LastRefreshed, staleMinutes);
55+
return
56+
this.Data is null
57+
|| this.IsStale(this.Data.LastModified, staleMinutes);
6058
}
6159
}
6260
}

0 commit comments

Comments
 (0)