Added max file size upload option. Switched from stream upload to multipart form content file upload
This commit is contained in:
@@ -10,6 +10,7 @@ public class AppConfiguration
|
|||||||
public AuthenticationConfig Authentication { get; set; } = new();
|
public AuthenticationConfig Authentication { get; set; } = new();
|
||||||
public DevelopmentConfig Development { get; set; } = new();
|
public DevelopmentConfig Development { get; set; } = new();
|
||||||
public ClientConfig Client { get; set; } = new();
|
public ClientConfig Client { get; set; } = new();
|
||||||
|
public KestrelConfig Kestrel { get; set; } = new();
|
||||||
|
|
||||||
public class ClientConfig
|
public class ClientConfig
|
||||||
{
|
{
|
||||||
@@ -48,4 +49,9 @@ public class AppConfiguration
|
|||||||
{
|
{
|
||||||
public bool EnableApiDocs { get; set; } = false;
|
public bool EnableApiDocs { get; set; } = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class KestrelConfig
|
||||||
|
{
|
||||||
|
public int UploadLimit { get; set; } = 100;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -3,8 +3,10 @@ using ICSharpCode.SharpZipLib.GZip;
|
|||||||
using ICSharpCode.SharpZipLib.Tar;
|
using ICSharpCode.SharpZipLib.Tar;
|
||||||
using ICSharpCode.SharpZipLib.Zip;
|
using ICSharpCode.SharpZipLib.Zip;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using MoonCore.Exceptions;
|
||||||
using MoonCore.Extended.PermFilter;
|
using MoonCore.Extended.PermFilter;
|
||||||
using MoonCore.Helpers;
|
using MoonCore.Helpers;
|
||||||
|
using Moonlight.ApiServer.Configuration;
|
||||||
using Moonlight.Shared.Http.Requests.Admin.Sys.Files;
|
using Moonlight.Shared.Http.Requests.Admin.Sys.Files;
|
||||||
using Moonlight.Shared.Http.Responses.Admin.Sys;
|
using Moonlight.Shared.Http.Responses.Admin.Sys;
|
||||||
|
|
||||||
@@ -65,7 +67,11 @@ public class FilesController : Controller
|
|||||||
[HttpPost("create")]
|
[HttpPost("create")]
|
||||||
public async Task Create([FromQuery] string path)
|
public async Task Create([FromQuery] string path)
|
||||||
{
|
{
|
||||||
var stream = Request.Body;
|
if (Request.Form.Files.Count != 1)
|
||||||
|
throw new HttpApiException("You need to provide exactly one file", 400);
|
||||||
|
|
||||||
|
var file = Request.Form.Files[0];
|
||||||
|
var stream = file.OpenReadStream();
|
||||||
|
|
||||||
var safePath = SanitizePath(path);
|
var safePath = SanitizePath(path);
|
||||||
var physicalPath = PathBuilder.File(BaseDirectory, safePath);
|
var physicalPath = PathBuilder.File(BaseDirectory, safePath);
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ public class Startup
|
|||||||
|
|
||||||
await CreateWebApplicationBuilder();
|
await CreateWebApplicationBuilder();
|
||||||
|
|
||||||
|
await ConfigureKestrel();
|
||||||
await RegisterAppConfiguration();
|
await RegisterAppConfiguration();
|
||||||
await RegisterLogging();
|
await RegisterLogging();
|
||||||
await RegisterBase();
|
await RegisterBase();
|
||||||
@@ -183,6 +184,20 @@ public class Startup
|
|||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Task ConfigureKestrel()
|
||||||
|
{
|
||||||
|
WebApplicationBuilder.WebHost.ConfigureKestrel(kestrelOptions =>
|
||||||
|
{
|
||||||
|
var maxUploadInBytes = ByteConverter
|
||||||
|
.FromMegaBytes(Configuration.Kestrel.UploadLimit)
|
||||||
|
.Bytes;
|
||||||
|
|
||||||
|
kestrelOptions.Limits.MaxRequestBodySize = maxUploadInBytes;
|
||||||
|
});
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Plugin Loading
|
#region Plugin Loading
|
||||||
|
|||||||
@@ -47,7 +47,13 @@ public class SysFileSystemProvider : IFileSystemProvider, ICompressFileSystemPro
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async Task Create(string path, Stream stream)
|
public async Task Create(string path, Stream stream)
|
||||||
=> await HttpApiClient.PostStream($"{BaseApiUrl}/create?path={path}", stream);
|
{
|
||||||
|
var content = new MultipartFormDataContent();
|
||||||
|
|
||||||
|
content.Add(new StreamContent(stream), "file", "x");
|
||||||
|
|
||||||
|
await HttpApiClient.Post($"{BaseApiUrl}/create?path={path}", content);
|
||||||
|
}
|
||||||
|
|
||||||
public async Task Move(string oldPath, string newPath)
|
public async Task Move(string oldPath, string newPath)
|
||||||
=> await HttpApiClient.Post($"{BaseApiUrl}/move?oldPath={oldPath}&newPath={newPath}");
|
=> await HttpApiClient.Post($"{BaseApiUrl}/move?oldPath={oldPath}&newPath={newPath}");
|
||||||
|
|||||||
@@ -27,7 +27,7 @@
|
|||||||
<PackageReference Include="MoonCore" Version="1.8.5" />
|
<PackageReference Include="MoonCore" Version="1.8.5" />
|
||||||
<PackageReference Include="MoonCore.Blazor" Version="1.2.9" />
|
<PackageReference Include="MoonCore.Blazor" Version="1.2.9" />
|
||||||
<PackageReference Include="MoonCore.PluginFramework" Version="1.0.5"/>
|
<PackageReference Include="MoonCore.PluginFramework" Version="1.0.5"/>
|
||||||
<PackageReference Include="MoonCore.Blazor.Tailwind" Version="1.3.3" />
|
<PackageReference Include="MoonCore.Blazor.Tailwind" Version="1.3.4" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
|
|||||||
Reference in New Issue
Block a user