Skip to content

Commit 3471349

Browse files
committed
Added a paginated GetAll implementation
1 parent f9bbd6e commit 3471349

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/BUTR.Site.NexusMods.Server/Services/HttpClients/ISteamAPIClient.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,25 @@ public async Task<bool> IsOwningGameAsync(SteamUserId steamUserId, uint appId, C
125125

126126
public async Task<List<SteamWorkshopItemInfo>> GetAllOwnedWorkshopItemAsync(SteamUserId steamUserId, uint appId, CancellationToken ct)
127127
{
128-
using var request = new HttpRequestMessage(HttpMethod.Get, $"IPublishedFileService/GetUserFiles/v1/?key={_options.APIKey}&steamid={steamUserId}&appid={appId}&return_short_description=true");
128+
var list = new List<SteamWorkshopItemInfo>();
129+
for (var page = 1;; page++)
130+
{
131+
var data = await GetAllOwnedWorkshopItemAsync(steamUserId, appId, page, ct);
132+
if (data.Count == 0) break;
133+
list.AddRange(data);
134+
}
135+
136+
return list;
137+
}
138+
139+
private async Task<List<SteamWorkshopItemInfo>> GetAllOwnedWorkshopItemAsync(SteamUserId steamUserId, uint appId, int page, CancellationToken ct)
140+
{
141+
using var request = new HttpRequestMessage(HttpMethod.Get, $"IPublishedFileService/GetUserFiles/v1/?key={_options.APIKey}&steamid={steamUserId}&appid={appId}&return_short_description=true&numperpage=100&page={page}");
129142
using var response = await _httpClient.SendAsync(request, ct);
130-
if (!response.IsSuccessStatusCode) return null;
143+
if (!response.IsSuccessStatusCode) return [];
131144

132145
var data = JsonSerializer.Deserialize<IsOwningWorkshopItemRoot>(await response.Content.ReadAsStreamAsync(ct));
133-
if (data is not { Response.WorkshopItems.Count: > 0 }) return null;
146+
if (data is not { Response.WorkshopItems.Count: > 0 }) return [];
134147

135148
return data.Response.WorkshopItems.Select(x => new SteamWorkshopItemInfo(x.SteamUserId, x.SteamWorkshopModId, x.Name)).ToList();
136149
}

0 commit comments

Comments
 (0)