From 3471349047e19d9bff788b16b72a325a87b4a230 Mon Sep 17 00:00:00 2001 From: Vitalii Mikhailov Date: Thu, 17 Oct 2024 10:41:05 +0300 Subject: [PATCH] Added a paginated GetAll implementation --- .../Services/HttpClients/ISteamAPIClient.cs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/BUTR.Site.NexusMods.Server/Services/HttpClients/ISteamAPIClient.cs b/src/BUTR.Site.NexusMods.Server/Services/HttpClients/ISteamAPIClient.cs index 830b7f4b..19ad5266 100644 --- a/src/BUTR.Site.NexusMods.Server/Services/HttpClients/ISteamAPIClient.cs +++ b/src/BUTR.Site.NexusMods.Server/Services/HttpClients/ISteamAPIClient.cs @@ -125,12 +125,25 @@ public async Task IsOwningGameAsync(SteamUserId steamUserId, uint appId, C public async Task> GetAllOwnedWorkshopItemAsync(SteamUserId steamUserId, uint appId, CancellationToken ct) { - using var request = new HttpRequestMessage(HttpMethod.Get, $"IPublishedFileService/GetUserFiles/v1/?key={_options.APIKey}&steamid={steamUserId}&appid={appId}&return_short_description=true"); + var list = new List(); + for (var page = 1;; page++) + { + var data = await GetAllOwnedWorkshopItemAsync(steamUserId, appId, page, ct); + if (data.Count == 0) break; + list.AddRange(data); + } + + return list; + } + + private async Task> GetAllOwnedWorkshopItemAsync(SteamUserId steamUserId, uint appId, int page, CancellationToken ct) + { + 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}"); using var response = await _httpClient.SendAsync(request, ct); - if (!response.IsSuccessStatusCode) return null; + if (!response.IsSuccessStatusCode) return []; var data = JsonSerializer.Deserialize(await response.Content.ReadAsStreamAsync(ct)); - if (data is not { Response.WorkshopItems.Count: > 0 }) return null; + if (data is not { Response.WorkshopItems.Count: > 0 }) return []; return data.Response.WorkshopItems.Select(x => new SteamWorkshopItemInfo(x.SteamUserId, x.SteamWorkshopModId, x.Name)).ToList(); }