Added logic to save list of blocked users.

This commit is contained in:
Casper Sparre 2025-04-02 20:16:51 +02:00
parent 499f13dba9
commit 5effa47fac
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[] NonInteractiveSpecificUsers { get; set; } = [];
public string[] NonInteractiveSpecificLists { get; set; } = []; public string[] NonInteractiveSpecificLists { get; set; } = [];
public bool OutputBlockedUsers { get; set; }
} }
public class CreatorConfig : IFileNameFormatConfig 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) public async Task<Dictionary<string, int>?> GetExpiredSubscriptions(string endpoint, bool includeRestricted, IDownloadConfig config)
{ {
Dictionary<string, string> getParams = new() Dictionary<string, string> getParams = new()
{ {
{ "offset", "0" }, { "offset", "0" },
@ -396,6 +395,20 @@ public class APIHelper : IAPIHelper
return await GetAllSubscriptions(getParams, endpoint, includeRestricted, config); 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) public async Task<Dictionary<string, int>> GetLists(string endpoint, IDownloadConfig config)
{ {

View File

@ -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:"); Log.Debug("Additional arguments:");
foreach (string argument in args) foreach (string argument in args)
{ {
@ -810,6 +818,12 @@ public class Program
try try
{ {
if (config.OutputBlockedUsers)
{
await DownloadBlockedUsers(apiHelper, config);
return;
}
await DownloadAllData(apiHelper, auth, config); await DownloadAllData(apiHelper, auth, config);
} }
finally finally
@ -836,6 +850,27 @@ public class Program
} }
} }
private static async Task DownloadBlockedUsers(APIHelper m_ApiHelper, Entities.Config Config)
{
const string OUTPUT_FILE = "blocked-users.json";
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) private static async Task DownloadAllData(APIHelper m_ApiHelper, Auth Auth, Entities.Config Config)
{ {