Fixed parameters to ensure no null values are passed incorrectly

This commit is contained in:
Casper Sparre 2025-10-14 00:35:31 +02:00
parent 53e2331bf1
commit bb0f780e7f
5 changed files with 12 additions and 12 deletions

View File

@ -248,7 +248,7 @@ public class APIHelper : IAPIHelper
}
public async Task<User?> GetUserInfo(string endpoint)
public async Task<User?> GetUserInfo(string username, string endpoint)
{
Log.Debug($"Calling GetUserInfo: {endpoint}");
@ -277,7 +277,7 @@ public class APIHelper : IAPIHelper
user = JsonConvert.DeserializeObject<Entities.User>(body, m_JsonSerializerSettings);
if (user is not null && !endpoint.EndsWith("/me"))
await m_DBHelper.UpdateUserInfo(user);
await m_DBHelper.UpdateUserInfo(username, user);
return user;
}

View File

@ -254,9 +254,9 @@ namespace OF_DL.Helpers
return result;
}
public async Task UpdateUserInfo(User? user)
public async Task UpdateUserInfo(string username, User? user)
{
if (user is null)
if (user?.id is null)
return;
SqliteConnection connection = await GetAndOpenConnectionAsync($"Data Source={Directory.GetCurrentDirectory()}/users.db");
@ -270,7 +270,7 @@ namespace OF_DL.Helpers
);
cmdInfo.Parameters.AddWithValue("@userId", user.id);
cmdInfo.Parameters.AddWithValue("@name", user.name);
cmdInfo.Parameters.AddWithValue("@name", user.name ?? user.username ?? username);
cmdInfo.Parameters.AddWithValue("@about", user.about);
cmdInfo.Parameters.AddWithValue("@expiresOn", user.subscribedByExpireDate);
cmdInfo.Parameters.AddWithValue("@photoCount", user.photosCount ?? 0);

View File

@ -29,7 +29,7 @@ namespace OF_DL.Helpers
Task<PaidMessageCollection> GetPaidMessages(string endpoint, string folder, string username, int userId, IDownloadConfig config, StatusContext ctx);
Task<Dictionary<string, int>> GetPurchasedTabUsers(string endpoint, IDownloadConfig config, Dictionary<string, int> users);
Task<List<PurchasedTabCollection>> GetPurchasedTab(string endpoint, string folder, IDownloadConfig config, Dictionary<string, int> users);
Task<User> GetUserInfo(string endpoint);
Task<User> GetUserInfo(string username, string endpoint);
Task<JObject> GetUserInfoById(string endpoint);
Dictionary<string, string> GetDynamicHeaders(string path, string queryParam);
Task<Dictionary<string, int>> GetActiveSubscriptions(string endpoint, bool includeRestrictedSubscriptions, IDownloadConfig config);

View File

@ -15,6 +15,6 @@ namespace OF_DL.Helpers
Task<long> GetStoredFileSize(string folder, long media_id, string api_type);
Task<bool> CheckDownloaded(string folder, long media_id, string api_type);
Task<DateTime?> GetMostRecentPostDate(string folder);
Task UpdateUserInfo(User? user);
Task UpdateUserInfo(string username, User? user);
}
}

View File

@ -912,7 +912,7 @@ public class Program
//Check if auth is valid
var apiHelper = new APIHelper(auth, config);
Entities.User? validate = await apiHelper.GetUserInfo($"/users/me");
Entities.User? validate = await apiHelper.GetUserInfo(string.Empty, $"/users/me");
if (validate == null || (validate?.name == null && validate?.username == null))
{
Log.Error("Auth failed");
@ -1052,8 +1052,8 @@ public class Program
try
{
Log.Information("Updating User Info for for: {Username:l}");
User? user_info = await m_ApiHelper.GetUserInfo($"/users/{username}");
await dbHelper.UpdateUserInfo(user_info);
User? user_info = await m_ApiHelper.GetUserInfo(username, $"/users/{username}");
await dbHelper.UpdateUserInfo(username, user_info);
}
catch (Exception ex)
{
@ -1281,7 +1281,7 @@ public class Program
Log.Debug($"Folder for {user.Key} already created");
}
Entities.User user_info = await m_ApiHelper.GetUserInfo($"/users/{user.Key}");
Entities.User user_info = await m_ApiHelper.GetUserInfo(user.Key, $"/users/{user.Key}");
await dBHelper.CreateDB(path);
}
@ -1474,7 +1474,7 @@ public class Program
var downloadContext = new DownloadContext(Auth, Config, GetCreatorFileNameFormatConfig(Config, user.Key), m_ApiHelper, dBHelper);
User? user_info = await m_ApiHelper.GetUserInfo($"/users/{user.Key}");
User? user_info = await m_ApiHelper.GetUserInfo(user.Key, $"/users/{user.Key}");
if (Config.DownloadAvatarHeaderPhoto && user_info != null)
{