forked from sim0n00ps/OF-DL
Updated blocked user lookup with progress status
This commit is contained in:
parent
1c39b29d65
commit
65371702dd
@ -414,17 +414,79 @@ public class APIHelper : IAPIHelper
|
||||
return await GetAllSubscriptions(getParams, endpoint, includeRestricted, config);
|
||||
}
|
||||
|
||||
public async Task<Dictionary<string, int>?> GetBlockedUsers(string endpoint, IDownloadConfig config)
|
||||
public async Task<Dictionary<string, int>?> GetBlockedUsers(string endpoint, IDownloadConfig config, StatusContext ctx)
|
||||
{
|
||||
int limit = 50;
|
||||
int offset = 0;
|
||||
bool includeRestricted = true;
|
||||
|
||||
Dictionary<string, string> getParams = new()
|
||||
{
|
||||
{ "type", "expired" },
|
||||
{ "format", "infinite"}
|
||||
["format"] = "infinite",
|
||||
["limit"] = limit.ToString(),
|
||||
["offset"] = offset.ToString()
|
||||
};
|
||||
|
||||
Log.Debug("Calling GetBlockedUsers");
|
||||
try
|
||||
{
|
||||
Dictionary<string, int> 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<Subscriptions>(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<Dictionary<string, int>> GetLists(string endpoint, IDownloadConfig config)
|
||||
|
@ -891,7 +891,14 @@ public class Program
|
||||
{
|
||||
const string OUTPUT_FILE = "blocked-users.json";
|
||||
|
||||
Dictionary<string, int>? blockedUsers = await m_ApiHelper.GetBlockedUsers("/users/blocked", Config);
|
||||
Dictionary<string, int>? 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)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user