mirror of
https://github.com/SoPat712/allstarr.git
synced 2026-02-09 23:55:10 -05:00
72 lines
2.0 KiB
C#
72 lines
2.0 KiB
C#
using octo_fiesta.Models;
|
|
using octo_fiesta.Services;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
// Add services to the container.
|
|
|
|
builder.Services.AddControllers();
|
|
builder.Services.AddHttpClient();
|
|
builder.Services.AddEndpointsApiExplorer();
|
|
builder.Services.AddSwaggerGen();
|
|
|
|
// Configuration
|
|
builder.Services.Configure<SubsonicSettings>(
|
|
builder.Configuration.GetSection("Subsonic"));
|
|
builder.Services.Configure<QobuzSettings>(
|
|
builder.Configuration.GetSection("Qobuz"));
|
|
|
|
// Get the configured music service
|
|
var musicService = builder.Configuration.GetValue<MusicService>("Subsonic:MusicService");
|
|
|
|
// Business services
|
|
// Registered as Singleton to share state (mappings cache, scan debounce, download tracking, rate limiting)
|
|
builder.Services.AddSingleton<ILocalLibraryService, LocalLibraryService>();
|
|
|
|
// Register music service based on configuration
|
|
if (musicService == MusicService.Qobuz)
|
|
{
|
|
// Qobuz services
|
|
builder.Services.AddSingleton<QobuzBundleService>();
|
|
builder.Services.AddSingleton<IMusicMetadataService, QobuzMetadataService>();
|
|
builder.Services.AddSingleton<IDownloadService, QobuzDownloadService>();
|
|
}
|
|
else
|
|
{
|
|
// Deezer services (default)
|
|
builder.Services.AddSingleton<IMusicMetadataService, DeezerMetadataService>();
|
|
builder.Services.AddSingleton<IDownloadService, DeezerDownloadService>();
|
|
}
|
|
|
|
// Startup validation - runs at application startup to validate configuration
|
|
builder.Services.AddHostedService<StartupValidationService>();
|
|
|
|
builder.Services.AddCors(options =>
|
|
{
|
|
options.AddDefaultPolicy(policy =>
|
|
{
|
|
policy.AllowAnyOrigin()
|
|
.AllowAnyMethod()
|
|
.AllowAnyHeader()
|
|
.WithExposedHeaders("X-Content-Duration", "X-Total-Count", "X-Nd-Authorization");
|
|
});
|
|
});
|
|
|
|
var app = builder.Build();
|
|
|
|
// Configure the HTTP request pipeline.
|
|
if (app.Environment.IsDevelopment())
|
|
{
|
|
app.UseSwagger();
|
|
app.UseSwaggerUI();
|
|
}
|
|
|
|
app.UseHttpsRedirection();
|
|
|
|
app.UseAuthorization();
|
|
|
|
app.UseCors();
|
|
|
|
app.MapControllers();
|
|
|
|
app.Run(); |