Cleanup from the Release (#2127)

* Added an FAQ link on the Kavita+ tab.

* Don't query Kavita+ for ratings on comic libraries as there is no upstream provider yet.

* Jumpbar keys are a little hard to click

* Fixed an issue where libraries that don't allow scrobbling could be scrobbled when generating past history with read events.

* Made the min/max release year on metadata filter number and removed the spin arrows for styling.

* Fixed disable tabs color contrast due to bootstrap undocumented change.

* Refactored whole codebase to unify caching mechanism. Upped the default cache memory amount to 75 to account for the extra data load. Still LRU.

Fixed an issue where Cache key was using Port instead.

Refactored all the Configuration code to use strongly typed deserialization.

* Fixed an issue where get latest progress would throw an exception if there was no progress due to LINQ and MAX query.

* Fixed a bug where Send to Device wasn't present on Series cards.

* Hooked up the ability to change the cache size for Kavita via the UI.
This commit is contained in:
Joe Milazzo 2023-07-12 16:06:30 -05:00 committed by GitHub
parent 1ed8889d08
commit 81da9dc444
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
37 changed files with 402 additions and 272 deletions

View file

@ -13,7 +13,7 @@ public static class Configuration
public const int DefaultHttpPort = 5000;
public const int DefaultTimeOutSecs = 90;
public const string DefaultXFrameOptions = "SAMEORIGIN";
public const int DefaultCacheMemory = 50;
public const long DefaultCacheMemory = 75;
private static readonly string AppSettingsFilename = Path.Join("config", GetAppSettingFilename());
public static string KavitaPlusApiUrl = "https://plus.kavitareader.com";
@ -42,7 +42,7 @@ public static class Configuration
set => SetBaseUrl(GetAppSettingFilename(), value);
}
public static int CacheSize
public static long CacheSize
{
get => GetCacheSize(GetAppSettingFilename());
set => SetCacheSize(GetAppSettingFilename(), value);
@ -69,15 +69,8 @@ public static class Configuration
try
{
var json = File.ReadAllText(filePath);
var jsonObj = JsonSerializer.Deserialize<dynamic>(json);
const string key = "TokenKey";
if (jsonObj.TryGetProperty(key, out JsonElement tokenElement))
{
return tokenElement.GetString();
}
return string.Empty;
var jsonObj = JsonSerializer.Deserialize<AppSettings>(json);
return jsonObj.TokenKey;
}
catch (Exception ex)
{
@ -144,29 +137,23 @@ public static class Configuration
private static int GetPort(string filePath)
{
const int defaultPort = 5000;
if (OsInfo.IsDocker)
{
return defaultPort;
return DefaultHttpPort;
}
try
{
var json = File.ReadAllText(filePath);
var jsonObj = JsonSerializer.Deserialize<dynamic>(json);
const string key = "Port";
if (jsonObj.TryGetProperty(key, out JsonElement tokenElement))
{
return tokenElement.GetInt32();
}
var jsonObj = JsonSerializer.Deserialize<AppSettings>(json);
return jsonObj.Port;
}
catch (Exception ex)
{
Console.WriteLine("Error writing app settings: " + ex.Message);
}
return defaultPort;
return DefaultHttpPort;
}
#endregion
@ -204,13 +191,8 @@ public static class Configuration
try
{
var json = File.ReadAllText(filePath);
var jsonObj = JsonSerializer.Deserialize<dynamic>(json);
const string key = "IpAddresses";
if (jsonObj.TryGetProperty(key, out JsonElement tokenElement))
{
return tokenElement.GetString();
}
var jsonObj = JsonSerializer.Deserialize<AppSettings>(json);
return jsonObj.IpAddresses;
}
catch (Exception ex)
{
@ -224,29 +206,23 @@ public static class Configuration
#region BaseUrl
private static string GetBaseUrl(string filePath)
{
try
{
var json = File.ReadAllText(filePath);
var jsonObj = JsonSerializer.Deserialize<dynamic>(json);
const string key = "BaseUrl";
var jsonObj = JsonSerializer.Deserialize<AppSettings>(json);
if (jsonObj.TryGetProperty(key, out JsonElement tokenElement))
var baseUrl = jsonObj.BaseUrl;
if (!string.IsNullOrEmpty(baseUrl))
{
var baseUrl = tokenElement.GetString();
if (!string.IsNullOrEmpty(baseUrl))
{
baseUrl = !baseUrl.StartsWith('/')
? $"/{baseUrl}"
: baseUrl;
baseUrl = !baseUrl.StartsWith('/')
? $"/{baseUrl}"
: baseUrl;
baseUrl = !baseUrl.EndsWith('/')
? $"{baseUrl}/"
: baseUrl;
baseUrl = !baseUrl.EndsWith('/')
? $"{baseUrl}/"
: baseUrl;
return baseUrl;
}
return DefaultBaseUrl;
return baseUrl;
}
}
catch (Exception ex)
@ -284,7 +260,7 @@ public static class Configuration
#endregion
#region CacheSize
private static void SetCacheSize(string filePath, int cache)
private static void SetCacheSize(string filePath, long cache)
{
if (cache <= 0) return;
try
@ -301,18 +277,14 @@ public static class Configuration
}
}
private static int GetCacheSize(string filePath)
private static long GetCacheSize(string filePath)
{
try
{
var json = File.ReadAllText(filePath);
var jsonObj = JsonSerializer.Deserialize<dynamic>(json);
const string key = "Port";
var jsonObj = JsonSerializer.Deserialize<AppSettings>(json);
if (jsonObj.TryGetProperty(key, out JsonElement tokenElement))
{
return tokenElement.GetInt32();
}
return jsonObj.Cache;
}
catch (Exception ex)
{
@ -336,14 +308,8 @@ public static class Configuration
try
{
var json = File.ReadAllText(filePath);
var jsonObj = JsonSerializer.Deserialize<dynamic>(json);
const string key = "XFrameOrigins";
if (jsonObj.TryGetProperty(key, out JsonElement tokenElement))
{
var origins = tokenElement.GetString();
return !string.IsNullOrEmpty(origins) ? origins : DefaultBaseUrl;
}
var jsonObj = JsonSerializer.Deserialize<AppSettings>(json);
return !string.IsNullOrEmpty(jsonObj.XFrameOrigins) ? jsonObj.XFrameOrigins : DefaultXFrameOptions;
}
catch (Exception ex)
{
@ -364,6 +330,8 @@ public static class Configuration
// ReSharper disable once MemberHidesStaticFromOuterClass
public string BaseUrl { get; set; }
// ReSharper disable once MemberHidesStaticFromOuterClass
public int Cache { get; set; }
public long Cache { get; set; }
// ReSharper disable once MemberHidesStaticFromOuterClass
public string XFrameOrigins { get; set; } = DefaultXFrameOptions;
}
}