Fixed lookup for Paid Posts and Messages, due to API changes

This commit is contained in:
Casper 2025-10-06 20:04:31 +02:00 committed by Casper Sparre
parent 824d88a6b8
commit 202558dd88
2 changed files with 21 additions and 13 deletions

View File

@ -735,12 +735,14 @@ public class APIHelper : IAPIHelper
Purchased paidPosts = new(); Purchased paidPosts = new();
PaidPostCollection paidPostCollection = new(); PaidPostCollection paidPostCollection = new();
int post_limit = 50; int post_limit = 50;
int offset = 0;
Dictionary<string, string> getParams = new() Dictionary<string, string> getParams = new()
{ {
{ "limit", post_limit.ToString() }, { "limit", post_limit.ToString() },
{ "order", "publish_date_desc" }, { "skip_users", "all" },
{ "format", "infinite" }, { "format", "infinite" },
{ "user_id", username } { "offset", offset.ToString() },
{ "author", username },
}; };
var body = await BuildHeaderAndExecuteRequests(getParams, endpoint, GetHttpClient(config)); var body = await BuildHeaderAndExecuteRequests(getParams, endpoint, GetHttpClient(config));
@ -750,9 +752,10 @@ public class APIHelper : IAPIHelper
ctx.SpinnerStyle(Style.Parse("blue")); ctx.SpinnerStyle(Style.Parse("blue"));
if (paidPosts != null && paidPosts.hasMore) if (paidPosts != null && paidPosts.hasMore)
{ {
getParams["offset"] = paidPosts.list.Count.ToString();
while (true) while (true)
{ {
offset += post_limit;
getParams["offset"] = offset.ToString();
Purchased newPaidPosts = new(); Purchased newPaidPosts = new();
@ -767,7 +770,6 @@ public class APIHelper : IAPIHelper
{ {
break; break;
} }
getParams["offset"] = Convert.ToString(Convert.ToInt32(getParams["offset"]) + post_limit);
} }
} }
@ -1524,7 +1526,8 @@ public class APIHelper : IAPIHelper
Dictionary<string, string> getParams = new() Dictionary<string, string> getParams = new()
{ {
{ "limit", post_limit.ToString() }, { "limit", post_limit.ToString() },
{ "order", "desc" } { "order", "desc" },
{ "skip_users", "all" },
}; };
var body = await BuildHeaderAndExecuteRequests(getParams, endpoint, GetHttpClient(config)); var body = await BuildHeaderAndExecuteRequests(getParams, endpoint, GetHttpClient(config));
@ -1534,9 +1537,10 @@ public class APIHelper : IAPIHelper
ctx.SpinnerStyle(Style.Parse("blue")); ctx.SpinnerStyle(Style.Parse("blue"));
if (messages.hasMore) if (messages.hasMore)
{ {
getParams["id"] = messages.list[^1].id.ToString();
while (true) while (true)
{ {
getParams["id"] = messages.list[^1].id.ToString();
Messages newmessages = new(); Messages newmessages = new();
var loopbody = await BuildHeaderAndExecuteRequests(getParams, endpoint, GetHttpClient(config)); var loopbody = await BuildHeaderAndExecuteRequests(getParams, endpoint, GetHttpClient(config));
@ -1550,7 +1554,6 @@ public class APIHelper : IAPIHelper
{ {
break; break;
} }
getParams["id"] = newmessages.list[newmessages.list.Count - 1].id.ToString();
} }
} }
@ -1835,12 +1838,14 @@ public class APIHelper : IAPIHelper
Purchased paidMessages = new(); Purchased paidMessages = new();
PaidMessageCollection paidMessageCollection = new(); PaidMessageCollection paidMessageCollection = new();
int post_limit = 50; int post_limit = 50;
int offset = 0;
Dictionary<string, string> getParams = new() Dictionary<string, string> getParams = new()
{ {
{ "limit", post_limit.ToString() }, { "limit", post_limit.ToString() },
{ "order", "publish_date_desc" }, { "skip_users", "all" },
{ "format", "infinite" }, { "format", "infinite" },
{ "user_id", username } { "offset", offset.ToString() },
{ "author", username },
}; };
var body = await BuildHeaderAndExecuteRequests(getParams, endpoint, GetHttpClient(config)); var body = await BuildHeaderAndExecuteRequests(getParams, endpoint, GetHttpClient(config));
@ -1850,9 +1855,11 @@ public class APIHelper : IAPIHelper
ctx.SpinnerStyle(Style.Parse("blue")); ctx.SpinnerStyle(Style.Parse("blue"));
if (paidMessages != null && paidMessages.hasMore) if (paidMessages != null && paidMessages.hasMore)
{ {
getParams["offset"] = paidMessages.list.Count.ToString();
while (true) while (true)
{ {
offset += post_limit;
getParams["offset"] = offset.ToString();
string loopqueryParams = "?" + string.Join("&", getParams.Select(kvp => $"{kvp.Key}={kvp.Value}")); string loopqueryParams = "?" + string.Join("&", getParams.Select(kvp => $"{kvp.Key}={kvp.Value}"));
Purchased newpaidMessages = new(); Purchased newpaidMessages = new();
Dictionary<string, string> loopheaders = GetDynamicHeaders("/api2/v2" + endpoint, loopqueryParams); Dictionary<string, string> loopheaders = GetDynamicHeaders("/api2/v2" + endpoint, loopqueryParams);
@ -1864,12 +1871,14 @@ public class APIHelper : IAPIHelper
{ {
looprequest.Headers.Add(keyValuePair.Key, keyValuePair.Value); looprequest.Headers.Add(keyValuePair.Key, keyValuePair.Value);
} }
using (var loopresponse = await loopclient.SendAsync(looprequest)) using (var loopresponse = await loopclient.SendAsync(looprequest))
{ {
loopresponse.EnsureSuccessStatusCode(); loopresponse.EnsureSuccessStatusCode();
var loopbody = await loopresponse.Content.ReadAsStringAsync(); var loopbody = await loopresponse.Content.ReadAsStringAsync();
newpaidMessages = JsonConvert.DeserializeObject<Purchased>(loopbody, m_JsonSerializerSettings); newpaidMessages = JsonConvert.DeserializeObject<Purchased>(loopbody, m_JsonSerializerSettings);
} }
paidMessages.list.AddRange(newpaidMessages.list); paidMessages.list.AddRange(newpaidMessages.list);
ctx.Status($"[red]Getting Paid Messages\n[/] [red]Found {paidMessages.list.Count}[/]"); ctx.Status($"[red]Getting Paid Messages\n[/] [red]Found {paidMessages.list.Count}[/]");
ctx.Spinner(Spinner.Known.Dots); ctx.Spinner(Spinner.Known.Dots);
@ -1878,7 +1887,6 @@ public class APIHelper : IAPIHelper
{ {
break; break;
} }
getParams["offset"] = Convert.ToString(Convert.ToInt32(getParams["offset"]) + post_limit);
} }
} }

