From 7a65bdf50f02f770071352b6241d5a298adf390c Mon Sep 17 00:00:00 2001 From: Casper Sparre Date: Wed, 2 Apr 2025 20:16:51 +0200 Subject: [PATCH] Added logic to save list of blocked users. --- OF DL/Entities/Config.cs | 2 ++ OF DL/Helpers/APIHelper.cs | 21 +++++++++++++++++---- OF DL/Program.cs | 37 ++++++++++++++++++++++++++++++++++++- 3 files changed, 55 insertions(+), 5 deletions(-) diff --git a/OF DL/Entities/Config.cs b/OF DL/Entities/Config.cs index 4beba86..80ad621 100644 --- a/OF DL/Entities/Config.cs +++ b/OF DL/Entities/Config.cs @@ -106,6 +106,8 @@ namespace OF_DL.Entities public string[] NonInteractiveSpecificUsers { get; set; } = []; public string[] NonInteractiveSpecificLists { get; set; } = []; + + public bool OutputBlockedUsers { get; set; } } public class CreatorConfig : IFileNameFormatConfig diff --git a/OF DL/Helpers/APIHelper.cs b/OF DL/Helpers/APIHelper.cs index 3bb720a..c4b24aa 100644 --- a/OF DL/Helpers/APIHelper.cs +++ b/OF DL/Helpers/APIHelper.cs @@ -382,7 +382,6 @@ public class APIHelper : IAPIHelper public async Task?> GetExpiredSubscriptions(string endpoint, bool includeRestricted, IDownloadConfig config) { - Dictionary getParams = new() { { "offset", "0" }, @@ -396,6 +395,20 @@ public class APIHelper : IAPIHelper return await GetAllSubscriptions(getParams, endpoint, includeRestricted, config); } + public async Task?> GetBlockedUsers(string endpoint, IDownloadConfig config) + { + Dictionary getParams = new() + { + { "offset", "0" }, + { "limit", "50" }, + { "type", "expired" }, + { "format", "infinite"} + }; + + Log.Debug("Calling GetBlockedUsers"); + + return await GetAllSubscriptions(getParams, endpoint, true, config); + } public async Task> GetLists(string endpoint, IDownloadConfig config) { @@ -2143,11 +2156,11 @@ public class APIHelper : IAPIHelper { JObject user = await GetUserInfoById($"/users/list?x[]={purchase.fromUser.id}"); - if(user is null) + if (user is null) { if (!config.BypassContentForCreatorsWhoNoLongerExist) { - if(!purchasedTabUsers.ContainsKey($"Deleted User - {purchase.fromUser.id}")) + if (!purchasedTabUsers.ContainsKey($"Deleted User - {purchase.fromUser.id}")) { purchasedTabUsers.Add($"Deleted User - {purchase.fromUser.id}", purchase.fromUser.id); } @@ -2197,7 +2210,7 @@ public class APIHelper : IAPIHelper { if (!config.BypassContentForCreatorsWhoNoLongerExist) { - if(!purchasedTabUsers.ContainsKey($"Deleted User - {purchase.author.id}")) + if (!purchasedTabUsers.ContainsKey($"Deleted User - {purchase.author.id}")) { purchasedTabUsers.Add($"Deleted User - {purchase.author.id}", purchase.author.id); } diff --git a/OF DL/Program.cs b/OF DL/Program.cs index 3fd3410..8a4bb82 100644 --- a/OF DL/Program.cs +++ b/OF DL/Program.cs @@ -515,6 +515,14 @@ public class Program } } + const string OUTPUT_BLOCKED_USERS_ARG = "--output-blocked"; + + if (args.Any(a => OUTPUT_BLOCKED_USERS_ARG.Equals(a, StringComparison.OrdinalIgnoreCase))) + { + config.NonInteractiveMode = true; + config.OutputBlockedUsers = true; + } + Log.Debug("Additional arguments:"); foreach (string argument in args) { @@ -810,6 +818,12 @@ public class Program try { + if (config.OutputBlockedUsers) + { + await DownloadBlockedUsers(apiHelper, config); + return; + } + await DownloadAllData(apiHelper, auth, config); } finally @@ -836,8 +850,29 @@ public class Program } } + private static async Task DownloadBlockedUsers(APIHelper m_ApiHelper, Entities.Config Config) + { + const string OUTPUT_FILE = "blocked-users.json"; - private static async Task DownloadAllData(APIHelper m_ApiHelper, Auth Auth, Entities.Config Config) + Log.Debug($"Calling GetBlockedUsers"); + + AnsiConsole.Markup($"[red]Getting Blocked Users\n[/]"); + + Dictionary? blockedUsers = await m_ApiHelper.GetBlockedUsers("/users/blocked", Config); + + if (blockedUsers is null || blockedUsers.Count == 0) + { + AnsiConsole.Markup($"[red]No Blocked Users found.\n[/]"); + } + else + { + AnsiConsole.Markup($"[red]Found {blockedUsers.Count} Blocked Users, saving to '{OUTPUT_FILE}'\n[/]"); + string json = JsonConvert.SerializeObject(blockedUsers, Formatting.Indented); + await File.WriteAllTextAsync(OUTPUT_FILE, json); + } + } + + private static async Task DownloadAllData(APIHelper m_ApiHelper, Auth Auth, Entities.Config Config) { DBHelper dBHelper = new DBHelper(Config);