Compare commits

..

3 Commits

3 changed files with 20 additions and 10 deletions

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

@ -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

@ -112,6 +112,7 @@ public class Program
levelSwitch.MinimumLevel = LogEventLevel.Error; //set initial level (until we've read from config)
Log.Logger = new LoggerConfiguration()
.Enrich.FromLogContext()
.Enrich.WithProperty("Application", "OF_DL")
.Enrich.WithProperty("StartTime", $"{DateTime.Now:yyyy-MM-dd HH:mm:ss} ")
.Enrich.WithProperty("MachineName", Environment.MachineName)
@ -966,16 +967,22 @@ public class Program
Console.WriteLine();
await AnsiConsole.Progress()
.Columns(new ProgressBarColumn(), new PercentageColumn(), new TaskDescriptionColumn())
.Columns(new ProgressBarColumn(), new PercentageColumn(), new TaskDescriptionColumn { Alignment = Justify.Left })
.StartAsync(RunUpdateAsync);
async Task RunUpdateAsync(ProgressContext context)
{
ProgressTask updateTask = context.AddTask($"Updating User Info for '{users.Count}' users", true, users.Count);
ProgressTask updateTask = null;
int maxUsernameLength = users.Keys.Max(s => s.Length);
foreach ((string username, long userId) in users)
{
updateTask.Description = $"Updating '{username}'";
string description = $"Updating '{username}'".PadRight(11 + maxUsernameLength);
double prevValue = updateTask?.Value ?? 0;
updateTask = context.AddTask(description, true, users.Count);
updateTask.Value = prevValue;
using (LogContext.PushProperty("Username", username))
using (LogContext.PushProperty("UserId", userId))
@ -984,23 +991,26 @@ public class Program
{
Log.Information("Updating User Info for for: {Username:l}");
User? user_info = await m_ApiHelper.GetUserInfo($"/users/{username}");
await dbHelper.UpdateUserInfo(user_info);
await dbHelper.UpdateUserInfo(username, user_info);
updateTask.Description = $"{description} - COMPLETE";
}
catch (Exception ex)
{
Log.Warning(ex, "Failed to update User Info for: {Username:l}");
AnsiConsole.Markup($"[red]Failed to update User Info for '{username}'\n[/]");
updateTask.Description = $"{description} - FAILED: {ex.Message}";
}
finally
{
updateTask.Increment(1);
}
}
}
updateTask.StopTask();
}
}
}
}
}
private static async Task DownloadAllData(APIHelper m_ApiHelper, Auth Auth, Entities.Config Config)
{