Skip to content

Commit

Permalink
Added a paginated GetAll implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Aragas committed Oct 17, 2024
1 parent f9bbd6e commit 3471349
Showing 1 changed file with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,25 @@ public async Task<bool> IsOwningGameAsync(SteamUserId steamUserId, uint appId, C

public async Task<List<SteamWorkshopItemInfo>> 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<SteamWorkshopItemInfo>();
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<List<SteamWorkshopItemInfo>> 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<IsOwningWorkshopItemRoot>(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();
}
Expand Down

0 comments on commit 3471349

Please sign in to comment.