Added logic to save list of blocked users.

This commit is contained in:
Casper Sparre 2025-04-02 20:16:51 +02:00
parent 8fd17feba5
commit 637bac5f61
3 changed files with 55 additions and 5 deletions

View File

@ -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

View File

@ -382,7 +382,6 @@ public class APIHelper : IAPIHelper
public async Task<Dictionary<string, int>?> GetExpiredSubscriptions(string endpoint, bool includeRestricted, IDownloadConfig config)
{
Dictionary<string, string> getParams = new()
{
{ "offset", "0" },
@ -396,6 +395,20 @@ public class APIHelper : IAPIHelper
return await GetAllSubscriptions(getParams, endpoint, includeRestricted, config);
}
public async Task<Dictionary<string, int>?> GetBlockedUsers(string endpoint, IDownloadConfig config)
{
Dictionary<string, string> getParams = new()
{
{ "offset", "0" },
{ "limit", "50" },
{ "type", "expired" },
{ "format", "infinite"}
};
Log.Debug("Calling GetBlockedUsers");
return await GetAllSubscriptions(getParams, endpoint, true, config);
}
public async Task<Dictionary<string, int>> 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);
}

View File

@ -514,6 +514,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)
{
@ -849,6 +857,12 @@ public class Program
try
{
if (config.OutputBlockedUsers)
{
await DownloadBlockedUsers(apiHelper, config);
return;
}
await DownloadAllData(apiHelper, auth, config);
}
finally
@ -875,8 +889,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<string, int>? 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);