diff --git a/Yavsc.Abstract/FileSystem/FileSystemHelpers.cs b/Yavsc.Abstract/FileSystem/FileSystemHelpers.cs index df09b244..fc7bef8a 100644 --- a/Yavsc.Abstract/FileSystem/FileSystemHelpers.cs +++ b/Yavsc.Abstract/FileSystem/FileSystemHelpers.cs @@ -1,4 +1,5 @@ using System.Linq; +using System.Text; namespace Yavsc.Abstract.FileSystem { @@ -6,20 +7,35 @@ namespace Yavsc.Abstract.FileSystem { public static bool IsValidYavscPath(this string path) { - if (path == null) return true; + if (string.IsNullOrEmpty(path)) return true; foreach (var name in path.Split('/')) { if (!IsValidDirectoryName(name) || name.Equals("..") || name.Equals(".")) return false; } - if (path[path.Length]==FileSystemConstants.RemoteDirectorySeparator) return false; + if (path[path.Length-1]==FileSystemConstants.RemoteDirectorySeparator) return false; return true; } public static bool IsValidDirectoryName(this string name) { return !name.Any(c => !FileSystemConstants.ValidFileNameChars.Contains(c)); } + // Ensure this path is canonical, + // No "dirto/./this", neither "dirt/to/that/" + // no .. and each char must be listed as valid in constants + public static string FilterFileName(string fileName) + { + if (fileName==null) return null; + StringBuilder sb = new StringBuilder(); + foreach (var c in fileName) + { + if (FileSystemConstants.ValidFileNameChars.Contains(c)) + sb.Append(c); + else sb.Append('_'); + } + return sb.ToString(); + } } public static class FileSystemConstants diff --git a/Yavsc.Abstract/FileSystem/IDirectoryShortInfo.cs b/Yavsc.Abstract/FileSystem/IDirectoryShortInfo.cs new file mode 100644 index 00000000..016d4bf4 --- /dev/null +++ b/Yavsc.Abstract/FileSystem/IDirectoryShortInfo.cs @@ -0,0 +1,8 @@ +namespace Yavsc.Abstract.FileSystem { + + public interface IDirectoryShortInfo + { + string Name { get; set; } + bool IsEmpty { get; set; } + } +} diff --git a/Yavsc.Abstract/FileSystem/IFileRecieved.Info.cs b/Yavsc.Abstract/FileSystem/IFileRecieved.Info.cs new file mode 100644 index 00000000..ffe7a00f --- /dev/null +++ b/Yavsc.Abstract/FileSystem/IFileRecieved.Info.cs @@ -0,0 +1,15 @@ +namespace Yavsc.Abstract.FileSystem +{ + public interface IFileRecievedInfo + { + string MimeType { get; set; } + + string DestDir { get; set; } + + string FileName { get; set; } + + bool Overriden { get; set; } + + bool QuotaOffensed { get; set; } + } +} \ No newline at end of file diff --git a/Yavsc.Abstract/FileSystem/UserDirectoryInfo.cs b/Yavsc.Abstract/FileSystem/UserDirectoryInfo.cs index c4b1c71a..963e4f08 100644 --- a/Yavsc.Abstract/FileSystem/UserDirectoryInfo.cs +++ b/Yavsc.Abstract/FileSystem/UserDirectoryInfo.cs @@ -7,15 +7,21 @@ namespace Yavsc.ViewModels.UserFiles { public class UserDirectoryInfo { - public string UserName { get; private set; } - public string SubPath { get; private set; } + public string UserName { get; set; } + public string SubPath { get; set; } public RemoteFileInfo [] Files { - get; private set; + get; set; } - public string [] SubDirectories {  - get; private set; + public DirectoryShortInfo [] SubDirectories {  + get; set; } private DirectoryInfo dInfo; + + // for deserialization + public UserDirectoryInfo() + { + + } public UserDirectoryInfo(string userReposPath, string username, string path) { if (string.IsNullOrWhiteSpace(username)) @@ -35,7 +41,12 @@ namespace Yavsc.ViewModels.UserFiles ( entry => new RemoteFileInfo { Name = entry.Name, Size = entry.Length, CreationTime = entry.CreationTime, LastModified = entry.LastWriteTime }).ToArray(); SubDirectories = dInfo.GetDirectories().Select - ( d=> d.Name ).ToArray(); + ( d=> new DirectoryShortInfo { Name= d.Name, IsEmpty=false } ).ToArray(); } } + + public class DirectoryShortInfo: IDirectoryShortInfo { + public string Name { get; set; } + public bool IsEmpty { get; set; } + } } diff --git a/Yavsc.Abstract/Makefile b/Yavsc.Abstract/Makefile index 6a29f6b9..60311884 100644 --- a/Yavsc.Abstract/Makefile +++ b/Yavsc.Abstract/Makefile @@ -1,17 +1,23 @@ CONFIG=Release -VERSION=1.0.2 +VERSION=1.0.5-rc4 PRJNAME=Yavsc.Abstract PKGFILENAME=$(PRJNAME).$(VERSION).nupkg DESTPATH=. PACKAGE=$(DESTPATH)/$(PKGFILENAME) +BINARY=bin/$(CONFIG)/net45/Yavsc.Abstract.dll +NUGETSOURCE=$(HOME)/Nupkgs/ -$(PACKAGE): - nuget pack $(PRJNAME).nuspec -Version $(VERSION) - -publish: $(PACKAGE) - cp $(PACKAGE) ~/Nupkgs +$(PACKAGE): $(BINARY) + nuget pack $(PRJNAME).nuspec -Version $(VERSION) -Properties config=$(CONFIG) clean: rm $(PACKAGE) +$(BINARY): project.lock.json + dnu build --configuration $(CONFIG) + +project.lock.json: project.json + dnu restore +deploy: $(PACKAGE) + cp $(PACKAGE) $(NUGETSOURCE) diff --git a/Yavsc.Abstract/Properties/AssemblyInfo.cs b/Yavsc.Abstract/Properties/AssemblyInfo.cs index fadca10f..616e1b27 100644 --- a/Yavsc.Abstract/Properties/AssemblyInfo.cs +++ b/Yavsc.Abstract/Properties/AssemblyInfo.cs @@ -4,15 +4,15 @@ using System.Reflection; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. -[assembly: AssemblyTitle("Yavsc.Client")] -[assembly: AssemblyDescription("")] +[assembly: AssemblyTitle("Yavsc.Abstract")] +[assembly: AssemblyDescription("Yavsc shared objects")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("Yavsc.Client")] -[assembly: AssemblyCopyright("Copyright © 2014")] +[assembly: AssemblyProduct("Yavsc.Abstract")] +[assembly: AssemblyCopyright("Copyright © 2014-2018")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] -[assembly: NeutralResourcesLanguage("en")] +[assembly: NeutralResourcesLanguage("fr")] // Version information for an assembly consists of the following four values: // @@ -24,5 +24,5 @@ using System.Reflection; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: AssemblyVersion("1.0.5.*")] +[assembly: AssemblyFileVersion("1.0.5.2")] diff --git a/Yavsc.Abstract/Yavsc.Abstract.1.0.0.nupkg b/Yavsc.Abstract/Yavsc.Abstract.1.0.0.nupkg new file mode 100644 index 00000000..4175a1ac Binary files /dev/null and b/Yavsc.Abstract/Yavsc.Abstract.1.0.0.nupkg differ diff --git a/Yavsc.Abstract/Yavsc.Abstract.1.0.3.nupkg b/Yavsc.Abstract/Yavsc.Abstract.1.0.3.nupkg new file mode 100644 index 00000000..d5387598 Binary files /dev/null and b/Yavsc.Abstract/Yavsc.Abstract.1.0.3.nupkg differ diff --git a/Yavsc.Abstract/Yavsc.Abstract.1.0.4.nupkg b/Yavsc.Abstract/Yavsc.Abstract.1.0.4.nupkg new file mode 100644 index 00000000..bd13d974 Binary files /dev/null and b/Yavsc.Abstract/Yavsc.Abstract.1.0.4.nupkg differ diff --git a/Yavsc.Abstract/Yavsc.Abstract.1.0.5-rc1.nupkg b/Yavsc.Abstract/Yavsc.Abstract.1.0.5-rc1.nupkg new file mode 100644 index 00000000..b0ceb5f0 Binary files /dev/null and b/Yavsc.Abstract/Yavsc.Abstract.1.0.5-rc1.nupkg differ diff --git a/Yavsc.Abstract/Yavsc.Abstract.1.0.5-rc2.nupkg b/Yavsc.Abstract/Yavsc.Abstract.1.0.5-rc2.nupkg new file mode 100644 index 00000000..1c92ccc2 Binary files /dev/null and b/Yavsc.Abstract/Yavsc.Abstract.1.0.5-rc2.nupkg differ diff --git a/Yavsc.Abstract/Yavsc.Abstract.1.0.5-rc3.nupkg b/Yavsc.Abstract/Yavsc.Abstract.1.0.5-rc3.nupkg new file mode 100644 index 00000000..9f88815e Binary files /dev/null and b/Yavsc.Abstract/Yavsc.Abstract.1.0.5-rc3.nupkg differ diff --git a/Yavsc.Abstract/Yavsc.Abstract.1.0.5-rc4.nupkg b/Yavsc.Abstract/Yavsc.Abstract.1.0.5-rc4.nupkg new file mode 100644 index 00000000..8e0062fa Binary files /dev/null and b/Yavsc.Abstract/Yavsc.Abstract.1.0.5-rc4.nupkg differ diff --git a/Yavsc.Abstract/Yavsc.Abstract.nuspec b/Yavsc.Abstract/Yavsc.Abstract.nuspec index dbe88946..feb13a19 100644 --- a/Yavsc.Abstract/Yavsc.Abstract.nuspec +++ b/Yavsc.Abstract/Yavsc.Abstract.nuspec @@ -18,6 +18,6 @@ yavsc - + diff --git a/Yavsc.Abstract/project.json b/Yavsc.Abstract/project.json index 5020dc7f..ef84b246 100644 --- a/Yavsc.Abstract/project.json +++ b/Yavsc.Abstract/project.json @@ -1,5 +1,5 @@ { - "version": "1.0.2", + "version": "1.0.5", "description": "Yavsc Client Api", "authors": [ "Paul Schneider" diff --git a/Yavsc/ApiControllers/FileSystemApiController.cs b/Yavsc/ApiControllers/FileSystemApiController.cs index 66bbbfe0..0e3b5115 100644 --- a/Yavsc/ApiControllers/FileSystemApiController.cs +++ b/Yavsc/ApiControllers/FileSystemApiController.cs @@ -10,8 +10,11 @@ using Yavsc.Models; namespace Yavsc.ApiControllers { using System.Threading.Tasks; + using Microsoft.Extensions.Logging; using Yavsc.Abstract.FileSystem; using Yavsc.Exceptions; + using Yavsc.Models.FileSystem; + public class FSQuotaException : Exception { } @@ -21,12 +24,16 @@ namespace Yavsc.ApiControllers { ApplicationDbContext dbContext; private IAuthorizationService AuthorizationService; + private ILogger logger; + public FileSystemApiController(ApplicationDbContext context, - IAuthorizationService authorizationService) + IAuthorizationService authorizationService, + ILoggerFactory loggerFactory) { AuthorizationService = authorizationService; dbContext = context; + logger = loggerFactory.CreateLogger(); } [HttpGet()] @@ -46,11 +53,11 @@ namespace Yavsc.ApiControllers } [HttpPost] - public IEnumerable Post(string subdir="", string names = null) + public IActionResult Post(string subdir="", string names = null) { string root = null; string [] destinationFileNames = names?.Split('/'); - + List received = new List(); InvalidPathException pathex = null; try { root = User.InitPostToFileSystem(subdir); @@ -58,20 +65,26 @@ namespace Yavsc.ApiControllers pathex = ex; } if (pathex!=null) - yield return new BadRequestObjectResult(pathex); - + return new BadRequestObjectResult(pathex); + var uid = User.GetUserId(); var user = dbContext.Users.Single( - u => u.Id == User.GetUserId() + u => u.Id == uid ); int i=0; + logger.LogInformation($"Recieving {Request.Form.Files.Count} files."); foreach (var f in Request.Form.Files) { var destFileName = destinationFileNames?.Length >i ? destinationFileNames[i] : null; var item = user.ReceiveUserFile(root, f, destFileName); dbContext.SaveChanges(User.GetUserId()); - yield return Ok(item); + received.Add(item); + logger.LogInformation($"Recieved '{item.FileName}'."); + if (item.QuotaOffensed) + break; + i++; }; + return Ok(received); } [HttpDelete] diff --git a/Yavsc/Helpers/FileSystemHelpers.cs b/Yavsc/Helpers/FileSystemHelpers.cs index 56a38294..631793bb 100644 --- a/Yavsc/Helpers/FileSystemHelpers.cs +++ b/Yavsc/Helpers/FileSystemHelpers.cs @@ -4,10 +4,8 @@ using System; using System.Drawing; using System.Drawing.Imaging; using System.IO; -using System.Linq; using System.Net.Mime; using System.Security.Claims; -using System.Text; using System.Web; using Microsoft.AspNet.Http; using Yavsc.Abstract.FileSystem; @@ -31,22 +29,7 @@ namespace Yavsc.Helpers return di; } - // Ensure this path is canonical, - // No "dirto/./this", neither "dirt/to/that/" - // no .. and each char must be listed as valid in constants - public static string FilterFileName(string fileName) - { - if (fileName==null) return null; - StringBuilder sb = new StringBuilder(); - foreach (var c in fileName) - { - if (FileSystemConstants.ValidFileNameChars.Contains(c)) - sb.Append(c); - else sb.Append('_'); - } - return sb.ToString(); - } public static string InitPostToFileSystem( this ClaimsPrincipal user, string subpath) @@ -81,10 +64,14 @@ namespace Yavsc.Helpers var item = new FileRecievedInfo(); // form-data; name="file"; filename="capt0008.jpg" ContentDisposition contentDisposition = new ContentDisposition(f.ContentDisposition); - item.FileName = FilterFileName (destFileName ?? contentDisposition.FileName); + item.FileName = Yavsc.Abstract.FileSystem.FileSystemHelpers.FilterFileName (destFileName ?? contentDisposition.FileName); item.MimeType = contentDisposition.DispositionType; var fi = new FileInfo(Path.Combine(root, item.FileName)); - if (fi.Exists) item.Overriden = true; + if (fi.Exists) + { + item.Overriden = true; + usage -= fi.Length; + } using (var dest = fi.OpenWrite()) { using (var org = f.OpenReadStream()) @@ -92,7 +79,7 @@ namespace Yavsc.Helpers byte[] buffer = new byte[1024]; long len = org.Length; if (len > (user.DiskQuota - usage)) { - + item.QuotaOffensed = true; return item; } usage += len; diff --git a/Yavsc/Models/FileSystem/FileRecievedInfo.cs b/Yavsc/Models/FileSystem/FileRecievedInfo.cs index 73bec448..d8609404 100644 --- a/Yavsc/Models/FileSystem/FileRecievedInfo.cs +++ b/Yavsc/Models/FileSystem/FileRecievedInfo.cs @@ -21,13 +21,23 @@ // along with this program. If not, see . +using Yavsc.Abstract.FileSystem; + namespace Yavsc.Models.FileSystem { - public class FileRecievedInfo + public class FileRecievedInfo : IFileRecievedInfo + { + public FileRecievedInfo() { - public string MimeType { get; set; } - public string DestDir { get; set; } - public string FileName { get; set; } - public bool Overriden { get; set; } + QuotaOffensed = Overriden = false; + MimeType = DestDir = FileName = null; } + + public string MimeType { get; set; } + public string DestDir { get; set; } + public string FileName { get; set; } + public bool Overriden { get; set; } + + public bool QuotaOffensed { get; set; } + } } \ No newline at end of file diff --git a/Yavsc/Startup/Startup.FileServer.cs b/Yavsc/Startup/Startup.FileServer.cs index 78b806fe..9551ba7f 100644 --- a/Yavsc/Startup/Startup.FileServer.cs +++ b/Yavsc/Startup/Startup.FileServer.cs @@ -28,7 +28,8 @@ namespace Yavsc { FileProvider = new PhysicalFileProvider(UserFilesDirName), RequestPath = new PathString(Constants.UserFilesPath), - EnableDirectoryBrowsing = env.IsDevelopment() + EnableDirectoryBrowsing = env.IsDevelopment(), + }; UserFilesOptions.EnableDefaultFiles=true; diff --git a/Yavsc/Views/Blogspot/Index.cshtml b/Yavsc/Views/Blogspot/Index.cshtml index d126760a..a6cde23e 100644 --- a/Yavsc/Views/Blogspot/Index.cshtml +++ b/Yavsc/Views/Blogspot/Index.cshtml @@ -67,21 +67,17 @@
-@first.Title +

@if (first.Photo==null) { } else {@first.Title}
- @((first.Content?.Length > 120) ? first.Content.Substring(0, 120) + " ..." : first.Content) - (@first.Author.UserName , - - posté le @first.DateCreated.ToString("dddd d MMM yyyy à H:mm") +
+
@first.Author.UserName , + (posté le @first.DateCreated.ToString("dddd d MMM yyyy à H:mm") @if ((first.DateModified - first.DateCreated).Minutes > 0){  @:- Modifié le @first.DateModified.ToString("dddd d MMM yyyy à H:mm",System.Globalization.CultureInfo.CurrentUICulture) - }) - - - + })
    diff --git a/Yavsc/Views/Blogspot/Title.cshtml b/Yavsc/Views/Blogspot/Title.cshtml index 688b3dfb..1073a7bb 100644 --- a/Yavsc/Views/Blogspot/Title.cshtml +++ b/Yavsc/Views/Blogspot/Title.cshtml @@ -30,7 +30,7 @@ - @((item.Content?.Length > 120) ? item.Content.Substring(0, 122) + " ..." : item.Content) + @((item.Content?.Length > 256) ? item.Content.Substring(0, 256) + " ..." : item.Content) (@item.Author.UserName , posté le @item.DateCreated.ToString("dddd d MMM yyyy à H:mm") diff --git a/Yavsc/Views/Manage/Index.cshtml b/Yavsc/Views/Manage/Index.cshtml index 09fa504d..ffd1769b 100755 --- a/Yavsc/Views/Manage/Index.cshtml +++ b/Yavsc/Views/Manage/Index.cshtml @@ -142,7 +142,7 @@ @if (Model.DiskQuota>0) { - @((Model.DiskUsage/Model.DiskQuota).ToString("%#0")) : + @(((double)Model.DiskUsage/Model.DiskQuota).ToString("%#0")) : } diff --git a/Yavsc/Views/Shared/Components/Directory/Default.cshtml b/Yavsc/Views/Shared/Components/Directory/Default.cshtml index 8155dc3a..c36b5583 100644 --- a/Yavsc/Views/Shared/Components/Directory/Default.cshtml +++ b/Yavsc/Views/Shared/Components/Directory/Default.cshtml @@ -3,8 +3,8 @@
    @Model.UserName / @Model.SubPath
    -@foreach (string subdir in Model.SubDirectories) { -@subdir +@foreach (var subdir in Model.SubDirectories) { +@subdir.Name }