mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-05-24 00:52:23 -04:00
Lots of cleanup
This commit is contained in:
parent
bd5a1338c4
commit
077e5f798a
@ -1,18 +1,10 @@
|
||||
using API.Helpers.Converters;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace API.Tests.Converters
|
||||
{
|
||||
public class CronConverterTests
|
||||
{
|
||||
private readonly ITestOutputHelper _testOutputHelper;
|
||||
|
||||
public CronConverterTests(ITestOutputHelper testOutputHelper)
|
||||
{
|
||||
_testOutputHelper = testOutputHelper;
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("daily", "0 0 * * *")]
|
||||
[InlineData("disabled", "0 0 31 2 *")]
|
||||
|
@ -1,5 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using API.Entities;
|
||||
using API.Entities.Enums;
|
||||
using API.Parser;
|
||||
using Xunit;
|
||||
using static API.Parser.Parser;
|
||||
|
@ -1,8 +1,4 @@
|
||||
using API.Interfaces;
|
||||
using API.Services;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NSubstitute;
|
||||
using Xunit;
|
||||
using Xunit;
|
||||
|
||||
namespace API.Tests.Services
|
||||
{
|
||||
|
@ -3,7 +3,6 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using API.Constants;
|
||||
using API.Data.Migrations;
|
||||
using API.DTOs;
|
||||
using API.Entities;
|
||||
using API.Extensions;
|
||||
|
@ -1,6 +1,5 @@
|
||||
using System.IO;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace API.Controllers
|
||||
{
|
||||
|
@ -18,7 +18,7 @@ namespace API.Controllers
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[HttpPost("restart")]
|
||||
public ActionResult RestartServer()
|
||||
{
|
||||
_logger.LogInformation($"{User.GetUsername()} is restarting server from admin dashboard.");
|
||||
|
@ -1,8 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using API.DTOs;
|
||||
using API.Entities;
|
||||
using API.Entities.Enums;
|
||||
using API.Extensions;
|
||||
using API.Helpers.Converters;
|
||||
using API.Interfaces;
|
||||
@ -62,6 +63,13 @@ namespace API.Controllers
|
||||
setting.Value = updateSettingsDto.TaskScan;
|
||||
_unitOfWork.SettingsRepository.Update(setting);
|
||||
}
|
||||
|
||||
if (setting.Key == ServerSettingKey.Port && updateSettingsDto.Port + "" != setting.Value)
|
||||
{
|
||||
setting.Value = updateSettingsDto.Port + "";
|
||||
Environment.SetEnvironmentVariable("KAVITA_PORT", setting.Value);
|
||||
_unitOfWork.SettingsRepository.Update(setting);
|
||||
}
|
||||
}
|
||||
|
||||
if (_unitOfWork.HasChanges() && await _unitOfWork.Complete())
|
||||
|
@ -1,6 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using API.Entities;
|
||||
using API.Entities.Enums;
|
||||
|
||||
namespace API.DTOs
|
||||
{
|
||||
|
@ -1,5 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using API.Entities;
|
||||
using API.Entities.Enums;
|
||||
|
||||
namespace API.DTOs
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
using API.Entities;
|
||||
using API.Entities.Enums;
|
||||
|
||||
namespace API.DTOs
|
||||
{
|
||||
|
@ -6,5 +6,6 @@
|
||||
public string TaskScan { get; set; }
|
||||
public string LoggingLevel { get; set; }
|
||||
public string TaskBackup { get; set; }
|
||||
public int Port { get; set; }
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace API.DTOs
|
||||
@ -11,6 +12,9 @@ namespace API.DTOs
|
||||
public byte[] CoverImage { get; set; }
|
||||
public int Pages { get; set; }
|
||||
public int PagesRead { get; set; }
|
||||
public DateTime LastModified { get; set; }
|
||||
public DateTime Created { get; set; }
|
||||
public bool IsSpecial { get; set; }
|
||||
public ICollection<ChapterDto> Chapters { get; set; }
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using API.Constants;
|
||||
using API.Entities;
|
||||
using API.Entities.Enums;
|
||||
using API.Services;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
|
||||
@ -30,12 +31,15 @@ namespace API.Data
|
||||
|
||||
public static async Task SeedSettings(DataContext context)
|
||||
{
|
||||
context.Database.EnsureCreated();
|
||||
await context.Database.EnsureCreatedAsync();
|
||||
|
||||
IList<ServerSetting> defaultSettings = new List<ServerSetting>()
|
||||
{
|
||||
new() {Key = ServerSettingKey.CacheDirectory, Value = CacheService.CacheDirectory},
|
||||
new () {Key = ServerSettingKey.TaskScan, Value = "daily"}
|
||||
new () {Key = ServerSettingKey.TaskScan, Value = "daily"},
|
||||
//new () {Key = ServerSettingKey.LoggingLevel, Value = "Information"},
|
||||
//new () {Key = ServerSettingKey.TaskBackup, Value = "daily"},
|
||||
new () {Key = ServerSettingKey.Port, Value = "5000"},
|
||||
};
|
||||
|
||||
foreach (var defaultSetting in defaultSettings)
|
||||
@ -43,7 +47,7 @@ namespace API.Data
|
||||
var existing = context.ServerSetting.FirstOrDefault(s => s.Key == defaultSetting.Key);
|
||||
if (existing == null)
|
||||
{
|
||||
context.ServerSetting.Add(defaultSetting);
|
||||
await context.ServerSetting.AddAsync(defaultSetting);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@ using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using API.DTOs;
|
||||
using API.Entities;
|
||||
using API.Entities.Enums;
|
||||
using API.Interfaces;
|
||||
using AutoMapper;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
@ -1,6 +1,6 @@
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace API.Entities
|
||||
namespace API.Entities.Enums
|
||||
{
|
||||
public enum LibraryType
|
||||
{
|
||||
|
@ -1,6 +1,6 @@
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace API.Entities
|
||||
namespace API.Entities.Enums
|
||||
{
|
||||
public enum MangaFormat
|
||||
{
|
||||
|
@ -1,10 +1,11 @@
|
||||
namespace API.Entities
|
||||
namespace API.Entities.Enums
|
||||
{
|
||||
public enum ServerSettingKey
|
||||
{
|
||||
TaskScan = 0,
|
||||
CacheDirectory = 1,
|
||||
TaskBackup = 2,
|
||||
LoggingLevel = 3
|
||||
LoggingLevel = 3,
|
||||
Port = 4
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using API.Entities.Enums;
|
||||
using API.Entities.Interfaces;
|
||||
|
||||
namespace API.Entities
|
||||
|
@ -1,4 +1,6 @@
|
||||
|
||||
using API.Entities.Enums;
|
||||
|
||||
namespace API.Entities
|
||||
{
|
||||
public class MangaFile
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using API.Entities.Enums;
|
||||
using API.Entities.Interfaces;
|
||||
|
||||
namespace API.Entities
|
||||
|
@ -1,6 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using API.DTOs;
|
||||
using API.Entities;
|
||||
using API.Entities.Enums;
|
||||
using AutoMapper;
|
||||
|
||||
namespace API.Helpers.Converters
|
||||
@ -26,7 +27,9 @@ namespace API.Helpers.Converters
|
||||
case ServerSettingKey.TaskBackup:
|
||||
destination.TaskBackup = row.Value;
|
||||
break;
|
||||
|
||||
case ServerSettingKey.Port:
|
||||
destination.Port = int.Parse(row.Value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
using System.Threading.Tasks;
|
||||
using API.DTOs;
|
||||
using API.Entities;
|
||||
using API.Entities.Enums;
|
||||
|
||||
namespace API.Interfaces
|
||||
{
|
||||
|
@ -1,9 +1,8 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text.RegularExpressions;
|
||||
using API.Entities;
|
||||
using API.Entities.Enums;
|
||||
|
||||
namespace API.Parser
|
||||
{
|
||||
|
@ -1,5 +1,4 @@
|
||||
|
||||
using API.Entities;
|
||||
using API.Entities.Enums;
|
||||
|
||||
namespace API.Parser
|
||||
{
|
||||
|
@ -4,7 +4,6 @@ using API.Data;
|
||||
using API.Entities;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
@ -14,12 +13,11 @@ namespace API
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
private static readonly int HttpPort = 5000;
|
||||
protected Program()
|
||||
{
|
||||
}
|
||||
|
||||
private static readonly int HttpPort = 5000; // TODO: Get from DB
|
||||
|
||||
public static async Task Main(string[] args)
|
||||
{
|
||||
var host = CreateHostBuilder(args).Build();
|
||||
@ -41,7 +39,7 @@ namespace API
|
||||
var logger = services.GetRequiredService < ILogger<Program>>();
|
||||
logger.LogError(ex, "An error occurred during migration");
|
||||
}
|
||||
|
||||
|
||||
await host.RunAsync();
|
||||
}
|
||||
|
||||
@ -49,26 +47,40 @@ namespace API
|
||||
Host.CreateDefaultBuilder(args)
|
||||
.ConfigureWebHostDefaults(webBuilder =>
|
||||
{
|
||||
webBuilder.UseKestrel((builderContext, opts) =>
|
||||
webBuilder.UseKestrel((opts) =>
|
||||
{
|
||||
opts.ListenAnyIP(HttpPort);
|
||||
});
|
||||
webBuilder.UseStartup<Startup>();
|
||||
});
|
||||
|
||||
private static string BuildUrl(string scheme, string bindAddress, int port)
|
||||
{
|
||||
return $"{scheme}://{bindAddress}:{port}";
|
||||
}
|
||||
|
||||
private static void ConfigureKestrelForHttps(KestrelServerOptions options)
|
||||
{
|
||||
options.ListenAnyIP(HttpPort);
|
||||
// options.ListenAnyIP(HttpsPort, listenOptions =>
|
||||
// {
|
||||
// listenOptions.Protocols = HttpProtocols.Http1AndHttp2;
|
||||
// //listenOptions.UseHttps(pfxFilePath, pfxPassword);
|
||||
// });
|
||||
}
|
||||
|
||||
// private static void StartNewInstance()
|
||||
// {
|
||||
// //_logger.LogInformation("Starting new instance");
|
||||
//
|
||||
// var module = options.RestartPath;
|
||||
//
|
||||
// if (string.IsNullOrWhiteSpace(module))
|
||||
// {
|
||||
// module = Environment.GetCommandLineArgs()[0];
|
||||
// }
|
||||
//
|
||||
// // string commandLineArgsString;
|
||||
// // if (options.RestartArgs != null)
|
||||
// // {
|
||||
// // commandLineArgsString = options.RestartArgs ?? string.Empty;
|
||||
// // }
|
||||
// // else
|
||||
// // {
|
||||
// // commandLineArgsString = string.Join(
|
||||
// // ' ',
|
||||
// // Environment.GetCommandLineArgs().Skip(1).Select(NormalizeCommandLineArgument));
|
||||
// // }
|
||||
//
|
||||
// //_logger.LogInformation("Executable: {0}", module);
|
||||
// //_logger.LogInformation("Arguments: {0}", commandLineArgsString);
|
||||
//
|
||||
// Process.Start(module, Array.Empty<string>);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
@ -129,6 +129,7 @@ namespace API.Services
|
||||
try {
|
||||
// TODO: In future, we need to take LibraryType into consideration for what extensions to allow (RAW should allow images)
|
||||
// or we need to move this filtering to another area (Process)
|
||||
// or we can get all files and put a check in place during Process to abandon files
|
||||
files = GetFilesWithCertainExtensions(currentDir, Parser.Parser.MangaFileExtensions)
|
||||
.ToArray();
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using API.Entities;
|
||||
using API.Entities.Enums;
|
||||
using API.Interfaces;
|
||||
using API.Parser;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
@ -1,5 +1,5 @@
|
||||
using System.Threading.Tasks;
|
||||
using API.Entities;
|
||||
using API.Entities.Enums;
|
||||
using API.Helpers.Converters;
|
||||
using API.Interfaces;
|
||||
using Hangfire;
|
||||
|
Loading…
x
Reference in New Issue
Block a user