🐛 Trying to fix upload offset not found in frontend

This commit is contained in:
2025-07-27 14:25:45 +08:00
parent f74b1cf46a
commit 4a0117906a
8 changed files with 35 additions and 13 deletions

View File

@@ -174,6 +174,7 @@ function customRequest({
'content-type': file.type ?? 'application/octet-stream', 'content-type': file.type ?? 'application/octet-stream',
}, },
headers: { headers: {
'X-DirectUpload': 'true',
...requestHeaders, ...requestHeaders,
...headers, ...headers,
}, },

View File

@@ -11,7 +11,7 @@ using tusdotnet.Stores;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
// Configure Kestrel and server options // Configure Kestrel and server options
builder.ConfigureAppKestrel(builder.Configuration); builder.ConfigureAppKestrel(builder.Configuration, maxRequestBodySize: long.MaxValue);
// Add application services // Add application services
builder.Services.AddRegistryService(builder.Configuration); builder.Services.AddRegistryService(builder.Configuration);

View File

@@ -19,6 +19,15 @@ public static class ApplicationBuilderExtensions
app.UseAuthorization(); app.UseAuthorization();
app.MapControllers(); app.MapControllers();
app.UseCors(opts =>
opts.SetIsOriginAllowed(_ => true)
.WithExposedHeaders("*")
.WithHeaders("*")
.AllowCredentials()
.AllowAnyHeader()
.AllowAnyMethod()
);
app.UseDefaultFiles(); app.UseDefaultFiles();
app.UseStaticFiles(new StaticFileOptions app.UseStaticFiles(new StaticFileOptions
{ {

View File

@@ -228,6 +228,9 @@ public abstract class TusService
}, },
OnCreateCompleteAsync = eventContext => OnCreateCompleteAsync = eventContext =>
{ {
var directUpload = eventContext.HttpContext.Request.Headers["X-DirectUpload"].FirstOrDefault();
if (!string.IsNullOrEmpty(directUpload)) return Task.CompletedTask;
var gatewayUrl = configuration["GatewayUrl"]; var gatewayUrl = configuration["GatewayUrl"];
if (gatewayUrl is not null) if (gatewayUrl is not null)
eventContext.SetUploadUrl(new Uri(gatewayUrl + "/drive/tus/" + eventContext.FileId)); eventContext.SetUploadUrl(new Uri(gatewayUrl + "/drive/tus/" + eventContext.FileId));

View File

@@ -2,6 +2,14 @@ using DysonNetwork.Gateway.Startup;
var builder = WebApplication.CreateBuilder(args); 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. // Add services to the container.
builder.Services.AddGateway(builder.Configuration); builder.Services.AddGateway(builder.Configuration);
builder.Services.AddControllers(); builder.Services.AddControllers();
@@ -12,7 +20,7 @@ app.UseRequestTimeouts();
app.UseCors(opts => app.UseCors(opts =>
opts.SetIsOriginAllowed(_ => true) opts.SetIsOriginAllowed(_ => true)
.WithExposedHeaders("*") .WithExposedHeaders("*")
.WithHeaders() .WithHeaders("*")
.AllowCredentials() .AllowCredentials()
.AllowAnyHeader() .AllowAnyHeader()
.AllowAnyMethod() .AllowAnyMethod()

View File

@@ -25,7 +25,7 @@ public static class ApplicationConfiguration
app.UseCors(opts => app.UseCors(opts =>
opts.SetIsOriginAllowed(_ => true) opts.SetIsOriginAllowed(_ => true)
.WithExposedHeaders("*") .WithExposedHeaders("*")
.WithHeaders() .WithHeaders("*")
.AllowCredentials() .AllowCredentials()
.AllowAnyHeader() .AllowAnyHeader()
.AllowAnyMethod() .AllowAnyMethod()

View File

@@ -20,7 +20,7 @@ public static class ApplicationConfiguration
app.UseCors(opts => app.UseCors(opts =>
opts.SetIsOriginAllowed(_ => true) opts.SetIsOriginAllowed(_ => true)
.WithExposedHeaders("*") .WithExposedHeaders("*")
.WithHeaders() .WithHeaders("*")
.AllowCredentials() .AllowCredentials()
.AllowAnyHeader() .AllowAnyHeader()
.AllowAnyMethod() .AllowAnyMethod()

View File

@@ -10,33 +10,34 @@ namespace DysonNetwork.Shared.Http;
public static class KestrelConfiguration 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.Host.UseContentRoot(Directory.GetCurrentDirectory());
builder.WebHost.ConfigureKestrel(options => builder.WebHost.ConfigureKestrel(options =>
{ {
options.Limits.MaxRequestBodySize = 50 * 1024 * 1024; options.Limits.MaxRequestBodySize = maxRequestBodySize;
options.Limits.KeepAliveTimeout = TimeSpan.FromMinutes(2); options.Limits.KeepAliveTimeout = TimeSpan.FromMinutes(2);
options.Limits.RequestHeadersTimeout = TimeSpan.FromSeconds(30); options.Limits.RequestHeadersTimeout = TimeSpan.FromSeconds(30);
var configuredUrl = Environment.GetEnvironmentVariable("ASPNETCORE_URLS"); var configuredUrl = Environment.GetEnvironmentVariable("ASPNETCORE_URLS");
if (!string.IsNullOrEmpty(configuredUrl)) return; if (!string.IsNullOrEmpty(configuredUrl)) return;
var certPath = configuration["Service:ClientCert"]!; var certPath = configuration["Service:ClientCert"]!;
var keyPath = configuration["Service:ClientKey"]!; var keyPath = configuration["Service:ClientKey"]!;
// Load PEM cert and key manually // Load PEM cert and key manually
var certificate = X509Certificate2.CreateFromPemFile(certPath, keyPath); var certificate = X509Certificate2.CreateFromPemFile(certPath, keyPath);
// Now pass the full cert // Now pass the full cert
options.ListenAnyIP(5001, listenOptions => options.ListenAnyIP(5001, listenOptions => { listenOptions.UseHttps(certificate); });
{
listenOptions.UseHttps(certificate);
});
// Optional: HTTP fallback // Optional: HTTP fallback
options.ListenAnyIP(8080); options.ListenAnyIP(8080);
}); });
return builder; return builder;
} }
} }