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