2020-05-13 21:52:34 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Diagnostics;
|
2020-05-09 03:56:06 +00:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Microsoft.AspNetCore.Builder;
|
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
|
|
|
|
using Microsoft.AspNetCore.Http.Features;
|
2021-02-17 05:46:05 +00:00
|
|
|
|
using Microsoft.AspNetCore.ResponseCompression;
|
2020-05-09 03:56:06 +00:00
|
|
|
|
using Microsoft.AspNetCore.StaticFiles;
|
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Microsoft.Extensions.FileProviders;
|
|
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using Wabbajack.BuildServer;
|
2020-12-30 03:59:22 +00:00
|
|
|
|
using Wabbajack.Lib.LibCefHelpers;
|
2020-05-09 03:56:06 +00:00
|
|
|
|
using Wabbajack.Server.DataLayer;
|
|
|
|
|
using Wabbajack.Server.Services;
|
|
|
|
|
|
|
|
|
|
namespace Wabbajack.Server
|
|
|
|
|
{
|
|
|
|
|
public class TestStartup : Startup
|
|
|
|
|
{
|
|
|
|
|
public TestStartup(IConfiguration configuration) : base(configuration)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public class Startup
|
|
|
|
|
{
|
|
|
|
|
public Startup(IConfiguration configuration)
|
|
|
|
|
{
|
|
|
|
|
Configuration = configuration;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IConfiguration Configuration { get; }
|
|
|
|
|
|
|
|
|
|
// This method gets called by the runtime. Use this method to add services to the container.
|
|
|
|
|
public void ConfigureServices(IServiceCollection services)
|
|
|
|
|
{
|
2020-12-30 03:59:22 +00:00
|
|
|
|
Helpers.Init();
|
2020-07-08 20:48:48 +00:00
|
|
|
|
/*services.AddSwaggerGen(c =>
|
2020-05-09 03:56:06 +00:00
|
|
|
|
{
|
|
|
|
|
c.SwaggerDoc("v1", new OpenApiInfo {Title = "Wabbajack Build API", Version = "v1"});
|
2020-07-08 20:48:48 +00:00
|
|
|
|
});*/
|
2020-05-09 03:56:06 +00:00
|
|
|
|
|
2020-05-09 22:16:16 +00:00
|
|
|
|
services.AddAuthentication(options =>
|
|
|
|
|
{
|
|
|
|
|
options.DefaultAuthenticateScheme = ApiKeyAuthenticationOptions.DefaultScheme;
|
|
|
|
|
options.DefaultChallengeScheme = ApiKeyAuthenticationOptions.DefaultScheme;
|
|
|
|
|
})
|
|
|
|
|
.AddApiKeySupport(options => {});
|
|
|
|
|
|
2020-05-09 03:56:06 +00:00
|
|
|
|
services.Configure<FormOptions>(x =>
|
|
|
|
|
{
|
|
|
|
|
x.ValueLengthLimit = int.MaxValue;
|
|
|
|
|
x.MultipartBodyLengthLimit = int.MaxValue;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
services.AddSingleton<AppSettings>();
|
2020-06-06 21:44:30 +00:00
|
|
|
|
services.AddSingleton<QuickSync>();
|
2020-05-09 03:56:06 +00:00
|
|
|
|
services.AddSingleton<SqlService>();
|
|
|
|
|
services.AddSingleton<GlobalInformation>();
|
2020-05-13 03:04:32 +00:00
|
|
|
|
services.AddSingleton<NexusPoll>();
|
|
|
|
|
services.AddSingleton<ArchiveMaintainer>();
|
2020-05-13 03:39:03 +00:00
|
|
|
|
services.AddSingleton<ModListDownloader>();
|
2020-05-13 21:52:34 +00:00
|
|
|
|
services.AddSingleton<NonNexusDownloadValidator>();
|
|
|
|
|
services.AddSingleton<ListValidator>();
|
2020-05-14 04:08:27 +00:00
|
|
|
|
services.AddSingleton<ArchiveDownloader>();
|
2020-05-15 05:25:02 +00:00
|
|
|
|
services.AddSingleton<DiscordWebHook>();
|
2020-05-16 15:08:40 +00:00
|
|
|
|
services.AddSingleton<NexusKeyMaintainance>();
|
2020-05-20 03:25:41 +00:00
|
|
|
|
services.AddSingleton<PatchBuilder>();
|
2020-07-20 03:45:55 +00:00
|
|
|
|
services.AddSingleton<CDNMirrorList>();
|
2020-07-25 18:09:02 +00:00
|
|
|
|
services.AddSingleton<NexusPermissionsUpdater>();
|
2020-08-05 00:34:09 +00:00
|
|
|
|
services.AddSingleton<MirrorUploader>();
|
2020-11-02 00:30:49 +00:00
|
|
|
|
services.AddSingleton<MirrorQueueService>();
|
2020-11-19 22:56:30 +00:00
|
|
|
|
services.AddSingleton<Watchdog>();
|
2020-11-24 17:19:26 +00:00
|
|
|
|
services.AddSingleton<DiscordFrontend>();
|
2021-02-06 16:43:11 +00:00
|
|
|
|
services.AddSingleton<AuthoredFilesCleanup>();
|
2021-02-18 05:44:54 +00:00
|
|
|
|
services.AddSingleton<MetricsKeyCache>();
|
2021-02-17 05:46:05 +00:00
|
|
|
|
services.AddResponseCompression(options =>
|
|
|
|
|
{
|
|
|
|
|
options.Providers.Add<BrotliCompressionProvider>();
|
|
|
|
|
options.Providers.Add<GzipCompressionProvider>();
|
2021-02-23 04:38:28 +00:00
|
|
|
|
options.MimeTypes = new[] {"application/json"};
|
2021-02-17 05:46:05 +00:00
|
|
|
|
});
|
2020-05-13 21:52:34 +00:00
|
|
|
|
|
2020-05-09 03:56:06 +00:00
|
|
|
|
services.AddMvc();
|
|
|
|
|
services.AddControllers()
|
|
|
|
|
.AddNewtonsoftJson(o =>
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
o.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
|
|
|
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
|
|
|
|
{
|
|
|
|
|
if (env.IsDevelopment())
|
|
|
|
|
{
|
|
|
|
|
app.UseDeveloperExceptionPage();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!(this is TestStartup))
|
|
|
|
|
app.UseHttpsRedirection();
|
|
|
|
|
|
|
|
|
|
app.UseDeveloperExceptionPage();
|
|
|
|
|
|
|
|
|
|
var provider = new FileExtensionContentTypeProvider();
|
|
|
|
|
provider.Mappings[".rar"] = "application/x-rar-compressed";
|
|
|
|
|
provider.Mappings[".7z"] = "application/x-7z-compressed";
|
|
|
|
|
provider.Mappings[".zip"] = "application/zip";
|
|
|
|
|
provider.Mappings[".wabbajack"] = "application/zip";
|
|
|
|
|
app.UseStaticFiles();
|
|
|
|
|
|
2020-07-08 20:48:48 +00:00
|
|
|
|
/*
|
2020-05-09 03:56:06 +00:00
|
|
|
|
app.UseSwagger();
|
|
|
|
|
app.UseSwaggerUI(c =>
|
|
|
|
|
{
|
|
|
|
|
c.SwaggerEndpoint("/swagger/v1/swagger.json", "Wabbajack Build API");
|
|
|
|
|
c.RoutePrefix = string.Empty;
|
2020-07-08 20:48:48 +00:00
|
|
|
|
}); */
|
|
|
|
|
|
2020-05-09 03:56:06 +00:00
|
|
|
|
app.UseRouting();
|
|
|
|
|
|
|
|
|
|
app.UseAuthentication();
|
|
|
|
|
app.UseAuthorization();
|
|
|
|
|
app.UseNexusPoll();
|
2020-05-13 03:39:03 +00:00
|
|
|
|
app.UseArchiveMaintainer();
|
|
|
|
|
app.UseModListDownloader();
|
2021-02-17 05:46:05 +00:00
|
|
|
|
app.UseResponseCompression();
|
2020-05-13 21:52:34 +00:00
|
|
|
|
|
|
|
|
|
app.UseService<NonNexusDownloadValidator>();
|
|
|
|
|
app.UseService<ListValidator>();
|
2020-05-14 04:08:27 +00:00
|
|
|
|
app.UseService<ArchiveDownloader>();
|
2020-05-15 05:25:02 +00:00
|
|
|
|
app.UseService<DiscordWebHook>();
|
2020-05-16 15:08:40 +00:00
|
|
|
|
app.UseService<NexusKeyMaintainance>();
|
2020-05-20 03:25:41 +00:00
|
|
|
|
app.UseService<PatchBuilder>();
|
2020-07-20 03:45:55 +00:00
|
|
|
|
app.UseService<CDNMirrorList>();
|
2020-07-25 18:09:02 +00:00
|
|
|
|
app.UseService<NexusPermissionsUpdater>();
|
2020-08-05 00:34:09 +00:00
|
|
|
|
app.UseService<MirrorUploader>();
|
2021-03-11 02:28:28 +00:00
|
|
|
|
//app.UseService<MirrorQueueService>();
|
2020-11-19 22:56:30 +00:00
|
|
|
|
app.UseService<Watchdog>();
|
2020-11-24 17:19:26 +00:00
|
|
|
|
app.UseService<DiscordFrontend>();
|
2021-04-11 22:04:12 +00:00
|
|
|
|
// Don't enable Author Files Cleanup
|
2021-03-04 12:50:40 +00:00
|
|
|
|
//app.UseService<AuthoredFilesCleanup>();
|
2021-02-18 05:44:54 +00:00
|
|
|
|
app.UseService<MetricsKeyCache>();
|
2020-05-09 03:56:06 +00:00
|
|
|
|
|
|
|
|
|
app.Use(next =>
|
|
|
|
|
{
|
|
|
|
|
return async context =>
|
|
|
|
|
{
|
|
|
|
|
var stopWatch = new Stopwatch();
|
|
|
|
|
stopWatch.Start();
|
|
|
|
|
context.Response.OnStarting(() =>
|
|
|
|
|
{
|
|
|
|
|
stopWatch.Stop();
|
|
|
|
|
var headers = context.Response.Headers;
|
|
|
|
|
headers.Add("Access-Control-Allow-Origin", "*");
|
|
|
|
|
headers.Add("Access-Control-Allow-Methods", "POST, GET");
|
|
|
|
|
headers.Add("Access-Control-Allow-Headers", "Accept, Origin, Content-type");
|
|
|
|
|
headers.Add("X-ResponseTime-Ms", stopWatch.ElapsedMilliseconds.ToString());
|
2020-08-26 04:03:43 +00:00
|
|
|
|
if (!headers.ContainsKey("Cache-Control"))
|
|
|
|
|
headers.Add("Cache-Control", "no-cache");
|
2020-05-09 03:56:06 +00:00
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
});
|
|
|
|
|
await next(context);
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
app.UseFileServer(new FileServerOptions
|
|
|
|
|
{
|
|
|
|
|
FileProvider = new PhysicalFileProvider(
|
|
|
|
|
Path.Combine(Directory.GetCurrentDirectory(), "public")),
|
|
|
|
|
StaticFileOptions = {ServeUnknownFileTypes = true},
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
app.UseEndpoints(endpoints =>
|
|
|
|
|
{
|
|
|
|
|
endpoints.MapControllers();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|