Some changes and missing classes on last commit
- Program.cs updated to services and init database
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CoenM.ImageSharp.ImageHash" Version="1.3.6" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="10.0.7" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="10.0.7" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="10.0.7">
|
||||
@@ -28,13 +29,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Controllers\" />
|
||||
<Folder Include="Entities\CardMarket\" />
|
||||
<Folder Include="Entities\Cards\" />
|
||||
<Folder Include="Entities\Collection\" />
|
||||
<Folder Include="Entities\TCGdex\" />
|
||||
<Folder Include="Entities\User\" />
|
||||
<Folder Include="Models\" />
|
||||
<Folder Include="Controllers\V1\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
+49
-3
@@ -1,21 +1,67 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using OakArchive.Database;
|
||||
using OakArchive.Services;
|
||||
|
||||
namespace OakArchive;
|
||||
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
public static async Task Main(string[] args)
|
||||
{
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
|
||||
builder.Services.AddControllers();
|
||||
|
||||
builder.Services.AddDbContext<ApplicationDbContext>(options =>
|
||||
options.UseNpgsql(builder.Configuration["DefaultConnection"]));
|
||||
|
||||
|
||||
builder.Services.AddMemoryCache(); // Registriert das native IMemoryCache von Microsoft
|
||||
builder.Services.AddSingleton<IMemoryCacheService, MemoryCacheService>();
|
||||
|
||||
builder.Services.AddHttpClient<ITcgDexService, TcgDexService>(client =>
|
||||
{
|
||||
client.BaseAddress = new Uri("https://api.tcgdex.net/v2/");
|
||||
client.DefaultRequestHeaders.Add("Accept", "application/json");
|
||||
});
|
||||
|
||||
builder.Services.AddScoped<ITcgDexDataUpdater, TcgDexDataUpdater>();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
app.Lifetime.ApplicationStarted.Register(async () =>
|
||||
{
|
||||
// Da ApplicationStarted synchron registriert, machen wir hier einen neuen asynchronen Scope auf
|
||||
using var scope = app.Services.CreateScope();
|
||||
try
|
||||
{
|
||||
var context = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
|
||||
|
||||
Console.WriteLine("[INFO] Prüfe auf ausstehende Datenbank-Migrationen...");
|
||||
|
||||
// Führt alle ausstehenden Migrationen auf der PostgreSQL-Datenbank aus.
|
||||
// Falls die Datenbank noch gar nicht existiert, wird sie hier automatisch erstellt!
|
||||
await context.Database.MigrateAsync();
|
||||
|
||||
var updater = scope.ServiceProvider.GetRequiredService<ITcgDexDataUpdater>();
|
||||
|
||||
Console.WriteLine("[INFO] === Starte TCGdex Test-Sync im Hintergrund ===");
|
||||
|
||||
var result = await updater.SyncBaseDataFromTcgDex();
|
||||
|
||||
Console.WriteLine($"[INFO] === Test-Sync beendet! Neue Daten geladen: {result} ===");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"[FEHLER] !!! Fehler beim Test-Sync: {ex.Message} !!!");
|
||||
Console.WriteLine(ex.StackTrace);
|
||||
}
|
||||
});
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
app.UseStaticFiles();
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
using CoenM.ImageHash.HashAlgorithms;
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.PixelFormats;
|
||||
using SixLabors.ImageSharp.Processing;
|
||||
|
||||
namespace OakArchive.Util;
|
||||
|
||||
public class PerceptualHashHelper
|
||||
{
|
||||
private static readonly PerceptualHash _perceptualHash = new();
|
||||
|
||||
private const int TargetWidth = 600;
|
||||
private const int TargetHeight = 840;
|
||||
private const int Margin = 15;
|
||||
|
||||
public static ulong GenerateHash(byte[] rawImage)
|
||||
{
|
||||
using var image = Image.Load<Rgba32>(rawImage);
|
||||
|
||||
image.Mutate(x => x.Resize(TargetWidth, TargetHeight));
|
||||
|
||||
return _perceptualHash.Hash(image);
|
||||
}
|
||||
|
||||
public static ulong GenerateHashWithMargin(byte[] rawImage)
|
||||
{
|
||||
using var image = Image.Load<Rgba32>(rawImage);
|
||||
|
||||
const int maxContentWidth = TargetWidth - (2 * Margin);
|
||||
const int maxContentHeight = TargetHeight - (2 * Margin);
|
||||
|
||||
image.Mutate(x => x.Resize(new ResizeOptions
|
||||
{
|
||||
Size = new Size(maxContentWidth, maxContentHeight),
|
||||
Mode = ResizeMode.Max
|
||||
}));
|
||||
|
||||
using var canvas = new Image<Rgba32>(TargetWidth, TargetHeight, Color.Black);
|
||||
|
||||
var posX = (TargetWidth - image.Width) / 2;
|
||||
var posY = (TargetHeight - image.Height) / 2;
|
||||
|
||||
canvas.Mutate(x => x.DrawImage(image, new Point(posX, posY), 1f));
|
||||
|
||||
return _perceptualHash.Hash(canvas);
|
||||
}
|
||||
}
|
||||
+3
-4
@@ -4,13 +4,12 @@
|
||||
build:
|
||||
context: .
|
||||
dockerfile: OakArchive/Dockerfile
|
||||
# Falls die DB in einer anderen Datei ist, nimm depends_on raus,
|
||||
# da Compose nur Services innerhalb derselben Datei überwachen kann.
|
||||
networks:
|
||||
- postgres-network
|
||||
environment:
|
||||
# WICHTIG: Host muss der 'container_name' oder 'service_name' der DB sein
|
||||
- CONNECTION_STRING=Host=OmniDB;Database=oak_db;Username=admin;Password=${DB_PASSWORD}
|
||||
- DefaultConnection=Host=OmniDB;Database=oak_db;Username=admin;Password=${DB_PASSWORD}
|
||||
volumes:
|
||||
- C:\Users\larsh\Documents\docker\oakarchive\Cards:/app/Cards
|
||||
|
||||
networks:
|
||||
postgres-network:
|
||||
|
||||
Reference in New Issue
Block a user