mirror of
https://github.com/C9Glax/tranga.git
synced 2025-02-22 23:30:13 +01:00
PGSqlContext add MangaConnector Discriminator
API use Newtonsoft Json,
This commit is contained in:
parent
a0774841bc
commit
0d32f15ee9
@ -4,7 +4,6 @@ using API;
|
|||||||
using API.Schema;
|
using API.Schema;
|
||||||
using API.Schema.Jobs;
|
using API.Schema.Jobs;
|
||||||
using API.Schema.MangaConnectors;
|
using API.Schema.MangaConnectors;
|
||||||
using API.Schema.NotificationConnectors;
|
|
||||||
using Asp.Versioning;
|
using Asp.Versioning;
|
||||||
using Asp.Versioning.Builder;
|
using Asp.Versioning.Builder;
|
||||||
using Asp.Versioning.Conventions;
|
using Asp.Versioning.Conventions;
|
||||||
@ -59,14 +58,15 @@ builder.Services.AddSwaggerGen(opt =>
|
|||||||
});
|
});
|
||||||
builder.Services.ConfigureOptions<NamedSwaggerGenOptions>();
|
builder.Services.ConfigureOptions<NamedSwaggerGenOptions>();
|
||||||
|
|
||||||
|
|
||||||
builder.Services.AddDbContext<PgsqlContext>(options =>
|
builder.Services.AddDbContext<PgsqlContext>(options =>
|
||||||
options.UseNpgsql($"Host={Environment.GetEnvironmentVariable("POSTGRES_Host")??"localhost:5432"}; " +
|
options.UseNpgsql($"Host={Environment.GetEnvironmentVariable("POSTGRES_HOST")??"localhost:5432"}; " +
|
||||||
$"Database={Environment.GetEnvironmentVariable("POSTGRES_DB")??"postgres"}; " +
|
$"Database={Environment.GetEnvironmentVariable("POSTGRES_DB")??"postgres"}; " +
|
||||||
$"Username={Environment.GetEnvironmentVariable("POSTGRES_USER")??"postgres"}; " +
|
$"Username={Environment.GetEnvironmentVariable("POSTGRES_USER")??"postgres"}; " +
|
||||||
$"Password={Environment.GetEnvironmentVariable("POSTGRES_PASSWORD")??"postgres"}"));
|
$"Password={Environment.GetEnvironmentVariable("POSTGRES_PASSWORD")??"postgres"}"));
|
||||||
|
|
||||||
builder.Services.AddControllers();
|
builder.Services.AddControllers().AddNewtonsoftJson();
|
||||||
|
|
||||||
|
builder.WebHost.UseUrls("http://*:6531");
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
@ -91,6 +91,12 @@ app.UseSwaggerUI(options =>
|
|||||||
|
|
||||||
app.UseHttpsRedirection();
|
app.UseHttpsRedirection();
|
||||||
|
|
||||||
|
using (var scope = app.Services.CreateScope())
|
||||||
|
{
|
||||||
|
var db = scope.ServiceProvider.GetRequiredService<PgsqlContext>();
|
||||||
|
db.Database.Migrate();
|
||||||
|
}
|
||||||
|
|
||||||
using (var scope = app.Services.CreateScope())
|
using (var scope = app.Services.CreateScope())
|
||||||
{
|
{
|
||||||
PgsqlContext context = scope.ServiceProvider.GetService<PgsqlContext>()!;
|
PgsqlContext context = scope.ServiceProvider.GetService<PgsqlContext>()!;
|
||||||
@ -109,7 +115,7 @@ using (var scope = app.Services.CreateScope())
|
|||||||
new ManhuaPlus(),
|
new ManhuaPlus(),
|
||||||
new Weebcentral()
|
new Weebcentral()
|
||||||
];
|
];
|
||||||
MangaConnector[] newConnectors = context.MangaConnectors.Where(c => !connectors.Contains(c)).ToArray();
|
MangaConnector[] newConnectors = connectors.Where(c => !context.MangaConnectors.Contains(c)).ToArray();
|
||||||
context.MangaConnectors.AddRange(newConnectors);
|
context.MangaConnectors.AddRange(newConnectors);
|
||||||
|
|
||||||
context.Jobs.RemoveRange(context.Jobs.Where(j => j.state == JobState.Completed && j.RecurrenceMs < 1));
|
context.Jobs.RemoveRange(context.Jobs.Where(j => j.state == JobState.Completed && j.RecurrenceMs < 1));
|
||||||
@ -119,7 +125,6 @@ using (var scope = app.Services.CreateScope())
|
|||||||
|
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
|
|
||||||
|
|
||||||
string TRANGA = "\n\n _______ \n|_ _|.----..---.-..-----..-----..---.-.\n | | | _|| _ || || _ || _ |\n |___| |__| |___._||__|__||___ ||___._|\n |_____| \n\n";
|
string TRANGA = "\n\n _______ \n|_ _|.----..---.-..-----..-----..---.-.\n | | | _|| _ || || _ || _ |\n |___| |__| |___._||__|__||___ ||___._|\n |_____| \n\n";
|
||||||
ILog Log = LogManager.GetLogger("Tranga");
|
ILog Log = LogManager.GetLogger("Tranga");
|
||||||
BasicConfigurator.Configure();
|
BasicConfigurator.Configure();
|
||||||
|
@ -14,6 +14,7 @@ public abstract class MangaConnector(string name, string[] supportedLanguages, s
|
|||||||
public string[] SupportedLanguages { get; init; } = supportedLanguages;
|
public string[] SupportedLanguages { get; init; } = supportedLanguages;
|
||||||
public string[] BaseUris { get; init; } = baseUris;
|
public string[] BaseUris { get; init; } = baseUris;
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
[ForeignKey("MangaIds")]
|
[ForeignKey("MangaIds")]
|
||||||
public virtual Manga[] Mangas { get; internal set; } = [];
|
public virtual Manga[] Mangas { get; internal set; } = [];
|
||||||
|
|
||||||
|
@ -22,6 +22,19 @@ public class PgsqlContext(DbContextOptions<PgsqlContext> options) : DbContext(op
|
|||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
|
modelBuilder.Entity<MangaConnector>()
|
||||||
|
.HasDiscriminator(c => c.Name)
|
||||||
|
.HasValue<AsuraToon>("AsuraToon")
|
||||||
|
.HasValue<Bato>("Bato")
|
||||||
|
.HasValue<MangaHere>("MangaHere")
|
||||||
|
.HasValue<MangaKatana>("MangaKatana")
|
||||||
|
.HasValue<MangaLife>("Manga4Life")
|
||||||
|
.HasValue<Manganato>("Manganato")
|
||||||
|
.HasValue<Mangasee>("Mangasee")
|
||||||
|
.HasValue<Mangaworld>("Mangaworld")
|
||||||
|
.HasValue<ManhuaPlus>("ManhuaPlus")
|
||||||
|
.HasValue<Weebcentral>("Weebcentral")
|
||||||
|
.HasValue<MangaDex>("MangaDex");
|
||||||
modelBuilder.Entity<LibraryConnector>()
|
modelBuilder.Entity<LibraryConnector>()
|
||||||
.HasDiscriminator<LibraryType>(l => l.LibraryType)
|
.HasDiscriminator<LibraryType>(l => l.LibraryType)
|
||||||
.HasValue<Komga>(LibraryType.Komga)
|
.HasValue<Komga>(LibraryType.Komga)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user