Skip to content

Commit

Permalink
Improve error handling, fix warnings and bump version to 1.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt committed Jan 30, 2024
1 parent 1b69951 commit 95b89a9
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 22 deletions.
13 changes: 11 additions & 2 deletions elFinder.NetCore.Web/Controllers/FileSystemController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,24 @@ public async Task<IActionResult> Connector()
}
catch (Exception ex)
{
// TODO: would be good to Sanitize Exception Message at least in production, can leak server file paths
return Json(new { error = "Unable to process your request: " + ex.Message });
}
}

[Route("thumb/{hash}")]
public async Task<IActionResult> Thumbs(string hash)
{
var connector = GetConnector();
return await connector.GetThumbnailAsync(HttpContext.Request, HttpContext.Response, hash);
try
{
var connector = GetConnector();
return await connector.GetThumbnailAsync(HttpContext.Request, HttpContext.Response, hash);
}
catch (Exception ex)
{
// TODO: would be good to Sanitize Exception Message at least in production, can leak server file paths
return Json(new { error = "Unable to process your request: " + ex.Message });
}
}

private Connector GetConnector()
Expand Down
2 changes: 1 addition & 1 deletion elFinder.NetCore.Web/elFinder.NetCore.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<PackageProjectUrl>https://github.com/gordon-matt/elFinder.NetCore</PackageProjectUrl>
<PackageLicenseUrl>
</PackageLicenseUrl>
<Version>1.3.6</Version>
<Version>1.4.0</Version>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
Expand Down
9 changes: 7 additions & 2 deletions elFinder.NetCore/Connector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,13 @@ protected async Task<IActionResult> ProcessCoreAsync(HttpRequest request)

if (encoding == "scheme")
{
using var client = new WebClient();
var data = await client.DownloadDataTaskAsync(new Uri(content));
//TODO: It's worth noting that for optimal performance and resource management,
// HttpClient should not be instantiated for each request in a real-world application.
// Instead, it's typically best to create a single or few long-lived HttpClient instances and reuse
// them for all HTTP calls. This can be achieved through dependency injection or a static/singleton
// instance, depending on your application's architecture.
using var client = new HttpClient();
var data = await client.GetByteArrayAsync(new Uri(content));
return await driver.PutAsync(path, data);
}
else
Expand Down
9 changes: 1 addition & 8 deletions elFinder.NetCore/Exceptions/FileTypeNotAllowedException.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Runtime.Serialization;

namespace elFinder.NetCore.Exceptions;
namespace elFinder.NetCore.Exceptions;

public class FileTypeNotAllowedException : ApplicationException
{
Expand All @@ -17,9 +15,4 @@ public FileTypeNotAllowedException(string message, Exception innerException)
: base(message, innerException)
{
}

protected FileTypeNotAllowedException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
9 changes: 1 addition & 8 deletions elFinder.NetCore/Exceptions/InvalidPathException.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Runtime.Serialization;

namespace elFinder.NetCore.Exceptions;
namespace elFinder.NetCore.Exceptions;

public class InvalidPathException : ApplicationException
{
Expand All @@ -17,9 +15,4 @@ public InvalidPathException(string message, Exception innerException)
: base(message, innerException)
{
}

protected InvalidPathException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
2 changes: 1 addition & 1 deletion elFinder.NetCore/elFinder.NetCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<NeutralLanguage>en-US</NeutralLanguage>
<Description>elFinder ASP.NET Core backend</Description>
<PackageProjectUrl>https://github.com/gordon-matt/elFinder.NetCore</PackageProjectUrl>
<Version>1.3.6</Version>
<Version>1.4.0</Version>
<PackageLicenseUrl>
</PackageLicenseUrl>
<OutputType>Library</OutputType>
Expand Down

0 comments on commit 95b89a9

Please sign in to comment.