diff --git a/API/Controllers/ReaderController.cs b/API/Controllers/ReaderController.cs index 0436e7d65e..14fc9aead2 100644 --- a/API/Controllers/ReaderController.cs +++ b/API/Controllers/ReaderController.cs @@ -288,21 +288,6 @@ public async Task> GetNextChapter(int seriesId, int volumeId, return Ok(-1); } - private int GetNextChapterId(Volume currentVolume, int currentChapterId) - { - var next = false; - foreach (var chapter in currentVolume.Chapters) - { - if (next) - { - return chapter.Id; - } - if (currentChapterId == chapter.Id) next = true; - } - - return -1; - } - private int GetNextChapterId(IEnumerable chapters, int currentChapterId) { var next = false; diff --git a/API/Parser/Parser.cs b/API/Parser/Parser.cs index 9612fb7cd4..3cffb87e64 100644 --- a/API/Parser/Parser.cs +++ b/API/Parser/Parser.cs @@ -9,7 +9,7 @@ namespace API.Parser { public static class Parser { - public static readonly string ArchiveFileExtensions = @"\.cbz|\.zip|\.rar|\.cbr|\.tar.gz|\.7zip"; + public static readonly string ArchiveFileExtensions = @"\.cbz|\.zip|\.rar|\.cbr|\.tar.gz|\.7zip|\.7z"; public static readonly string BookFileExtensions = @"\.epub"; public static readonly string ImageFileExtensions = @"^(\.png|\.jpeg|\.jpg)"; public static readonly Regex FontSrcUrlRegex = new Regex("(src:url\\(\"?'?)([a-z0-9/\\._]+)(\"?'?\\))", RegexOptions.IgnoreCase | RegexOptions.Compiled); diff --git a/API/Program.cs b/API/Program.cs index 2240e6ad6c..db3ad9a1fa 100644 --- a/API/Program.cs +++ b/API/Program.cs @@ -1,5 +1,6 @@ using System; using System.IO; +using System.Security.Cryptography; using System.Threading; using System.Threading.Tasks; using API.Data; @@ -14,7 +15,6 @@ using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Sentry; -using Sentry.Extensions.Logging; namespace API { @@ -26,12 +26,26 @@ protected Program() { } + private static string GetAppSettingFilename() + { + var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"); + var isDevelopment = environment == Environments.Development; + return "appSettings" + (isDevelopment ? ".Development" : "") + ".json"; + } + public static async Task Main(string[] args) { // Before anything, check if JWT has been generated properly or if user still has default + if (!Configuration.CheckIfJwtTokenSet(GetAppSettingFilename())) + { + Console.WriteLine("Generating JWT TokenKey for encrypting user sessions..."); + var rBytes = new byte[24]; + using (var crypto = new RNGCryptoServiceProvider()) crypto.GetBytes(rBytes); + var base64 = Convert.ToBase64String(rBytes).Replace("/", ""); + Configuration.UpdateJwtToken(GetAppSettingFilename(), base64); + } + - - var host = CreateHostBuilder(args).Build(); using var scope = host.Services.CreateScope(); diff --git a/API/Startup.cs b/API/Startup.cs index 90c7969441..29cce38329 100644 --- a/API/Startup.cs +++ b/API/Startup.cs @@ -1,8 +1,6 @@ using System; -using System.IO; using System.IO.Compression; using System.Linq; -using System.Reflection; using API.Extensions; using API.Interfaces; using API.Middleware; diff --git a/Kavita.Common/Configuration.cs b/Kavita.Common/Configuration.cs index e69de29bb2..5503e5dc1f 100644 --- a/Kavita.Common/Configuration.cs +++ b/Kavita.Common/Configuration.cs @@ -0,0 +1,47 @@ +using System; +using System.IO; +using System.Text.Json; + +namespace Kavita.Common +{ + public static class Configuration + { + + public static bool CheckIfJwtTokenSet(string filePath) + { + try { + var json = File.ReadAllText(filePath); + var jsonObj = JsonSerializer.Deserialize(json); + const string key = "TokenKey"; + + JsonElement? tokenElement = null; + if (jsonObj?.TryGetProperty(key, out tokenElement)) + { + return tokenElement?.GetString() != "super secret unguessable key"; + } + + return false; + + } + catch (Exception ex) { + Console.WriteLine("Error writing app settings: " + ex.Message); + } + + return false; + } + + public static bool UpdateJwtToken(string filePath, string token) + { + try + { + var json = File.ReadAllText(filePath).Replace("super secret unguessable key", token); + File.WriteAllText(filePath, json); + return true; + } + catch (Exception) + { + return false; + } + } + } +} \ No newline at end of file diff --git a/Kavita.Common/Kavita.Common.csproj b/Kavita.Common/Kavita.Common.csproj index 736bcdb7a0..1b93ba6228 100644 --- a/Kavita.Common/Kavita.Common.csproj +++ b/Kavita.Common/Kavita.Common.csproj @@ -9,6 +9,7 @@ + @@ -16,9 +17,6 @@ D:\Program Files\JetBrains\JetBrains Rider 2020.3.2\lib\ReSharperHost\TestRunner\netcoreapp2.0\JetBrains.ReSharper.TestRunner.Merged.dll - - ..\..\..\..\..\..\..\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.5\Microsoft.Win32.Registry.dll - diff --git a/README.md b/README.md index 83229889c4..286dbc50ea 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ your manga collection with your friends and family! [![Discord](https://img.shields.io/badge/discord-chat-7289DA.svg?maxAge=60)](https://discord.gg/eczRp9eeem) ![Github Downloads](https://img.shields.io/github/downloads/Kareadita/Kavita/total.svg) +[![Feature Requests](https://feathub.com/Kareadita/Kavita?format=svg)](https://feathub.com/Kareadita/Kavita) ## Goals: diff --git a/favicon.ico b/favicon.ico index 1ed03f4f76..cc5e735190 100644 Binary files a/favicon.ico and b/favicon.ico differ