diff --git a/src/Yavsc.Abstract/FileSystem/AbstractFileSystemHelpers.cs b/src/Yavsc.Abstract/FileSystem/AbstractFileSystemHelpers.cs index bb9896c2..ae605168 100644 --- a/src/Yavsc.Abstract/FileSystem/AbstractFileSystemHelpers.cs +++ b/src/Yavsc.Abstract/FileSystem/AbstractFileSystemHelpers.cs @@ -47,7 +47,6 @@ namespace Yavsc.Helpers public static UserDirectoryInfo GetUserFiles(string userName, string subdir) { - UserDirectoryInfo di = new UserDirectoryInfo(UserFilesDirName, userName, subdir); return di; } diff --git a/src/Yavsc.Abstract/FileSystem/UserDirectoryInfo.cs b/src/Yavsc.Abstract/FileSystem/UserDirectoryInfo.cs index 30a53dd0..ad5a8db0 100644 --- a/src/Yavsc.Abstract/FileSystem/UserDirectoryInfo.cs +++ b/src/Yavsc.Abstract/FileSystem/UserDirectoryInfo.cs @@ -28,7 +28,7 @@ namespace Yavsc.ViewModels.UserFiles if (string.IsNullOrWhiteSpace(username)) throw new NotSupportedException("No user name, no user dir."); UserName = username; - var finalPath = username; + var finalPath = path == null ? username : Path.Combine(username, path); if (!finalPath.IsValidYavscPath()) throw new InvalidOperationException( $"File name contains invalid chars ({finalPath})"); diff --git a/src/Yavsc/ApiControllers/Blogspot/FileSystemApiController.cs b/src/Yavsc/ApiControllers/Blogspot/FileSystemApiController.cs index c747c459..036af5a8 100644 --- a/src/Yavsc/ApiControllers/Blogspot/FileSystemApiController.cs +++ b/src/Yavsc/ApiControllers/Blogspot/FileSystemApiController.cs @@ -47,6 +47,7 @@ namespace Yavsc.ApiControllers if (subdir !=null) if (!subdir.IsValidYavscPath()) return new BadRequestResult(); + // _logger.LogInformation($"listing files from {User.Identity.Name}{subdir}"); var files = AbstractFileSystemHelpers.GetUserFiles(User.Identity.Name, subdir); return Ok(files); } diff --git a/src/Yavsc/Controllers/FileSystemController.cs b/src/Yavsc/Controllers/FileSystemController.cs new file mode 100644 index 00000000..47569342 --- /dev/null +++ b/src/Yavsc/Controllers/FileSystemController.cs @@ -0,0 +1,24 @@ +using Microsoft.AspNet.Mvc; +using Microsoft.Extensions.Logging; +using Yavsc.Helpers; + +namespace Yavsc.Controllers +{ + public class FileSystemController : Controller + { + ILogger _logger; + public FileSystemController(ILoggerFactory loggerFactory) + { + _logger = loggerFactory.CreateLogger(); + } + + public IActionResult Index(string subdir="") + { + if (subdir !=null) + if (!subdir.IsValidYavscPath()) + return new BadRequestResult(); + var files = AbstractFileSystemHelpers.GetUserFiles(User.Identity.Name, subdir); + return View(files); + } + } +} \ No newline at end of file diff --git a/src/Yavsc/Helpers/FileSystemHelpers.cs b/src/Yavsc/Helpers/FileSystemHelpers.cs index 75bf9bad..d032ead6 100644 --- a/src/Yavsc/Helpers/FileSystemHelpers.cs +++ b/src/Yavsc/Helpers/FileSystemHelpers.cs @@ -103,16 +103,24 @@ namespace Yavsc.Helpers user.DiskUsage -= fi.Length; } + static string ParseFileNameFromDisposition(string disposition) + { + // form-data_ name=_file__ filename=_Constants.Private.cs_ + var parts = disposition.Split(' '); + var filename = parts[2].Split('=')[1]; + filename = filename.Substring(1,filename.Length-2); + return filename; + } + public static void AddQuota(this ApplicationUser user, int quota) { user.DiskQuota += quota; } public static FileRecievedInfo ReceiveUserFile(this ApplicationUser user, string root, IFormFile f, string destFileName = null) { - return ReceiveUserFile(user, root, f.OpenReadStream(), destFileName ?? f.ContentDisposition, f.ContentType, CancellationToken.None); + return ReceiveUserFile(user, root, f.OpenReadStream(), destFileName ?? ParseFileNameFromDisposition(f.ContentDisposition), f.ContentType, CancellationToken.None); } - public static FileRecievedInfo ReceiveUserFile(this ApplicationUser user, string root, Stream inputStream, string destFileName, string contentType, CancellationToken token) { // TODO lock user's disk usage for this scope, diff --git a/src/Yavsc/Views/Blogspot/Create.cshtml b/src/Yavsc/Views/Blogspot/Create.cshtml index 12d515cb..adc581f3 100644 --- a/src/Yavsc/Views/Blogspot/Create.cshtml +++ b/src/Yavsc/Views/Blogspot/Create.cshtml @@ -52,7 +52,10 @@ @SR["Back to List"] + @{ await Html.RenderPartialAsync("_PostFilesPartial"); } @section Scripts { + + @{ await Html.RenderPartialAsync("_FSScriptsPartial"); } @{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); } } diff --git a/src/Yavsc/Views/Blogspot/Edit.cshtml b/src/Yavsc/Views/Blogspot/Edit.cshtml index 50d64be6..1b12a4d5 100644 --- a/src/Yavsc/Views/Blogspot/Edit.cshtml +++ b/src/Yavsc/Views/Blogspot/Edit.cshtml @@ -35,6 +35,7 @@ +@{ await Html.RenderPartialAsync("_FSScriptsPartial"); } @@ -230,13 +209,7 @@ @await Component.InvokeAsync("Directory","")
-
-
- -
- - @Html.AntiForgeryToken() -
+ @{ await Html.RenderPartialAsync("_PostFilesPartial"); }
@SR["Back to List"] diff --git a/src/Yavsc/Views/Shared/Components/Directory/Default.cshtml b/src/Yavsc/Views/Shared/Components/Directory/Default.cshtml index c36b5583..505891ff 100644 --- a/src/Yavsc/Views/Shared/Components/Directory/Default.cshtml +++ b/src/Yavsc/Views/Shared/Components/Directory/Default.cshtml @@ -1,6 +1,6 @@ @using Yavsc.ViewModels.UserFiles @model UserDirectoryInfo -
+
@Model.UserName / @Model.SubPath
@foreach (var subdir in Model.SubDirectories) { @@ -20,7 +20,7 @@ tr.fileinfo td { tr.fileinfo:hover {background-color: #f5f5f5} - +
diff --git a/src/Yavsc/Views/Shared/_FSScriptsPartial.cshtml b/src/Yavsc/Views/Shared/_FSScriptsPartial.cshtml new file mode 100644 index 00000000..d955f1c3 --- /dev/null +++ b/src/Yavsc/Views/Shared/_FSScriptsPartial.cshtml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/Yavsc/Views/Shared/_PostFilesPartial.cshtml b/src/Yavsc/Views/Shared/_PostFilesPartial.cshtml new file mode 100644 index 00000000..87d37421 --- /dev/null +++ b/src/Yavsc/Views/Shared/_PostFilesPartial.cshtml @@ -0,0 +1,6 @@ + +
+ +
+ @Html.AntiForgeryToken() + \ No newline at end of file diff --git a/src/Yavsc/wwwroot/js/fs.js b/src/Yavsc/wwwroot/js/fs.js new file mode 100644 index 00000000..3e327f10 --- /dev/null +++ b/src/Yavsc/wwwroot/js/fs.js @@ -0,0 +1,93 @@ +// requires DropZone ยช toMarkdown + +window.RemoteFS = (function ($) { + var Combine = function (patha, pathb) { + if (!patha) return pathb; + if (!pathb) return patha; + return patha + '/' + pathb; + }; + + var OpenDir = function ($view, sub) { + $view.data('path', sub); + InitDir($view); + }; + + var InitDir = function ($view) { + + var path = $view.data('path'); + var owner = $view.data('owner'); + var url = path ? '/api/fs/' + path : '/api/fs'; + + $view.empty(); + $.get(url, function(data) { + + $('').click(function() { + OpenDir($view, null); + }).appendTo($view); + + var npath = null; + + if (path) $.each(path.split('/'), function () { + var part = this; + if (npath) npath = npath + '/' + part; + else npath = part; + $('
Nom
').append(''); + $.each(data.Files, function () { + var item = this; + var $tr = $(''); + var $td = $('') + $('').append(item.Name).click(function() { + document.location = '/' + owner + '/' + npath + '/' + item.Name + }).appendTo($td); + $td.appendTo($tr); + $('').appendTo($tr); + $('').appendTo($tr); + $tr.appendTo($ftable) + }); + $ftable.appendTo($view); + }) + }; + + $(document).ready(function ($) { + OpenDir($('.dirinfo')); + }); + +})(window.jQuery); + +Dropzone.options.postfiles= { + maxFilesize: 20, // MB TODO: let sell it. + autoProcessQueue: true, + accept: function(file, done) { + if (file.name == "justinbieber.jpg") { + done("Naha, you don't.") + } + else { done() } + }, + success: function (file, response) { + console.log('response:'); + console.log(response); + for (var i = 0; i < response.length; i++) { + var filer = response[i]; + console.log('response item:'); + console.log(filer); + + $('

' + filer.FileName + '

').appendTo('#ql-editor-2'); + updateMD ('Content', $('#contentview').html()) + } + }, + url: '/api/fs' + }; + +
NomTailleModification
' + item.Size + '' + item.LastModified + '