Add checks for valid auth data before making API calls for media

This commit is contained in:
whimsical-c4lic0 2026-02-10 16:40:29 -06:00
parent 94e135f168
commit a9a4c2ee20

View File

@ -147,6 +147,12 @@ public class ApiService(IAuthService authService, IConfigService configService,
return headers;
}
private bool HasSignedRequestAuth()
{
Auth? currentAuth = authService.CurrentAuth;
return currentAuth is { UserId: not null, Cookie: not null, UserAgent: not null, XBc: not null };
}
/// <summary>
/// Retrieves user information from the API.
@ -157,6 +163,11 @@ public class ApiService(IAuthService authService, IConfigService configService,
{
Log.Debug($"Calling GetUserInfo: {endpoint}");
if (!HasSignedRequestAuth())
{
return null;
}
try
{
UserEntities.User user = new();
@ -197,6 +208,11 @@ public class ApiService(IAuthService authService, IConfigService configService,
/// <returns>A JSON object when available.</returns>
public async Task<JObject?> GetUserInfoById(string endpoint)
{
if (!HasSignedRequestAuth())
{
return null;
}
try
{
HttpClient client = new();
@ -272,6 +288,11 @@ public class ApiService(IAuthService authService, IConfigService configService,
{
Log.Debug("Calling GetLists");
if (!HasSignedRequestAuth())
{
return null;
}
try
{
int offset = 0;
@ -333,6 +354,11 @@ public class ApiService(IAuthService authService, IConfigService configService,
{
Log.Debug($"Calling GetListUsers - {endpoint}");
if (!HasSignedRequestAuth())
{
return null;
}
try
{
int offset = 0;
@ -393,6 +419,11 @@ public class ApiService(IAuthService authService, IConfigService configService,
{
Log.Debug($"Calling GetMedia - {username}");
if (!HasSignedRequestAuth())
{
return null;
}
try
{
Dictionary<long, string> returnUrls = new();
@ -2928,6 +2959,11 @@ public class ApiService(IAuthService authService, IConfigService configService,
private async Task<Dictionary<string, long>?> GetAllSubscriptions(Dictionary<string, string> getParams,
string endpoint, bool includeRestricted)
{
if (!HasSignedRequestAuth())
{
return null;
}
try
{
Dictionary<string, long> users = new();