-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleanup usings and use file scoped namespaces
- Loading branch information
Matt
committed
Jan 27, 2024
1 parent
f7a9e9e
commit 1b69951
Showing
57 changed files
with
3,359 additions
and
3,550 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,10 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
namespace elFinder.NetCore.Web.Controllers; | ||
|
||
namespace elFinder.NetCore.Web.Controllers | ||
[Route("file-manager")] | ||
public class FileManagerController : Controller | ||
{ | ||
[Route("file-manager")] | ||
public class FileManagerController : Controller | ||
public IActionResult Index() | ||
{ | ||
public IActionResult Index() | ||
{ | ||
return View(); | ||
} | ||
return View(); | ||
} | ||
} |
131 changes: 63 additions & 68 deletions
131
elFinder.NetCore.Web/Controllers/FileSystemController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1,81 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using elFinder.NetCore.Drivers.FileSystem; | ||
using elFinder.NetCore.Drivers.FileSystem; | ||
using Microsoft.AspNetCore.Http.Extensions; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace elFinder.NetCore.Web.Controllers | ||
namespace elFinder.NetCore.Web.Controllers; | ||
|
||
[Route("el-finder/file-system")] | ||
public class FileSystemController : Controller | ||
{ | ||
[Route("el-finder/file-system")] | ||
public class FileSystemController : Controller | ||
[Route("connector")] | ||
public async Task<IActionResult> Connector() | ||
{ | ||
[Route("connector")] | ||
public async Task<IActionResult> Connector() | ||
try | ||
{ | ||
try | ||
{ | ||
var connector = GetConnector(); | ||
return await connector.ProcessAsync(Request); | ||
} | ||
catch (Exception ex) | ||
{ | ||
return Json(new { error = "Unable to process your request: " + ex.Message }); | ||
} | ||
var connector = GetConnector(); | ||
return await connector.ProcessAsync(Request); | ||
} | ||
|
||
[Route("thumb/{hash}")] | ||
public async Task<IActionResult> Thumbs(string hash) | ||
catch (Exception ex) | ||
{ | ||
var connector = GetConnector(); | ||
return await connector.GetThumbnailAsync(HttpContext.Request, HttpContext.Response, hash); | ||
return Json(new { error = "Unable to process your request: " + ex.Message }); | ||
} | ||
} | ||
|
||
private Connector GetConnector() | ||
{ | ||
var driver = new FileSystemDriver(); | ||
[Route("thumb/{hash}")] | ||
public async Task<IActionResult> Thumbs(string hash) | ||
{ | ||
var connector = GetConnector(); | ||
return await connector.GetThumbnailAsync(HttpContext.Request, HttpContext.Response, hash); | ||
} | ||
|
||
string absoluteUrl = UriHelper.BuildAbsolute(Request.Scheme, Request.Host); | ||
var uri = new Uri(absoluteUrl); | ||
private Connector GetConnector() | ||
{ | ||
var driver = new FileSystemDriver(); | ||
|
||
string absoluteUrl = UriHelper.BuildAbsolute(Request.Scheme, Request.Host); | ||
var uri = new Uri(absoluteUrl); | ||
|
||
var root = new RootVolume( | ||
PathHelper.MapPath("~/Files"), | ||
$"{uri.Scheme}://{uri.Authority}/Files/", | ||
$"{uri.Scheme}://{uri.Authority}/el-finder/file-system/thumb/") | ||
var root = new RootVolume( | ||
PathHelper.MapPath("~/Files"), | ||
$"{uri.Scheme}://{uri.Authority}/Files/", | ||
$"{uri.Scheme}://{uri.Authority}/el-finder/file-system/thumb/") | ||
{ | ||
//IsReadOnly = !User.IsInRole("Administrators") | ||
IsReadOnly = false, // Can be readonly according to user's membership permission | ||
IsLocked = false, // If locked, files and directories cannot be deleted, renamed or moved | ||
Alias = "Files", // Beautiful name given to the root/home folder | ||
//MaxUploadSizeInKb = 2048, // Limit imposed to user uploaded file <= 2048 KB | ||
AccessControlAttributes = new HashSet<NamedAccessControlAttributeSet>() | ||
{ | ||
//IsReadOnly = !User.IsInRole("Administrators") | ||
IsReadOnly = false, // Can be readonly according to user's membership permission | ||
IsLocked = false, // If locked, files and directories cannot be deleted, renamed or moved | ||
Alias = "Files", // Beautiful name given to the root/home folder | ||
//MaxUploadSizeInKb = 2048, // Limit imposed to user uploaded file <= 2048 KB | ||
AccessControlAttributes = new HashSet<NamedAccessControlAttributeSet>() | ||
new NamedAccessControlAttributeSet(PathHelper.MapPath("~/Files/readonly.txt")) | ||
{ | ||
Write = false, | ||
Locked = true | ||
}, | ||
new NamedAccessControlAttributeSet(PathHelper.MapPath("~/Files/Prohibited")) | ||
{ | ||
new NamedAccessControlAttributeSet(PathHelper.MapPath("~/Files/readonly.txt")) | ||
{ | ||
Write = false, | ||
Locked = true | ||
}, | ||
new NamedAccessControlAttributeSet(PathHelper.MapPath("~/Files/Prohibited")) | ||
{ | ||
Read = false, | ||
Write = false, | ||
Locked = true | ||
}, | ||
new NamedAccessControlAttributeSet(PathHelper.MapPath("~/Files/Parent/Children")) | ||
{ | ||
Read = true, | ||
Write = false, | ||
Locked = true | ||
} | ||
Read = false, | ||
Write = false, | ||
Locked = true | ||
}, | ||
// Upload file type constraints | ||
//UploadAllow = new[] { "image", "text" }, | ||
//UploadDeny = new[] { "text/csv" }, | ||
//UploadOrder = new[] { "allow", "deny" } | ||
}; | ||
new NamedAccessControlAttributeSet(PathHelper.MapPath("~/Files/Parent/Children")) | ||
{ | ||
Read = true, | ||
Write = false, | ||
Locked = true | ||
} | ||
}, | ||
// Upload file type constraints | ||
//UploadAllow = new[] { "image", "text" }, | ||
//UploadDeny = new[] { "text/csv" }, | ||
//UploadOrder = new[] { "allow", "deny" } | ||
}; | ||
|
||
driver.AddRoot(root); | ||
driver.AddRoot(root); | ||
|
||
return new Connector(driver) | ||
{ | ||
// This allows support for the "onlyMimes" option on the client. | ||
MimeDetect = MimeDetectOption.Internal | ||
}; | ||
} | ||
return new Connector(driver) | ||
{ | ||
// This allows support for the "onlyMimes" option on the client. | ||
MimeDetect = MimeDetectOption.Internal | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,16 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
namespace elFinder.NetCore.Web.Controllers; | ||
|
||
namespace elFinder.NetCore.Web.Controllers | ||
public class HomeController : Controller | ||
{ | ||
public class HomeController : Controller | ||
[Route("")] | ||
public IActionResult Index() | ||
{ | ||
[Route("")] | ||
public IActionResult Index() | ||
{ | ||
return View(); | ||
} | ||
return View(); | ||
} | ||
|
||
[Route("error")] | ||
public IActionResult Error() | ||
{ | ||
return View(); | ||
} | ||
[Route("error")] | ||
public IActionResult Error() | ||
{ | ||
return View(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,16 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
namespace elFinder.NetCore.Web.Controllers; | ||
|
||
namespace elFinder.NetCore.Web.Controllers | ||
[Route("tiny-mce")] | ||
public class TinyMCEController : Controller | ||
{ | ||
[Route("tiny-mce")] | ||
public class TinyMCEController : Controller | ||
public IActionResult Index() | ||
{ | ||
public IActionResult Index() | ||
{ | ||
return View(); | ||
} | ||
return View(); | ||
} | ||
|
||
[Route("browse")] | ||
public IActionResult Browse() | ||
{ | ||
return View(); | ||
} | ||
[Route("browse")] | ||
public IActionResult Browse() | ||
{ | ||
return View(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,24 @@ | ||
using Microsoft.AspNetCore.Hosting; | ||
using System; | ||
using System.IO; | ||
namespace elFinder.NetCore.Web; | ||
|
||
namespace elFinder.NetCore.Web | ||
public static class PathHelper | ||
{ | ||
public static class PathHelper | ||
public static string WebRootPath { get; set; } | ||
|
||
public static string GetFullPathNormalized(string path) | ||
{ | ||
public static string WebRootPath { get; set; } | ||
return Path.TrimEndingDirectorySeparator(Path.GetFullPath(path)); | ||
} | ||
|
||
public static string GetFullPathNormalized(string path) | ||
{ | ||
return Path.TrimEndingDirectorySeparator(Path.GetFullPath(path)); | ||
} | ||
public static string MapPath(string path, string basePath = null) | ||
{ | ||
basePath = string.IsNullOrEmpty(basePath) ? WebRootPath : basePath; | ||
|
||
public static string MapPath(string path, string basePath = null) | ||
if (string.IsNullOrEmpty(basePath)) | ||
{ | ||
basePath = string.IsNullOrEmpty(basePath) ? WebRootPath : basePath; | ||
|
||
if (string.IsNullOrEmpty(basePath)) | ||
{ | ||
throw new ArgumentException("elFinder PathHelper don't have WebRootPath or basePath configured."); | ||
} | ||
|
||
path = path.Replace("~/", "").TrimStart('/').Replace('/', '\\'); | ||
return GetFullPathNormalized(Path.Combine(basePath, path)); | ||
throw new ArgumentException("PathHelper does not have WebRootPath or basePath configured."); | ||
} | ||
|
||
path = path.Replace("~/", "").TrimStart('/').Replace('/', '\\'); | ||
return GetFullPathNormalized(Path.Combine(basePath, path)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
global using Microsoft.AspNetCore.Mvc; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,34 @@ | ||
using System; | ||
namespace elFinder.NetCore; | ||
|
||
namespace elFinder.NetCore | ||
public class AccessControlAttributeSet | ||
{ | ||
public class AccessControlAttributeSet | ||
public bool Read { get; set; } = true; | ||
|
||
public bool Write { get; set; } = true; | ||
|
||
public bool Locked { get; set; } | ||
} | ||
|
||
public class NamedAccessControlAttributeSet : AccessControlAttributeSet | ||
{ | ||
public NamedAccessControlAttributeSet() : base() | ||
{ | ||
public bool Read { get; set; } = true; | ||
} | ||
|
||
public bool Write { get; set; } = true; | ||
public NamedAccessControlAttributeSet(string fullName) : base() | ||
{ | ||
FullName = fullName ?? throw new ArgumentNullException(nameof(fullName)); | ||
} | ||
|
||
public bool Locked { get; set; } | ||
public string FullName { get; } | ||
|
||
public override bool Equals(object obj) | ||
{ | ||
return (obj as NamedAccessControlAttributeSet)?.FullName == FullName; | ||
} | ||
|
||
public class NamedAccessControlAttributeSet : AccessControlAttributeSet | ||
public override int GetHashCode() | ||
{ | ||
public NamedAccessControlAttributeSet() : base() | ||
{ | ||
} | ||
|
||
public NamedAccessControlAttributeSet(string fullName) : base() | ||
{ | ||
FullName = fullName ?? throw new ArgumentNullException(nameof(fullName)); | ||
} | ||
|
||
public string FullName { get; } | ||
|
||
public override bool Equals(object obj) | ||
{ | ||
return (obj as NamedAccessControlAttributeSet)?.FullName == FullName; | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
return FullName.GetHashCode(); | ||
} | ||
return FullName.GetHashCode(); | ||
} | ||
} |
Oops, something went wrong.