getting some interface to fs
This commit is contained in:
@ -47,7 +47,6 @@ namespace Yavsc.Helpers
|
||||
|
||||
public static UserDirectoryInfo GetUserFiles(string userName, string subdir)
|
||||
{
|
||||
|
||||
UserDirectoryInfo di = new UserDirectoryInfo(UserFilesDirName, userName, subdir);
|
||||
return di;
|
||||
}
|
||||
|
@ -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})");
|
||||
|
@ -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);
|
||||
}
|
||||
|
24
src/Yavsc/Controllers/FileSystemController.cs
Normal file
24
src/Yavsc/Controllers/FileSystemController.cs
Normal file
@ -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<FileSystemController>();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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,
|
||||
|
@ -52,7 +52,10 @@
|
||||
<a asp-action="Index">@SR["Back to List"]</a>
|
||||
</div>
|
||||
|
||||
@{ await Html.RenderPartialAsync("_PostFilesPartial"); }
|
||||
|
||||
@section Scripts {
|
||||
<script src="~/js/dropzone.js"></script>
|
||||
@{ await Html.RenderPartialAsync("_FSScriptsPartial"); }
|
||||
@{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); }
|
||||
}
|
||||
|
@ -35,6 +35,7 @@
|
||||
<script src="~/js/dropzone.js"></script>
|
||||
<script src="~/js/quill.js"></script>
|
||||
<script src="~/js/to-markdown.js"></script>
|
||||
@{ await Html.RenderPartialAsync("_FSScriptsPartial"); }
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$(".mdcoding").addClass('hidden');
|
||||
@ -95,29 +96,7 @@
|
||||
};
|
||||
initQuill();
|
||||
|
||||
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, ev) {
|
||||
console.log('response:');
|
||||
console.log(response);
|
||||
for(i=0;i<response.length;i++) {
|
||||
var file = response[i];
|
||||
console.log('response item:');
|
||||
console.log(file);
|
||||
|
||||
$('<p><a href="/files/@User.GetUserName()/'+file.FileName+'">'+file.FileName+'</a></p>').appendTo('#ql-editor-2');
|
||||
updateMD('Content',$('#contentview').html())
|
||||
}
|
||||
},
|
||||
url: "/api/fs"
|
||||
};
|
||||
|
||||
|
||||
});
|
||||
</script>
|
||||
@ -230,13 +209,7 @@
|
||||
</div>
|
||||
@await Component.InvokeAsync("Directory","")
|
||||
<div >
|
||||
<form id="postfiles" class="dropzone" method="post" enctype="multipart/form-data">
|
||||
<div class="fallback">
|
||||
<input name="File[]" type="file" id="filesinput"/>
|
||||
</div>
|
||||
<input type="hidden" name="postId" value="@Model.Id" />
|
||||
@Html.AntiForgeryToken()
|
||||
</form>
|
||||
@{ await Html.RenderPartialAsync("_PostFilesPartial"); }
|
||||
</div>
|
||||
<div>
|
||||
<a asp-action="Index">@SR["Back to List"]</a>
|
||||
|
@ -1,6 +1,6 @@
|
||||
@using Yavsc.ViewModels.UserFiles
|
||||
@model UserDirectoryInfo
|
||||
<div class="dirinfo">
|
||||
<div class="dirinfo" data-owner="@Model.UserName" data-path="@Model.SubPath">
|
||||
<strong>@Model.UserName / @Model.SubPath</strong>
|
||||
<div class="subdirs">
|
||||
@foreach (var subdir in Model.SubDirectories) {
|
||||
@ -20,7 +20,7 @@ tr.fileinfo td {
|
||||
tr.fileinfo:hover {background-color: #f5f5f5}
|
||||
|
||||
</style>
|
||||
<table >
|
||||
<table>
|
||||
<tr class="fileheaders">
|
||||
<th>Nom
|
||||
</th>
|
||||
|
1
src/Yavsc/Views/Shared/_FSScriptsPartial.cshtml
Normal file
1
src/Yavsc/Views/Shared/_FSScriptsPartial.cshtml
Normal file
@ -0,0 +1 @@
|
||||
<script src="/js/fs.js" asp-append-version="true"></script>
|
6
src/Yavsc/Views/Shared/_PostFilesPartial.cshtml
Normal file
6
src/Yavsc/Views/Shared/_PostFilesPartial.cshtml
Normal file
@ -0,0 +1,6 @@
|
||||
<form id="postfiles" class="dropzone" method="post" enctype="multipart/form-data">
|
||||
<div class="fallback">
|
||||
<input name="File[]" type="file" id="filesinput"/>
|
||||
</div>
|
||||
@Html.AntiForgeryToken()
|
||||
</form>
|
93
src/Yavsc/wwwroot/js/fs.js
Normal file
93
src/Yavsc/wwwroot/js/fs.js
Normal file
@ -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) {
|
||||
|
||||
$('<button>' + owner + '</button>').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;
|
||||
$('<button>').append(part).click(function() {
|
||||
OpenDir($view, npath)
|
||||
}).appendTo($view)
|
||||
});
|
||||
|
||||
$.each(data.SubDirectories, function () {
|
||||
var item = this;
|
||||
var spath = (path) ? path + '/' + item.Name : item.Name;
|
||||
$('<button>').append(item.Name).click(function() {
|
||||
OpenDir($view, spath);
|
||||
}).appendTo($view);
|
||||
});
|
||||
var $ftable = $('<table>').append('<tr class="fileheaders"><th>Nom</th><th>Taille</th><th>Modification</th></tr>');
|
||||
$.each(data.Files, function () {
|
||||
var item = this;
|
||||
var $tr = $('<tr></tr>');
|
||||
var $td = $('<td></td>')
|
||||
$('<a></a>').append(item.Name).click(function() {
|
||||
document.location = '/' + owner + '/' + npath + '/' + item.Name
|
||||
}).appendTo($td);
|
||||
$td.appendTo($tr);
|
||||
$('<td>' + item.Size + '</td>').appendTo($tr);
|
||||
$('<td>' + item.LastModified + '</td>').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);
|
||||
|
||||
$('<p><a href="/files/@User.GetUserName()/' + filer.FileName + '">' + filer.FileName + '</a></p>').appendTo('#ql-editor-2');
|
||||
updateMD ('Content', $('#contentview').html())
|
||||
}
|
||||
},
|
||||
url: '/api/fs'
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user