From a9a4c2ee2068e76e869b7058413def5dcf45fd54 Mon Sep 17 00:00:00 2001 From: whimsical-c4lic0 Date: Tue, 10 Feb 2026 16:40:29 -0600 Subject: [PATCH] Add checks for valid auth data before making API calls for media --- OF DL.Core/Services/ApiService.cs | 36 +++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/OF DL.Core/Services/ApiService.cs b/OF DL.Core/Services/ApiService.cs index 09efb41..c6126bd 100644 --- a/OF DL.Core/Services/ApiService.cs +++ b/OF DL.Core/Services/ApiService.cs @@ -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 }; + } + /// /// 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, /// A JSON object when available. public async Task 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 returnUrls = new(); @@ -2928,6 +2959,11 @@ public class ApiService(IAuthService authService, IConfigService configService, private async Task?> GetAllSubscriptions(Dictionary getParams, string endpoint, bool includeRestricted) { + if (!HasSignedRequestAuth()) + { + return null; + } + try { Dictionary users = new();