Bugfix/release cleanup (#512)

* Lots of cleanup on the warnings in the solution. Deprecated IsLastWriteLessThan and made a new method HasFileBeenModifiedSince.

* Added some tests for the new extension method.

* Changed filter import to use correct import

* Scan Series now uses Refresh Metadata for Series, rather than library one.

* Fixed an issue where cover generation wasn't properly taking forced update into consideration. Removed a case of cover generation for no reason.

* Fixed series downloads not triggering backend call
This commit is contained in:
Joseph Milazzo 2021-08-21 10:03:47 -07:00 committed by GitHub
parent 2a3a08de74
commit 0d2d73e8ae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
33 changed files with 116 additions and 131 deletions

View file

@ -8,7 +8,7 @@ namespace Kavita.Common
{
public static class Configuration
{
private static string AppSettingsFilename = GetAppSettingFilename();
private static readonly string AppSettingsFilename = GetAppSettingFilename();
public static string Branch
{
get => GetBranch(GetAppSettingFilename());
@ -53,6 +53,7 @@ namespace Kavita.Common
var json = File.ReadAllText(filePath);
var jsonObj = JsonSerializer.Deserialize<dynamic>(json);
const string key = "TokenKey";
if (jsonObj == null) return string.Empty;
if (jsonObj.TryGetProperty(key, out JsonElement tokenElement))
{
@ -69,7 +70,7 @@ namespace Kavita.Common
return string.Empty;
}
private static bool SetJwtToken(string filePath, string token)
private static void SetJwtToken(string filePath, string token)
{
try
{
@ -77,53 +78,37 @@ namespace Kavita.Common
var json = File.ReadAllText(filePath)
.Replace("\"TokenKey\": \"" + currentToken, "\"TokenKey\": \"" + token);
File.WriteAllText(filePath, json);
return true;
}
catch (Exception)
{
return false;
/* Swallow exception */
}
}
public static bool CheckIfJwtTokenSet()
{
//string filePath
try
{
return GetJwtToken(GetAppSettingFilename()) != "super secret unguessable key";
}
catch (Exception ex)
{
Console.WriteLine("Error writing app settings: " + ex.Message);
}
try
{
return GetJwtToken(GetAppSettingFilename()) != "super secret unguessable key";
}
catch (Exception ex)
{
Console.WriteLine("Error writing app settings: " + ex.Message);
}
return false;
return false;
}
public static bool UpdateJwtToken(string token)
{
try
{
var filePath = GetAppSettingFilename();
var json = File.ReadAllText(filePath).Replace("super secret unguessable key", token);
File.WriteAllText(GetAppSettingFilename(), json);
return true;
}
catch (Exception)
{
return false;
}
}
#endregion
#region Port
public static bool SetPort(string filePath, int port)
private static void SetPort(string filePath, int port)
{
if (new OsInfo(Array.Empty<IOsVersionAdapter>()).IsDocker)
{
return true;
return;
}
try
@ -131,15 +116,14 @@ namespace Kavita.Common
var currentPort = GetPort(filePath);
var json = File.ReadAllText(filePath).Replace("\"Port\": " + currentPort, "\"Port\": " + port);
File.WriteAllText(filePath, json);
return true;
}
catch (Exception)
{
return false;
/* Swallow Exception */
}
}
public static int GetPort(string filePath)
private static int GetPort(string filePath)
{
const int defaultPort = 5000;
if (new OsInfo(Array.Empty<IOsVersionAdapter>()).IsDocker)
@ -152,6 +136,7 @@ namespace Kavita.Common
var json = File.ReadAllText(filePath);
var jsonObj = JsonSerializer.Deserialize<dynamic>(json);
const string key = "Port";
if (jsonObj == null) return defaultPort;
if (jsonObj.TryGetProperty(key, out JsonElement tokenElement))
{
@ -170,7 +155,7 @@ namespace Kavita.Common
#region LogLevel
public static bool SetLogLevel(string filePath, string logLevel)
private static void SetLogLevel(string filePath, string logLevel)
{
try
{
@ -178,20 +163,21 @@ namespace Kavita.Common
var json = File.ReadAllText(filePath)
.Replace($"\"Default\": \"{currentLevel}\"", $"\"Default\": \"{logLevel}\"");
File.WriteAllText(filePath, json);
return true;
}
catch (Exception)
{
return false;
/* Swallow Exception */
}
}
public static string GetLogLevel(string filePath)
private static string GetLogLevel(string filePath)
{
try
{
var json = File.ReadAllText(filePath);
var jsonObj = JsonSerializer.Deserialize<dynamic>(json);
if (jsonObj == null) return string.Empty;
if (jsonObj.TryGetProperty("Logging", out JsonElement tokenElement))
{
foreach (var property in tokenElement.EnumerateObject())
@ -217,7 +203,7 @@ namespace Kavita.Common
#endregion
public static string GetBranch(string filePath)
private static string GetBranch(string filePath)
{
const string defaultBranch = "main";
@ -226,6 +212,7 @@ namespace Kavita.Common
var json = File.ReadAllText(filePath);
var jsonObj = JsonSerializer.Deserialize<dynamic>(json);
const string key = "Branch";
if (jsonObj == null) return string.Empty;
if (jsonObj.TryGetProperty(key, out JsonElement tokenElement))
{
@ -240,7 +227,7 @@ namespace Kavita.Common
return defaultBranch;
}
public static bool SetBranch(string filePath, string updatedBranch)
private static void SetBranch(string filePath, string updatedBranch)
{
try
{
@ -248,11 +235,10 @@ namespace Kavita.Common
var json = File.ReadAllText(filePath)
.Replace("\"Branch\": " + currentBranch, "\"Branch\": " + updatedBranch);
File.WriteAllText(filePath, json);
return true;
}
catch (Exception)
{
return false;
/* Swallow Exception */
}
}
}