forked from sim0n00ps/OF-DL
Updated subscription lookup logic to match the website.
It increments the offset with the limit before making the next request, until 'hasMore' is false. Also tweaked loop code, to be a bit more clean.
This commit is contained in:
parent
599d94176f
commit
99437048ce
@ -314,47 +314,44 @@ public class APIHelper : IAPIHelper
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
Dictionary<string, int> users = new();
|
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");
|
Log.Debug("Calling GetAllSubscrptions");
|
||||||
|
|
||||||
string? body = await BuildHeaderAndExecuteRequests(getParams, endpoint, new HttpClient());
|
|
||||||
|
|
||||||
subscriptions = JsonConvert.DeserializeObject<Subscriptions>(body);
|
|
||||||
if (subscriptions != null && subscriptions.hasMore)
|
|
||||||
{
|
|
||||||
getParams["offset"] = subscriptions.list.Count.ToString();
|
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
Subscriptions newSubscriptions = new();
|
string? body = await BuildHeaderAndExecuteRequests(getParams, endpoint, new HttpClient());
|
||||||
string? loopbody = await BuildHeaderAndExecuteRequests(getParams, endpoint, new 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;
|
||||||
}
|
|
||||||
getParams["offset"] = subscriptions.list.Count.ToString();
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (Subscriptions.List subscription in subscriptions.list)
|
if (!subscriptions.hasMore)
|
||||||
{
|
break;
|
||||||
if ((!(subscription.isRestricted ?? false) || ((subscription.isRestricted ?? false) && includeRestricted))
|
|
||||||
&& !users.ContainsKey(subscription.username))
|
offset += limit;
|
||||||
{
|
getParams["offset"] = offset.ToString();
|
||||||
users.Add(subscription.username, subscription.id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return users;
|
return users;
|
||||||
@ -377,8 +374,6 @@ public class APIHelper : IAPIHelper
|
|||||||
{
|
{
|
||||||
Dictionary<string, string> getParams = new()
|
Dictionary<string, string> getParams = new()
|
||||||
{
|
{
|
||||||
{ "offset", "0" },
|
|
||||||
{ "limit", "50" },
|
|
||||||
{ "type", "active" },
|
{ "type", "active" },
|
||||||
{ "format", "infinite"}
|
{ "format", "infinite"}
|
||||||
};
|
};
|
||||||
@ -392,8 +387,6 @@ public class APIHelper : IAPIHelper
|
|||||||
|
|
||||||
Dictionary<string, string> getParams = new()
|
Dictionary<string, string> getParams = new()
|
||||||
{
|
{
|
||||||
{ "offset", "0" },
|
|
||||||
{ "limit", "50" },
|
|
||||||
{ "type", "expired" },
|
{ "type", "expired" },
|
||||||
{ "format", "infinite"}
|
{ "format", "infinite"}
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user