forked from sim0n00ps/OF-DL
Compare commits
3 Commits
c50525bd77
...
333e91d01c
| Author | SHA1 | Date | |
|---|---|---|---|
| 333e91d01c | |||
| 5a7e9ed74e | |||
| 2fcfe879e7 |
@ -246,7 +246,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}");
|
Log.Debug($"Calling GetUserInfo: {endpoint}");
|
||||||
|
|
||||||
@ -275,7 +275,7 @@ public class APIHelper : IAPIHelper
|
|||||||
user = JsonConvert.DeserializeObject<Entities.User>(body, m_JsonSerializerSettings);
|
user = JsonConvert.DeserializeObject<Entities.User>(body, m_JsonSerializerSettings);
|
||||||
|
|
||||||
if (user is not null && !endpoint.EndsWith("/me"))
|
if (user is not null && !endpoint.EndsWith("/me"))
|
||||||
await m_DBHelper.UpdateUserInfo(user);
|
await m_DBHelper.UpdateUserInfo(username, user);
|
||||||
|
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -254,9 +254,9 @@ namespace OF_DL.Helpers
|
|||||||
return result;
|
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;
|
return;
|
||||||
|
|
||||||
SqliteConnection connection = await GetAndOpenConnectionAsync($"Data Source={Directory.GetCurrentDirectory()}/users.db");
|
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("@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("@about", user.about);
|
||||||
cmdInfo.Parameters.AddWithValue("@expiresOn", user.subscribedByExpireDate);
|
cmdInfo.Parameters.AddWithValue("@expiresOn", user.subscribedByExpireDate);
|
||||||
cmdInfo.Parameters.AddWithValue("@photoCount", user.photosCount ?? 0);
|
cmdInfo.Parameters.AddWithValue("@photoCount", user.photosCount ?? 0);
|
||||||
|
|||||||
@ -29,7 +29,7 @@ namespace OF_DL.Helpers
|
|||||||
Task<PaidMessageCollection> GetPaidMessages(string endpoint, string folder, string username, int userId, IDownloadConfig config, StatusContext ctx);
|
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<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<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);
|
Task<JObject> GetUserInfoById(string endpoint);
|
||||||
Dictionary<string, string> GetDynamicHeaders(string path, string queryParam);
|
Dictionary<string, string> GetDynamicHeaders(string path, string queryParam);
|
||||||
Task<Dictionary<string, int>> GetActiveSubscriptions(string endpoint, bool includeRestrictedSubscriptions, IDownloadConfig config);
|
Task<Dictionary<string, int>> GetActiveSubscriptions(string endpoint, bool includeRestrictedSubscriptions, IDownloadConfig config);
|
||||||
|
|||||||
@ -15,6 +15,6 @@ namespace OF_DL.Helpers
|
|||||||
Task<long> GetStoredFileSize(string folder, long media_id, string api_type);
|
Task<long> GetStoredFileSize(string folder, long media_id, string api_type);
|
||||||
Task<bool> CheckDownloaded(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<DateTime?> GetMostRecentPostDate(string folder);
|
||||||
Task UpdateUserInfo(User? user);
|
Task UpdateUserInfo(string username, User? user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -112,6 +112,7 @@ public class Program
|
|||||||
levelSwitch.MinimumLevel = LogEventLevel.Error; //set initial level (until we've read from config)
|
levelSwitch.MinimumLevel = LogEventLevel.Error; //set initial level (until we've read from config)
|
||||||
|
|
||||||
Log.Logger = new LoggerConfiguration()
|
Log.Logger = new LoggerConfiguration()
|
||||||
|
.Enrich.FromLogContext()
|
||||||
.Enrich.WithProperty("Application", "OF_DL")
|
.Enrich.WithProperty("Application", "OF_DL")
|
||||||
.Enrich.WithProperty("StartTime", $"{DateTime.Now:yyyy-MM-dd HH:mm:ss} ")
|
.Enrich.WithProperty("StartTime", $"{DateTime.Now:yyyy-MM-dd HH:mm:ss} ")
|
||||||
.Enrich.WithProperty("MachineName", Environment.MachineName)
|
.Enrich.WithProperty("MachineName", Environment.MachineName)
|
||||||
@ -843,7 +844,7 @@ public class Program
|
|||||||
//Check if auth is valid
|
//Check if auth is valid
|
||||||
var apiHelper = new APIHelper(auth, config);
|
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))
|
if (validate == null || (validate?.name == null && validate?.username == null))
|
||||||
{
|
{
|
||||||
Log.Error("Auth failed");
|
Log.Error("Auth failed");
|
||||||
@ -966,16 +967,22 @@ public class Program
|
|||||||
|
|
||||||
Console.WriteLine();
|
Console.WriteLine();
|
||||||
await AnsiConsole.Progress()
|
await AnsiConsole.Progress()
|
||||||
.Columns(new ProgressBarColumn(), new PercentageColumn(), new TaskDescriptionColumn())
|
.Columns(new ProgressBarColumn(), new PercentageColumn(), new TaskDescriptionColumn { Alignment = Justify.Left })
|
||||||
.StartAsync(RunUpdateAsync);
|
.StartAsync(RunUpdateAsync);
|
||||||
|
|
||||||
async Task RunUpdateAsync(ProgressContext context)
|
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)
|
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("Username", username))
|
||||||
using (LogContext.PushProperty("UserId", userId))
|
using (LogContext.PushProperty("UserId", userId))
|
||||||
@ -983,24 +990,27 @@ public class Program
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
Log.Information("Updating User Info for for: {Username:l}");
|
Log.Information("Updating User Info for for: {Username:l}");
|
||||||
User? user_info = await m_ApiHelper.GetUserInfo($"/users/{username}");
|
User? user_info = await m_ApiHelper.GetUserInfo(username, $"/users/{username}");
|
||||||
await dbHelper.UpdateUserInfo(user_info);
|
await dbHelper.UpdateUserInfo(username, user_info);
|
||||||
|
|
||||||
|
updateTask.Description = $"{description} - COMPLETE";
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Log.Warning(ex, "Failed to update User Info for: {Username:l}");
|
Log.Warning(ex, "Failed to update User Info for: {Username:l}");
|
||||||
AnsiConsole.Markup($"[red]Failed to update User Info for '{username}'\n[/]");
|
AnsiConsole.Markup($"[red]Failed to update User Info for '{username}'\n[/]");
|
||||||
|
|
||||||
|
updateTask.Description = $"{description} - FAILED: {ex.Message}";
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
updateTask.Increment(1);
|
updateTask.Increment(1);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
updateTask.StopTask();
|
updateTask.StopTask();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static async Task DownloadAllData(APIHelper m_ApiHelper, Auth Auth, Entities.Config Config)
|
private static async Task DownloadAllData(APIHelper m_ApiHelper, Auth Auth, Entities.Config Config)
|
||||||
{
|
{
|
||||||
@ -1212,7 +1222,7 @@ public class Program
|
|||||||
Log.Debug($"Folder for {user.Key} already created");
|
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);
|
await dBHelper.CreateDB(path);
|
||||||
}
|
}
|
||||||
@ -1405,7 +1415,7 @@ public class Program
|
|||||||
|
|
||||||
var downloadContext = new DownloadContext(Auth, Config, GetCreatorFileNameFormatConfig(Config, user.Key), m_ApiHelper, dBHelper);
|
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)
|
if (Config.DownloadAvatarHeaderPhoto && user_info != null)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user