From 65371702dd1c207eca0d457f12fe6e1130ab17dd Mon Sep 17 00:00:00 2001 From: Casper Sparre Date: Tue, 2 Sep 2025 21:17:59 +0200 Subject: [PATCH] Updated blocked user lookup with progress status --- OF DL/Helpers/APIHelper.cs | 72 +++++++++++++++++++++++++++++++++++--- OF DL/Program.cs | 9 ++++- 2 files changed, 75 insertions(+), 6 deletions(-) diff --git a/OF DL/Helpers/APIHelper.cs b/OF DL/Helpers/APIHelper.cs index 80e67bd..d9fea2a 100644 --- a/OF DL/Helpers/APIHelper.cs +++ b/OF DL/Helpers/APIHelper.cs @@ -414,17 +414,79 @@ public class APIHelper : IAPIHelper return await GetAllSubscriptions(getParams, endpoint, includeRestricted, config); } - public async Task?> GetBlockedUsers(string endpoint, IDownloadConfig config) + public async Task?> GetBlockedUsers(string endpoint, IDownloadConfig config, StatusContext ctx) { + int limit = 50; + int offset = 0; + bool includeRestricted = true; + Dictionary getParams = new() { - { "type", "expired" }, - { "format", "infinite"} + ["format"] = "infinite", + ["limit"] = limit.ToString(), + ["offset"] = offset.ToString() }; - Log.Debug("Calling GetBlockedUsers"); + try + { + Dictionary users = []; - return await GetAllSubscriptions(getParams, endpoint, true, config); + Log.Debug("Calling GetBlockedUsers"); + + bool isLastLoop = false; + while (true) + { + string? body = await BuildHeaderAndExecuteRequests(getParams, endpoint, httpClient); + + if (string.IsNullOrWhiteSpace(body)) + break; + + Subscriptions? subscriptions = JsonConvert.DeserializeObject(body, m_JsonSerializerSettings); + + ctx.Status($"[red]Getting Blocked Users\n[/] [red]Found {users.Count}[/]"); + ctx.Spinner(Spinner.Known.Dots); + ctx.SpinnerStyle(Style.Parse("blue")); + + if (subscriptions?.list is null) + break; + + foreach (Subscriptions.List item in subscriptions.list) + { + if (users.ContainsKey(item.username)) + continue; + + bool isRestricted = item.isRestricted ?? false; + bool isRestrictedButAllowed = isRestricted && includeRestricted; + + if (!isRestricted || isRestrictedButAllowed) + users.Add(item.username, item.id); + } + + if (isLastLoop) + break; + + if (!subscriptions.hasMore || subscriptions.list.Count == 0) + isLastLoop = true; + + offset += subscriptions.list.Count; + getParams["offset"] = offset.ToString(); + } + + return users; + } + catch (Exception ex) + { + Console.WriteLine("Exception caught: {0}\n\nStackTrace: {1}", ex.Message, ex.StackTrace); + Log.Error("Exception caught: {0}\n\nStackTrace: {1}", ex.Message, ex.StackTrace); + if (ex.InnerException != null) + { + Console.WriteLine("\nInner Exception:"); + Console.WriteLine("Exception caught: {0}\n\nStackTrace: {1}", ex.InnerException.Message, ex.InnerException.StackTrace); + Log.Error("Inner Exception: {0}\n\nStackTrace: {1}", ex.InnerException.Message, ex.InnerException.StackTrace); + } + } + + return null; } public async Task> GetLists(string endpoint, IDownloadConfig config) diff --git a/OF DL/Program.cs b/OF DL/Program.cs index c88fedc..50bce1c 100644 --- a/OF DL/Program.cs +++ b/OF DL/Program.cs @@ -891,7 +891,14 @@ public class Program { const string OUTPUT_FILE = "blocked-users.json"; - Dictionary? blockedUsers = await m_ApiHelper.GetBlockedUsers("/users/blocked", Config); + Dictionary? blockedUsers = null; + + await AnsiConsole + .Status() + .StartAsync("[red]Getting Blocked Users[/]", async ctx => + { + blockedUsers = await m_ApiHelper.GetBlockedUsers("/users/blocked", Config, ctx); + }); if (blockedUsers is null || blockedUsers.Count == 0) {