Skip to content

Commit 2c303a0

Browse files
committed
Improve error handling, fix warnings and bump version to 1.4.0
1 parent 871549a commit 2c303a0

File tree

6 files changed

+22
-22
lines changed

6 files changed

+22
-22
lines changed

elFinder.NetCore.Web/Controllers/FileSystemController.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,24 @@ public async Task<IActionResult> Connector()
1616
}
1717
catch (Exception ex)
1818
{
19+
// TODO: would be good to Sanitize Exception Message at least in production, can leak server file paths
1920
return Json(new { error = "Unable to process your request: " + ex.Message });
2021
}
2122
}
2223

2324
[Route("thumb/{hash}")]
2425
public async Task<IActionResult> Thumbs(string hash)
2526
{
26-
var connector = GetConnector();
27-
return await connector.GetThumbnailAsync(HttpContext.Request, HttpContext.Response, hash);
27+
try
28+
{
29+
var connector = GetConnector();
30+
return await connector.GetThumbnailAsync(HttpContext.Request, HttpContext.Response, hash);
31+
}
32+
catch (Exception ex)
33+
{
34+
// TODO: would be good to Sanitize Exception Message at least in production, can leak server file paths
35+
return Json(new { error = "Unable to process your request: " + ex.Message });
36+
}
2837
}
2938

3039
private Connector GetConnector()

elFinder.NetCore.Web/elFinder.NetCore.Web.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<PackageProjectUrl>https://github.com/gordon-matt/elFinder.NetCore</PackageProjectUrl>
1010
<PackageLicenseUrl>
1111
</PackageLicenseUrl>
12-
<Version>1.3.6</Version>
12+
<Version>1.4.0</Version>
1313
<ImplicitUsings>enable</ImplicitUsings>
1414
</PropertyGroup>
1515
<ItemGroup>

elFinder.NetCore/Connector.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,13 @@ protected async Task<IActionResult> ProcessCoreAsync(HttpRequest request)
163163

164164
if (encoding == "scheme")
165165
{
166-
using var client = new WebClient();
167-
var data = await client.DownloadDataTaskAsync(new Uri(content));
166+
//TODO: It's worth noting that for optimal performance and resource management,
167+
// HttpClient should not be instantiated for each request in a real-world application.
168+
// Instead, it's typically best to create a single or few long-lived HttpClient instances and reuse
169+
// them for all HTTP calls. This can be achieved through dependency injection or a static/singleton
170+
// instance, depending on your application's architecture.
171+
using var client = new HttpClient();
172+
var data = await client.GetByteArrayAsync(new Uri(content));
168173
return await driver.PutAsync(path, data);
169174
}
170175
else

elFinder.NetCore/Exceptions/FileTypeNotAllowedException.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using System.Runtime.Serialization;
2-
3-
namespace elFinder.NetCore.Exceptions;
1+
namespace elFinder.NetCore.Exceptions;
42

53
public class FileTypeNotAllowedException : ApplicationException
64
{
@@ -17,9 +15,4 @@ public FileTypeNotAllowedException(string message, Exception innerException)
1715
: base(message, innerException)
1816
{
1917
}
20-
21-
protected FileTypeNotAllowedException(SerializationInfo info, StreamingContext context)
22-
: base(info, context)
23-
{
24-
}
2518
}

elFinder.NetCore/Exceptions/InvalidPathException.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using System.Runtime.Serialization;
2-
3-
namespace elFinder.NetCore.Exceptions;
1+
namespace elFinder.NetCore.Exceptions;
42

53
public class InvalidPathException : ApplicationException
64
{
@@ -17,9 +15,4 @@ public InvalidPathException(string message, Exception innerException)
1715
: base(message, innerException)
1816
{
1917
}
20-
21-
protected InvalidPathException(SerializationInfo info, StreamingContext context)
22-
: base(info, context)
23-
{
24-
}
2518
}

elFinder.NetCore/elFinder.NetCore.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<NeutralLanguage>en-US</NeutralLanguage>
77
<Description>elFinder ASP.NET Core backend</Description>
88
<PackageProjectUrl>https://github.com/gordon-matt/elFinder.NetCore</PackageProjectUrl>
9-
<Version>1.3.6</Version>
9+
<Version>1.4.0</Version>
1010
<PackageLicenseUrl>
1111
</PackageLicenseUrl>
1212
<OutputType>Library</OutputType>

0 commit comments

Comments
 (0)