forked from sim0n00ps/OF-DL
WIP
This commit is contained in:
parent
d1968d2981
commit
d0cdb5ae40
@ -146,6 +146,11 @@ namespace OF_DL.Helpers
|
||||
await cmdInfo.ExecuteNonQueryAsync();
|
||||
}
|
||||
|
||||
using (SqliteCommand cmdInfo = new("CREATE TABLE IF NOT EXISTS user_info_blob (user_id INTEGER NOT NULL, name VARCHAR NOT NULL, blob TEXT NULL, PRIMARY KEY(user_id));", connection))
|
||||
{
|
||||
await cmdInfo.ExecuteNonQueryAsync();
|
||||
}
|
||||
|
||||
Log.Debug("Adding missing creators");
|
||||
foreach (KeyValuePair<string, long> user in users)
|
||||
{
|
||||
@ -262,28 +267,56 @@ namespace OF_DL.Helpers
|
||||
SqliteConnection connection = await GetAndOpenConnectionAsync($"Data Source={Directory.GetCurrentDirectory()}/users.db");
|
||||
Log.Debug("Database data source: " + connection.DataSource);
|
||||
|
||||
//"SELECT name, about, expires_on, photo_count, video_count FROM user_info WHERE user_id = @userId"
|
||||
using SqliteCommand cmdInfo = new(
|
||||
"INSERT OR REPLACE INTO user_info (user_id, name, about, expires_on, photo_count, video_count) " +
|
||||
"VALUES (@userId, @name, @about, @expiresOn, @photoCount, @videoCount);",
|
||||
connection
|
||||
);
|
||||
await UpdateAsync();
|
||||
await UpdateBlobAsync();
|
||||
|
||||
cmdInfo.Parameters.AddWithValue("@userId", user.id);
|
||||
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);
|
||||
cmdInfo.Parameters.AddWithValue("@videoCount", user.videosCount ?? 0);
|
||||
|
||||
try
|
||||
async Task UpdateAsync()
|
||||
{
|
||||
int rowCount = await cmdInfo.ExecuteNonQueryAsync();
|
||||
Log.Debug("Inserted or updated creator info: {Username:l}", user.username);
|
||||
using SqliteCommand cmdInfo = new(
|
||||
"INSERT OR REPLACE INTO user_info (user_id, name, about, expires_on, photo_count, video_count) " +
|
||||
"VALUES (@userId, @name, @about, @expiresOn, @photoCount, @videoCount);",
|
||||
connection
|
||||
);
|
||||
|
||||
cmdInfo.Parameters.AddWithValue("@userId", user.id);
|
||||
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);
|
||||
cmdInfo.Parameters.AddWithValue("@videoCount", user.videosCount ?? 0);
|
||||
|
||||
try
|
||||
{
|
||||
await cmdInfo.ExecuteNonQueryAsync();
|
||||
Log.Debug("Inserted or updated creator info: {Username:l}", user.username);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Warning(ex, "Failed to update User Info for: {Username:l}", user.username);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
async Task UpdateBlobAsync()
|
||||
{
|
||||
Log.Warning(ex, "Failed to update User Info for: {Username:l}", user.username);
|
||||
using SqliteCommand cmdInfo = new(
|
||||
"INSERT OR REPLACE INTO user_info_blob (user_id, name, blob) " +
|
||||
"VALUES (@userId, @name, @blob);",
|
||||
connection
|
||||
);
|
||||
|
||||
cmdInfo.Parameters.AddWithValue("@userId", user.id);
|
||||
cmdInfo.Parameters.AddWithValue("@name", user.name ?? user.username ?? username);
|
||||
cmdInfo.Parameters.AddWithValue("@blob", Newtonsoft.Json.JsonConvert.SerializeObject(user));
|
||||
|
||||
try
|
||||
{
|
||||
await cmdInfo.ExecuteNonQueryAsync();
|
||||
Log.Debug("Inserted or updated creator blob: {Username:l}", user.username);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Warning(ex, "Failed to update User Info Blob for: {Username:l}", user.username);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user