mirror of
https://github.com/spacebarchat/server.git
synced 2026-03-30 20:25:40 +00:00
60 lines
1.8 KiB
C#
60 lines
1.8 KiB
C#
using System.Buffers.Text;
|
|
using ArcaneLibs;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Spacebar.Cdn.Fsck;
|
|
using Spacebar.Interop.Cdn.Abstractions;
|
|
using Spacebar.Interop.Cdn.Signing;
|
|
using Spacebar.Models.Db.Contexts;
|
|
|
|
var builder = Host.CreateApplicationBuilder(args);
|
|
if (!string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("APPSETTINGS_PATH")))
|
|
builder.Configuration.AddJsonFile(Environment.GetEnvironmentVariable("APPSETTINGS_PATH")!);
|
|
|
|
// builder.Services.AddSingleton<IFileSource>(new ProxyFileSource("http://cdn.old.server.spacebar.chat"));
|
|
IFileSource fromSrc, toSrc;
|
|
|
|
if (args.Length != 2) {
|
|
Console.WriteLine("Usage: Spacebar.Cdn.Migration <from-path> <to-path>");
|
|
return;
|
|
}
|
|
|
|
if (args[0].StartsWith("http://"))
|
|
fromSrc = new ProxyFileSource(args[0]);
|
|
else
|
|
fromSrc = new FilesystemFileSource(args[0]);
|
|
|
|
if (args[1].StartsWith("http://"))
|
|
toSrc = new ProxyFileSource(args[1]);
|
|
else
|
|
toSrc = new FilesystemFileSource(args[1]);
|
|
|
|
builder.Services.AddSingleton(new MigrationFileStores() {
|
|
From = fromSrc,
|
|
To = toSrc
|
|
});
|
|
|
|
builder.Services.AddSingleton<CdnSigningService>(sp =>
|
|
new CdnSigningService(
|
|
sp.GetRequiredService<ILogger<CdnSigningService>>(),
|
|
Convert.FromBase64String(""),
|
|
false,
|
|
true,
|
|
TimeSpan.FromMinutes(5)
|
|
)
|
|
);
|
|
builder.Services.AddHostedService<FsckService>();
|
|
|
|
builder.Services.AddDbContextPool<SpacebarDbContext>(options => {
|
|
options
|
|
.UseNpgsql(builder.Configuration.GetConnectionString("Spacebar"))
|
|
.EnableDetailedErrors();
|
|
});
|
|
|
|
StreamingHttpClient.LogRequests = false;
|
|
|
|
var host = builder.Build();
|
|
|
|
await host.Services.GetRequiredService<MigrationFileStores>().From.Init();
|
|
await host.Services.GetRequiredService<MigrationFileStores>().To.Init();
|
|
|
|
host.Start(); |