Compare commits

..

3 Commits

Author SHA1 Message Date
319e98443a Debug logging in BuildHeaderAndExecuteRequests 2025-05-20 20:06:13 +02:00
527613b78b Reverted subscription fetching to be done in sequence 2025-05-20 20:06:13 +02:00
82406bf8a4 Updated subscription lookup to match OF website.
It always increments the offset with the limit before making the next request.
2025-05-20 20:06:13 +02:00

View File

@ -326,50 +326,62 @@ public class APIHelper : IAPIHelper
} }
public async Task<Dictionary<string, int>?> GetAllSubscriptions(Dictionary<string, string> getParams, string endpoint, bool includeRestricted, IDownloadConfig config) public async Task<Dictionary<string, int>?> GetAllSubscriptions(Dictionary<string, string> getParams, int limit, string endpoint, bool includeRestricted, IDownloadConfig config)
{ {
try try
{ {
Dictionary<string, int> users = new(); Dictionary<string, int> users = new();
Subscriptions subscriptions = new();
int limit = 25;
int offset = 0; int offset = 0;
getParams["limit"] = limit.ToString();
getParams["offset"] = offset.ToString(); getParams["offset"] = offset.ToString();
Log.Debug("Calling GetAllSubscrptions"); Log.Debug("Calling GetAllSubscrptions");
while (true)
{
string? body = await BuildHeaderAndExecuteRequests(getParams, endpoint, httpClient); string? body = await BuildHeaderAndExecuteRequests(getParams, endpoint, httpClient);
if (string.IsNullOrWhiteSpace(body)) subscriptions = JsonConvert.DeserializeObject<Subscriptions>(body);
break; if (subscriptions != null && subscriptions.hasMore)
Subscriptions? subscriptions = JsonConvert.DeserializeObject<Subscriptions>(body, m_JsonSerializerSettings);
if (subscriptions?.list is null)
break;
foreach (Subscriptions.List item in subscriptions.list)
{ {
if (users.ContainsKey(item.username)) offset += limit;
continue; getParams["offset"] = offset.ToString();
bool isRestricted = item.isRestricted ?? false; while (true)
bool isRestrictedButAllowed = isRestricted && includeRestricted; {
Subscriptions newSubscriptions = new();
string? loopbody = await BuildHeaderAndExecuteRequests(getParams, endpoint, httpClient);
if (!isRestricted || isRestrictedButAllowed) if (!string.IsNullOrEmpty(loopbody) && (!loopbody.Contains("[]") || loopbody.Trim() != "[]"))
users.Add(item.username, item.id); {
newSubscriptions = JsonConvert.DeserializeObject<Subscriptions>(loopbody, m_JsonSerializerSettings);
}
else
{
break;
} }
if (!subscriptions.hasMore) subscriptions.list.AddRange(newSubscriptions.list);
if (!newSubscriptions.hasMore)
{
break; break;
}
offset += limit; offset += limit;
getParams["offset"] = offset.ToString(); getParams["offset"] = offset.ToString();
} }
}
foreach (Subscriptions.List subscription in subscriptions.list)
{
if (users.ContainsKey(subscription.username))
continue;
bool isRestricted = subscription.isRestricted ?? false;
bool isRestrictedButAllowed = isRestricted && includeRestricted;
if (!isRestricted || isRestrictedButAllowed)
users.Add(subscription.username, subscription.id);
}
return users; return users;
} }
@ -389,8 +401,10 @@ public class APIHelper : IAPIHelper
public async Task<Dictionary<string, int>?> GetActiveSubscriptions(string endpoint, bool includeRestricted, IDownloadConfig config) public async Task<Dictionary<string, int>?> GetActiveSubscriptions(string endpoint, bool includeRestricted, IDownloadConfig config)
{ {
int limit = 50;
Dictionary<string, string> getParams = new() Dictionary<string, string> getParams = new()
{ {
{ "limit", $"{limit}" },
{ "type", "active" }, { "type", "active" },
{ "format", "infinite"} { "format", "infinite"}
}; };
@ -398,14 +412,16 @@ public class APIHelper : IAPIHelper
Log.Debug("Calling GetActiveSubscriptions"); Log.Debug("Calling GetActiveSubscriptions");
AnsiConsole.Markup($"[red]Getting Active Subscriptions (Include Restricted: {includeRestricted})\n[/]"); AnsiConsole.Markup($"[red]Getting Active Subscriptions (Include Restricted: {includeRestricted})\n[/]");
return await GetAllSubscriptions(getParams, endpoint, includeRestricted, config); return await GetAllSubscriptions(getParams, limit, endpoint, includeRestricted, config);
} }
public async Task<Dictionary<string, int>?> GetExpiredSubscriptions(string endpoint, bool includeRestricted, IDownloadConfig config) public async Task<Dictionary<string, int>?> GetExpiredSubscriptions(string endpoint, bool includeRestricted, IDownloadConfig config)
{ {
int limit = 50;
Dictionary<string, string> getParams = new() Dictionary<string, string> getParams = new()
{ {
{ "limit", $"{limit}" },
{ "type", "expired" }, { "type", "expired" },
{ "format", "infinite"} { "format", "infinite"}
}; };
@ -413,13 +429,15 @@ public class APIHelper : IAPIHelper
Log.Debug("Calling GetExpiredSubscriptions"); Log.Debug("Calling GetExpiredSubscriptions");
AnsiConsole.Markup($"[red]Getting Expired Subscriptions (Include Restricted: {includeRestricted})\n[/]"); AnsiConsole.Markup($"[red]Getting Expired Subscriptions (Include Restricted: {includeRestricted})\n[/]");
return await GetAllSubscriptions(getParams, endpoint, includeRestricted, config); return await GetAllSubscriptions(getParams, limit, 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)
{ {
int limit = 50;
Dictionary<string, string> getParams = new() Dictionary<string, string> getParams = new()
{ {
{ "limit", $"{limit}" },
{ "type", "expired" }, { "type", "expired" },
{ "format", "infinite"} { "format", "infinite"}
}; };
@ -427,7 +445,7 @@ public class APIHelper : IAPIHelper
Log.Debug("Calling GetBlockedUsers"); Log.Debug("Calling GetBlockedUsers");
AnsiConsole.Markup($"[red]Getting Blocked Users\n[/]"); AnsiConsole.Markup($"[red]Getting Blocked Users\n[/]");
return await GetAllSubscriptions(getParams, endpoint, true, config); return await GetAllSubscriptions(getParams, limit, endpoint, true, config);
} }
public async Task<Dictionary<string, int>> GetLists(string endpoint, IDownloadConfig config) public async Task<Dictionary<string, int>> GetLists(string endpoint, IDownloadConfig config)