mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-05-24 00:52:23 -04:00
* Stashing code * removed some debug code on series detail page. Now detail is collapsed by default. * Added AgeRating * Fixed a crash when NetVips tries to write a cover file and cover directory is not existing. * When a card is selected for bulk actions, show an outline in addition to select box * Added AgeRating into the metadata parsing. Added a hack where ComicInfo uses Number in ComicInfo rather than Volume. This is to test out the effects on users libraries. * Added AgeRating and ReleaseDate to the metadata implelentation.
135 lines
4.8 KiB
C#
135 lines
4.8 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.IO.Abstractions;
|
|
using System.Security.Cryptography;
|
|
using System.Threading.Tasks;
|
|
using API.Data;
|
|
using API.Entities;
|
|
using API.Services;
|
|
using Kavita.Common;
|
|
using Kavita.Common.EnvironmentInfo;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.AspNetCore.Identity;
|
|
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace API
|
|
{
|
|
public class Program
|
|
{
|
|
private static readonly int HttpPort = Configuration.Port;
|
|
|
|
protected Program()
|
|
{
|
|
}
|
|
|
|
public static async Task Main(string[] args)
|
|
{
|
|
Console.OutputEncoding = System.Text.Encoding.UTF8;
|
|
var isDocker = new OsInfo(Array.Empty<IOsVersionAdapter>()).IsDocker;
|
|
|
|
|
|
// TODO: Figure out a solution for this migration and logger.
|
|
var directoryService = new DirectoryService(null, new FileSystem());
|
|
MigrateConfigFiles.Migrate(isDocker, directoryService);
|
|
|
|
// Before anything, check if JWT has been generated properly or if user still has default
|
|
if (!Configuration.CheckIfJwtTokenSet() &&
|
|
Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") != Environments.Development)
|
|
{
|
|
Console.WriteLine("Generating JWT TokenKey for encrypting user sessions...");
|
|
var rBytes = new byte[128];
|
|
RandomNumberGenerator.Create().GetBytes(rBytes);
|
|
Configuration.JwtToken = Convert.ToBase64String(rBytes).Replace("/", string.Empty);
|
|
}
|
|
|
|
var host = CreateHostBuilder(args).Build();
|
|
|
|
using var scope = host.Services.CreateScope();
|
|
var services = scope.ServiceProvider;
|
|
|
|
try
|
|
{
|
|
var context = services.GetRequiredService<DataContext>();
|
|
var roleManager = services.GetRequiredService<RoleManager<AppRole>>();
|
|
|
|
if (isDocker && new FileInfo("data/appsettings.json").Exists)
|
|
{
|
|
var logger = services.GetRequiredService<ILogger<Startup>>();
|
|
logger.LogCritical("WARNING! Mount point is incorrect, nothing here will persist. Please change your container mount from /kavita/data to /kavita/config");
|
|
return;
|
|
}
|
|
|
|
// This doesn't work either
|
|
//var directoryService = services.GetRequiredService<DirectoryService>();
|
|
|
|
|
|
|
|
|
|
var requiresCoverImageMigration = !Directory.Exists(directoryService.CoverImageDirectory);
|
|
try
|
|
{
|
|
// If this is a new install, tables wont exist yet
|
|
if (requiresCoverImageMigration)
|
|
{
|
|
MigrateCoverImages.ExtractToImages(context, directoryService, services.GetRequiredService<ImageService>());
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
requiresCoverImageMigration = false;
|
|
}
|
|
|
|
// Apply all migrations on startup
|
|
await context.Database.MigrateAsync();
|
|
|
|
if (requiresCoverImageMigration)
|
|
{
|
|
await MigrateCoverImages.UpdateDatabaseWithImages(context, directoryService);
|
|
}
|
|
|
|
await Seed.SeedRoles(roleManager);
|
|
await Seed.SeedSettings(context, directoryService);
|
|
await Seed.SeedUserApiKeys(context);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
var logger = services.GetRequiredService<ILogger<Program>>();
|
|
logger.LogError(ex, "An error occurred during migration");
|
|
}
|
|
|
|
await host.RunAsync();
|
|
}
|
|
|
|
private static IHostBuilder CreateHostBuilder(string[] args) =>
|
|
Host.CreateDefaultBuilder(args)
|
|
.ConfigureAppConfiguration((hostingContext, config) =>
|
|
{
|
|
config.Sources.Clear();
|
|
|
|
var env = hostingContext.HostingEnvironment;
|
|
|
|
config.AddJsonFile("config/appsettings.json", optional: true, reloadOnChange: false)
|
|
.AddJsonFile($"config/appsettings.{env.EnvironmentName}.json",
|
|
optional: true, reloadOnChange: false);
|
|
})
|
|
.ConfigureWebHostDefaults(webBuilder =>
|
|
{
|
|
webBuilder.UseKestrel((opts) =>
|
|
{
|
|
opts.ListenAnyIP(HttpPort, options => { options.Protocols = HttpProtocols.Http1AndHttp2; });
|
|
});
|
|
|
|
webBuilder.UseStartup<Startup>();
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|