Added safe-guard against paid content returned for other models

This commit is contained in:
Casper Sparre 2025-10-06 20:10:23 +02:00
parent 579d62d889
commit deabe347cb
3 changed files with 25 additions and 16 deletions

View File

@ -895,7 +895,7 @@ public class APIHelper : IAPIHelper
} }
public async Task<PaidPostCollection> GetPaidPosts(string endpoint, string folder, string username, IDownloadConfig config, List<long> paid_post_ids, StatusContext ctx) public async Task<PaidPostCollection> GetPaidPosts(string endpoint, string folder, string username, int userId, IDownloadConfig config, List<long> paid_post_ids, StatusContext ctx)
{ {
Log.Debug($"Calling GetPaidPosts - {username}"); Log.Debug($"Calling GetPaidPosts - {username}");
@ -946,6 +946,9 @@ public class APIHelper : IAPIHelper
{ {
if (purchase.responseType == "post" && purchase.media != null && purchase.media.Count > 0) if (purchase.responseType == "post" && purchase.media != null && purchase.media.Count > 0)
{ {
if (purchase.fromUser.id != userId)
continue; // Ensures only posts from current model are included
List<long> previewids = new(); List<long> previewids = new();
if (purchase.previews != null) if (purchase.previews != null)
{ {
@ -1999,7 +2002,7 @@ public class APIHelper : IAPIHelper
} }
public async Task<PaidMessageCollection> GetPaidMessages(string endpoint, string folder, string username, IDownloadConfig config, StatusContext ctx) public async Task<PaidMessageCollection> GetPaidMessages(string endpoint, string folder, string username, int userId, IDownloadConfig config, StatusContext ctx)
{ {
Log.Debug($"Calling GetPaidMessages - {username}"); Log.Debug($"Calling GetPaidMessages - {username}");
@ -2062,10 +2065,16 @@ public class APIHelper : IAPIHelper
if (paidMessages.list != null && paidMessages.list.Count > 0) if (paidMessages.list != null && paidMessages.list.Count > 0)
{ {
int ownUserId = Convert.ToInt32(auth.USER_ID);
int[] validUserIds = [ownUserId, userId];
foreach (Purchased.List purchase in paidMessages.list.Where(p => p.responseType == "message").OrderByDescending(p => p.postedAt ?? p.createdAt)) foreach (Purchased.List purchase in paidMessages.list.Where(p => p.responseType == "message").OrderByDescending(p => p.postedAt ?? p.createdAt))
{ {
if (!config.IgnoreOwnMessages || purchase.fromUser.id != Convert.ToInt32(auth.USER_ID)) if (!config.IgnoreOwnMessages || purchase.fromUser.id != ownUserId)
{ {
if (!validUserIds.Contains(purchase.fromUser.id))
continue; // Ensures only messages from current model (or self) are included
if (purchase.postedAt != null) if (purchase.postedAt != null)
{ {
await m_DBHelper.AddMessage(folder, purchase.id, purchase.text != null ? purchase.text : string.Empty, purchase.price != null ? purchase.price : "0", true, false, purchase.postedAt.Value, purchase.fromUser.id); await m_DBHelper.AddMessage(folder, purchase.id, purchase.text != null ? purchase.text : string.Empty, purchase.price != null ? purchase.price : "0", true, false, purchase.postedAt.Value, purchase.fromUser.id);

View File

@ -20,13 +20,13 @@ namespace OF_DL.Helpers
Task<List<string>> GetListUsers(string endpoint, IDownloadConfig config); Task<List<string>> GetListUsers(string endpoint, IDownloadConfig config);
Task<Dictionary<string, int>?> GetUsersFromList(string endpoint, bool includeRestricted, IDownloadConfig config); Task<Dictionary<string, int>?> GetUsersFromList(string endpoint, bool includeRestricted, IDownloadConfig config);
Task<Dictionary<long, string>> GetMedia(MediaType mediatype, string endpoint, string? username, string folder, IDownloadConfig config, List<long> paid_post_ids); Task<Dictionary<long, string>> GetMedia(MediaType mediatype, string endpoint, string? username, string folder, IDownloadConfig config, List<long> paid_post_ids);
Task<PaidPostCollection> GetPaidPosts(string endpoint, string folder, string username, IDownloadConfig config, List<long> paid_post_ids, StatusContext ctx); Task<PaidPostCollection> GetPaidPosts(string endpoint, string folder, string username, int userId, IDownloadConfig config, List<long> paid_post_ids, StatusContext ctx);
Task<PostCollection> GetPosts(string endpoint, string folder, IDownloadConfig config, List<long> paid_post_ids, StatusContext ctx); Task<PostCollection> GetPosts(string endpoint, string folder, IDownloadConfig config, List<long> paid_post_ids, StatusContext ctx);
Task<SinglePostCollection> GetPost(string endpoint, string folder, IDownloadConfig config); Task<SinglePostCollection> GetPost(string endpoint, string folder, IDownloadConfig config);
Task<StreamsCollection> GetStreams(string endpoint, string folder, IDownloadConfig config, List<long> paid_post_ids, StatusContext ctx); Task<StreamsCollection> GetStreams(string endpoint, string folder, IDownloadConfig config, List<long> paid_post_ids, StatusContext ctx);
Task<ArchivedCollection> GetArchived(string endpoint, string folder, IDownloadConfig config, StatusContext ctx); Task<ArchivedCollection> GetArchived(string endpoint, string folder, IDownloadConfig config, StatusContext ctx);
Task<MessageCollection> GetMessages(string endpoint, string folder, IDownloadConfig config, StatusContext ctx); Task<MessageCollection> GetMessages(string endpoint, string folder, IDownloadConfig config, StatusContext ctx);
Task<PaidMessageCollection> GetPaidMessages(string endpoint, string folder, string username, IDownloadConfig config, StatusContext ctx); Task<PaidMessageCollection> GetPaidMessages(string endpoint, string folder, string username, int userId, IDownloadConfig config, StatusContext ctx);
Task<Dictionary<string, int>> GetPurchasedTabUsers(string endpoint, IDownloadConfig config, Dictionary<string, int> users); Task<Dictionary<string, int>> GetPurchasedTabUsers(string endpoint, IDownloadConfig config, Dictionary<string, int> users);
Task<List<PurchasedTabCollection>> GetPurchasedTab(string endpoint, string folder, IDownloadConfig config, Dictionary<string, int> users); Task<List<PurchasedTabCollection>> GetPurchasedTab(string endpoint, string folder, IDownloadConfig config, Dictionary<string, int> users);
Task<User> GetUserInfo(string endpoint); Task<User> GetUserInfo(string endpoint);

View File

@ -1435,7 +1435,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/chat", path, user.Key, downloadContext.DownloadConfig!, ctx); paidMessageCollection = await downloadContext.ApiHelper.GetPaidMessages("/posts/paid/chat", path, user.Key, user.Value, downloadContext.DownloadConfig!, ctx);
}); });
int oldPaidMessagesCount = 0; int oldPaidMessagesCount = 0;
int newPaidMessagesCount = 0; int newPaidMessagesCount = 0;
@ -2098,7 +2098,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/post", path, user.Key, downloadContext.DownloadConfig!, paid_post_ids, ctx); purchasedPosts = await downloadContext.ApiHelper.GetPaidPosts("/posts/paid/post", path, user.Key, user.Value, downloadContext.DownloadConfig!, paid_post_ids, ctx);
}); });
int oldPaidPostCount = 0; int oldPaidPostCount = 0;