View File

@ -1303,7 +1303,7 @@ public class Program
await AnsiConsole.Status() await AnsiConsole.Status()
.StartAsync("[red]Getting Paid Messages[/]", async ctx => .StartAsync("[red]Getting Paid Messages[/]", async ctx =>
{ {
paidMessageCollection = await downloadContext.ApiHelper.GetPaidMessages("/posts/paid", path, user.Key, downloadContext.DownloadConfig!, ctx); paidMessageCollection = await downloadContext.ApiHelper.GetPaidMessages("/posts/paid/chat", path, user.Key, downloadContext.DownloadConfig!, ctx);
}); });
int oldPaidMessagesCount = 0; int oldPaidMessagesCount = 0;
int newPaidMessagesCount = 0; int newPaidMessagesCount = 0;
@ -1956,7 +1956,7 @@ public class Program
await AnsiConsole.Status() await AnsiConsole.Status()
.StartAsync("[red]Getting Paid Posts[/]", async ctx => .StartAsync("[red]Getting Paid Posts[/]", async ctx =>
{ {
purchasedPosts = await downloadContext.ApiHelper.GetPaidPosts("/posts/paid", path, user.Key, downloadContext.DownloadConfig!, paid_post_ids, ctx); purchasedPosts = await downloadContext.ApiHelper.GetPaidPosts("/posts/paid/post", path, user.Key, downloadContext.DownloadConfig!, paid_post_ids, ctx);
}); });
int oldPaidPostCount = 0; int oldPaidPostCount = 0;