Compare commits

..

3 Commits

Author SHA1 Message Date
44bb749c2d Debug logging in BuildHeaderAndExecuteRequests 2025-05-21 18:16:04 +02:00
cb107d11ea Reverted subscription fetching to be done in sequence 2025-05-21 18:16:03 +02:00
ed5f6ad6f7 Updated subscription lookup to match OF website.
It always increments the offset with the limit before making the next request.
2025-05-21 18:16:03 +02:00

View File

@ -326,61 +326,49 @@ public class APIHelper : IAPIHelper
} }
public async Task<Dictionary<string, int>?> GetAllSubscriptions(Dictionary<string, string> getParams, int limit, string endpoint, bool includeRestricted, IDownloadConfig config) public async Task<Dictionary<string, int>?> GetAllSubscriptions(Dictionary<string, string> getParams, 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");
string? body = await BuildHeaderAndExecuteRequests(getParams, endpoint, httpClient);
subscriptions = JsonConvert.DeserializeObject<Subscriptions>(body);
if (subscriptions != null && subscriptions.hasMore)
{
offset += limit;
getParams["offset"] = offset.ToString();
while (true) while (true)
{ {
Subscriptions newSubscriptions = new(); string? body = await BuildHeaderAndExecuteRequests(getParams, endpoint, httpClient);
string? loopbody = await BuildHeaderAndExecuteRequests(getParams, endpoint, httpClient);
if (!string.IsNullOrEmpty(loopbody) && (!loopbody.Contains("[]") || loopbody.Trim() != "[]")) if (string.IsNullOrWhiteSpace(body))
{
newSubscriptions = JsonConvert.DeserializeObject<Subscriptions>(loopbody, m_JsonSerializerSettings);
}
else
{
break; break;
}
subscriptions.list.AddRange(newSubscriptions.list); Subscriptions? subscriptions = JsonConvert.DeserializeObject<Subscriptions>(body, m_JsonSerializerSettings);
if (!newSubscriptions.hasMore)
{ if (subscriptions?.list is null)
break; break;
}
offset += limit; foreach (Subscriptions.List item in subscriptions.list)
getParams["offset"] = offset.ToString();
}
}
foreach (Subscriptions.List subscription in subscriptions.list)
{ {
if (users.ContainsKey(subscription.username)) if (users.ContainsKey(item.username))
continue; continue;
bool isRestricted = subscription.isRestricted ?? false; bool isRestricted = item.isRestricted ?? false;
bool isRestrictedButAllowed = isRestricted && includeRestricted; bool isRestrictedButAllowed = isRestricted && includeRestricted;
if (!isRestricted || isRestrictedButAllowed) if (!isRestricted || isRestrictedButAllowed)
users.Add(subscription.username, subscription.id); users.Add(item.username, item.id);
}
if (!subscriptions.hasMore)
break;
offset += limit;
getParams["offset"] = offset.ToString();
} }
return users; return users;
@ -401,10 +389,8 @@ 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"}
}; };
@ -412,16 +398,14 @@ 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, limit, endpoint, includeRestricted, config); return await GetAllSubscriptions(getParams, 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"}
}; };
@ -429,15 +413,13 @@ 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, limit, endpoint, includeRestricted, config); 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)
{ {
int limit = 50;
Dictionary<string, string> getParams = new() Dictionary<string, string> getParams = new()
{ {
{ "limit", $"{limit}" },
{ "type", "expired" }, { "type", "expired" },
{ "format", "infinite"} { "format", "infinite"}
}; };
@ -445,7 +427,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, limit, endpoint, true, config); return await GetAllSubscriptions(getParams, 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)