forked from sim0n00ps/OF-DL
Compare commits
3 Commits
44bb749c2d
...
319e98443a
Author | SHA1 | Date | |
---|---|---|---|
319e98443a | |||
527613b78b | |||
82406bf8a4 |
@ -326,49 +326,61 @@ 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
|
||||
{
|
||||
Dictionary<string, int> users = new();
|
||||
Subscriptions subscriptions = new();
|
||||
|
||||
int limit = 25;
|
||||
int offset = 0;
|
||||
|
||||
getParams["limit"] = limit.ToString();
|
||||
getParams["offset"] = offset.ToString();
|
||||
|
||||
Log.Debug("Calling GetAllSubscrptions");
|
||||
|
||||
while (true)
|
||||
string? body = await BuildHeaderAndExecuteRequests(getParams, endpoint, httpClient);
|
||||
|
||||
subscriptions = JsonConvert.DeserializeObject<Subscriptions>(body);
|
||||
if (subscriptions != null && subscriptions.hasMore)
|
||||
{
|
||||
string? body = await BuildHeaderAndExecuteRequests(getParams, endpoint, httpClient);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(body))
|
||||
break;
|
||||
|
||||
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))
|
||||
continue;
|
||||
|
||||
bool isRestricted = item.isRestricted ?? false;
|
||||
bool isRestrictedButAllowed = isRestricted && includeRestricted;
|
||||
|
||||
if (!isRestricted || isRestrictedButAllowed)
|
||||
users.Add(item.username, item.id);
|
||||
}
|
||||
|
||||
if (!subscriptions.hasMore)
|
||||
break;
|
||||
|
||||
offset += limit;
|
||||
getParams["offset"] = offset.ToString();
|
||||
|
||||
while (true)
|
||||
{
|
||||
Subscriptions newSubscriptions = new();
|
||||
string? loopbody = await BuildHeaderAndExecuteRequests(getParams, endpoint, httpClient);
|
||||
|
||||
if (!string.IsNullOrEmpty(loopbody) && (!loopbody.Contains("[]") || loopbody.Trim() != "[]"))
|
||||
{
|
||||
newSubscriptions = JsonConvert.DeserializeObject<Subscriptions>(loopbody, m_JsonSerializerSettings);
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
subscriptions.list.AddRange(newSubscriptions.list);
|
||||
if (!newSubscriptions.hasMore)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
offset += limit;
|
||||
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;
|
||||
@ -389,8 +401,10 @@ public class APIHelper : IAPIHelper
|
||||
|
||||
public async Task<Dictionary<string, int>?> GetActiveSubscriptions(string endpoint, bool includeRestricted, IDownloadConfig config)
|
||||
{
|
||||
int limit = 50;
|
||||
Dictionary<string, string> getParams = new()
|
||||
{
|
||||
{ "limit", $"{limit}" },
|
||||
{ "type", "active" },
|
||||
{ "format", "infinite"}
|
||||
};
|
||||
@ -398,14 +412,16 @@ public class APIHelper : IAPIHelper
|
||||
Log.Debug("Calling GetActiveSubscriptions");
|
||||
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)
|
||||
{
|
||||
int limit = 50;
|
||||
Dictionary<string, string> getParams = new()
|
||||
{
|
||||
{ "limit", $"{limit}" },
|
||||
{ "type", "expired" },
|
||||
{ "format", "infinite"}
|
||||
};
|
||||
@ -413,13 +429,15 @@ public class APIHelper : IAPIHelper
|
||||
Log.Debug("Calling GetExpiredSubscriptions");
|
||||
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)
|
||||
{
|
||||
int limit = 50;
|
||||
Dictionary<string, string> getParams = new()
|
||||
{
|
||||
{ "limit", $"{limit}" },
|
||||
{ "type", "expired" },
|
||||
{ "format", "infinite"}
|
||||
};
|
||||
@ -427,7 +445,7 @@ public class APIHelper : IAPIHelper
|
||||
Log.Debug("Calling GetBlockedUsers");
|
||||
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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user