From 4a0117906a917ee9d710a02fbc493801a9c6516f Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sun, 27 Jul 2025 14:25:45 +0800 Subject: [PATCH] :bug: Trying to fix upload offset not found in frontend --- DysonNetwork.Drive/Client/src/views/index.vue | 1 + DysonNetwork.Drive/Program.cs | 2 +- .../Startup/ApplicationBuilderExtensions.cs | 9 +++++++++ DysonNetwork.Drive/Storage/TusService.cs | 3 +++ DysonNetwork.Gateway/Program.cs | 10 +++++++++- .../Startup/ApplicationConfiguration.cs | 2 +- .../Startup/ApplicationConfiguration.cs | 2 +- .../Http/KestrelConfiguration.cs | 19 ++++++++++--------- 8 files changed, 35 insertions(+), 13 deletions(-) diff --git a/DysonNetwork.Drive/Client/src/views/index.vue b/DysonNetwork.Drive/Client/src/views/index.vue index 566ad5c..88d4cbe 100644 --- a/DysonNetwork.Drive/Client/src/views/index.vue +++ b/DysonNetwork.Drive/Client/src/views/index.vue @@ -174,6 +174,7 @@ function customRequest({ 'content-type': file.type ?? 'application/octet-stream', }, headers: { + 'X-DirectUpload': 'true', ...requestHeaders, ...headers, }, diff --git a/DysonNetwork.Drive/Program.cs b/DysonNetwork.Drive/Program.cs index 79d30a3..344ab0e 100644 --- a/DysonNetwork.Drive/Program.cs +++ b/DysonNetwork.Drive/Program.cs @@ -11,7 +11,7 @@ using tusdotnet.Stores; var builder = WebApplication.CreateBuilder(args); // Configure Kestrel and server options -builder.ConfigureAppKestrel(builder.Configuration); +builder.ConfigureAppKestrel(builder.Configuration, maxRequestBodySize: long.MaxValue); // Add application services builder.Services.AddRegistryService(builder.Configuration); diff --git a/DysonNetwork.Drive/Startup/ApplicationBuilderExtensions.cs b/DysonNetwork.Drive/Startup/ApplicationBuilderExtensions.cs index 9d85778..a325430 100644 --- a/DysonNetwork.Drive/Startup/ApplicationBuilderExtensions.cs +++ b/DysonNetwork.Drive/Startup/ApplicationBuilderExtensions.cs @@ -19,6 +19,15 @@ public static class ApplicationBuilderExtensions app.UseAuthorization(); app.MapControllers(); + app.UseCors(opts => + opts.SetIsOriginAllowed(_ => true) + .WithExposedHeaders("*") + .WithHeaders("*") + .AllowCredentials() + .AllowAnyHeader() + .AllowAnyMethod() + ); + app.UseDefaultFiles(); app.UseStaticFiles(new StaticFileOptions { diff --git a/DysonNetwork.Drive/Storage/TusService.cs b/DysonNetwork.Drive/Storage/TusService.cs index 157b323..ae46f10 100644 --- a/DysonNetwork.Drive/Storage/TusService.cs +++ b/DysonNetwork.Drive/Storage/TusService.cs @@ -228,6 +228,9 @@ public abstract class TusService }, OnCreateCompleteAsync = eventContext => { + var directUpload = eventContext.HttpContext.Request.Headers["X-DirectUpload"].FirstOrDefault(); + if (!string.IsNullOrEmpty(directUpload)) return Task.CompletedTask; + var gatewayUrl = configuration["GatewayUrl"]; if (gatewayUrl is not null) eventContext.SetUploadUrl(new Uri(gatewayUrl + "/drive/tus/" + eventContext.FileId)); diff --git a/DysonNetwork.Gateway/Program.cs b/DysonNetwork.Gateway/Program.cs index 71f5b9f..a7fc70b 100644 --- a/DysonNetwork.Gateway/Program.cs +++ b/DysonNetwork.Gateway/Program.cs @@ -2,6 +2,14 @@ using DysonNetwork.Gateway.Startup; var builder = WebApplication.CreateBuilder(args); +builder.Host.UseContentRoot(Directory.GetCurrentDirectory()); +builder.WebHost.ConfigureKestrel(options => +{ + options.Limits.MaxRequestBodySize = long.MaxValue; + options.Limits.KeepAliveTimeout = TimeSpan.FromMinutes(2); + options.Limits.RequestHeadersTimeout = TimeSpan.FromSeconds(30); +}); + // Add services to the container. builder.Services.AddGateway(builder.Configuration); builder.Services.AddControllers(); @@ -12,7 +20,7 @@ app.UseRequestTimeouts(); app.UseCors(opts => opts.SetIsOriginAllowed(_ => true) .WithExposedHeaders("*") - .WithHeaders() + .WithHeaders("*") .AllowCredentials() .AllowAnyHeader() .AllowAnyMethod() diff --git a/DysonNetwork.Pass/Startup/ApplicationConfiguration.cs b/DysonNetwork.Pass/Startup/ApplicationConfiguration.cs index baa05df..82f956a 100644 --- a/DysonNetwork.Pass/Startup/ApplicationConfiguration.cs +++ b/DysonNetwork.Pass/Startup/ApplicationConfiguration.cs @@ -25,7 +25,7 @@ public static class ApplicationConfiguration app.UseCors(opts => opts.SetIsOriginAllowed(_ => true) .WithExposedHeaders("*") - .WithHeaders() + .WithHeaders("*") .AllowCredentials() .AllowAnyHeader() .AllowAnyMethod() diff --git a/DysonNetwork.Pusher/Startup/ApplicationConfiguration.cs b/DysonNetwork.Pusher/Startup/ApplicationConfiguration.cs index 7dc3f30..1ade7f0 100644 --- a/DysonNetwork.Pusher/Startup/ApplicationConfiguration.cs +++ b/DysonNetwork.Pusher/Startup/ApplicationConfiguration.cs @@ -20,7 +20,7 @@ public static class ApplicationConfiguration app.UseCors(opts => opts.SetIsOriginAllowed(_ => true) .WithExposedHeaders("*") - .WithHeaders() + .WithHeaders("*") .AllowCredentials() .AllowAnyHeader() .AllowAnyMethod() diff --git a/DysonNetwork.Shared/Http/KestrelConfiguration.cs b/DysonNetwork.Shared/Http/KestrelConfiguration.cs index fa8735e..a493893 100644 --- a/DysonNetwork.Shared/Http/KestrelConfiguration.cs +++ b/DysonNetwork.Shared/Http/KestrelConfiguration.cs @@ -10,33 +10,34 @@ namespace DysonNetwork.Shared.Http; public static class KestrelConfiguration { - public static WebApplicationBuilder ConfigureAppKestrel(this WebApplicationBuilder builder, IConfiguration configuration) + public static WebApplicationBuilder ConfigureAppKestrel( + this WebApplicationBuilder builder, + IConfiguration configuration, + long maxRequestBodySize = 50 * 1024 * 1024 + ) { builder.Host.UseContentRoot(Directory.GetCurrentDirectory()); builder.WebHost.ConfigureKestrel(options => { - options.Limits.MaxRequestBodySize = 50 * 1024 * 1024; + options.Limits.MaxRequestBodySize = maxRequestBodySize; options.Limits.KeepAliveTimeout = TimeSpan.FromMinutes(2); options.Limits.RequestHeadersTimeout = TimeSpan.FromSeconds(30); - + var configuredUrl = Environment.GetEnvironmentVariable("ASPNETCORE_URLS"); if (!string.IsNullOrEmpty(configuredUrl)) return; - + var certPath = configuration["Service:ClientCert"]!; var keyPath = configuration["Service:ClientKey"]!; // Load PEM cert and key manually var certificate = X509Certificate2.CreateFromPemFile(certPath, keyPath); // Now pass the full cert - options.ListenAnyIP(5001, listenOptions => - { - listenOptions.UseHttps(certificate); - }); + options.ListenAnyIP(5001, listenOptions => { listenOptions.UseHttps(certificate); }); // Optional: HTTP fallback options.ListenAnyIP(8080); }); - + return builder; } } \ No newline at end of file