public static FolderItemInfo GetInfo(InternalFolder folder, DirectoryInfo info) { int count; long size; if (info == null) { GetFileCountAndSize(out count, out size); } else { GetFileCountAndSize(info, out count, out size); } return(new FolderItemInfo() { Name = folder.Name, Path = folder.VirtualPath, SharedId = folder.SharedId, Permission = folder.Permission, Deletable = info != null && info.FullName != info.Root.FullName, FileCount = count, Size = size, LastAccessTime = info?.LastAccessTime ?? DateTime.MinValue, LastWriteTime = info?.LastWriteTime ?? DateTime.MinValue, CreationTime = info?.CreationTime ?? DateTime.MinValue, Attributes = info?.Attributes ?? FileAttributes.Directory, }); }
private async Task <InternalFolder> ValidateAddFolderShare(AddFolderShareBody body) { if (string.IsNullOrWhiteSpace(body.Name)) { throw (HttpResultException)BadRequest("Name missing"); } string userId = HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); InternalFolder folder = await ShareFolderHelper.GetFolderItem(body.Path, dbContext, userId, this); if (folder == null) { throw (HttpResultException)NotFound("Base not found"); } if (!HasPermission(folder.Permission, body.Permission)) { throw (HttpResultException)Forbid(); } if (!string.IsNullOrWhiteSpace(folder.PhysicalPath) && !System.IO.Directory.Exists(folder.PhysicalPath)) { throw (HttpResultException)NotFound("Folder not found"); } if (body.UserId != null && !await dbContext.Users.AnyAsync(u => u.Id == body.UserId)) { throw (HttpResultException)BadRequest("User not found"); } return(folder); }
private static IEnumerable <FileItem> GetFiles(InternalFolder folder) { if (string.IsNullOrWhiteSpace(folder.PhysicalPath)) { return(new FileItem[0]); } return(Directory.EnumerateFiles(folder.PhysicalPath).Select(GetFileItem)); FileItem GetFileItem(string path) { string name = Path.GetFileName(path); return(new FileItem() { Name = name, Extension = Path.GetExtension(path), Path = Path.Join(folder.VirtualPath, name), SharedId = null, Permission = (FileItemPermission)folder.Permission, }); } }
private static IEnumerable <FolderItem> GetFolders(InternalFolder folder) { if (string.IsNullOrWhiteSpace(folder.PhysicalPath)) { return(DriveInfo.GetDrives().Where(d => d.IsReady).Select(d => new FolderItem() { Name = d.Name, Path = Path.Join(folder.VirtualPath, d.Name), SharedId = null, Permission = folder.Permission, Deletable = false, })); } return(Directory.EnumerateDirectories(folder.PhysicalPath).Select(p => new FolderItem() { Name = Path.GetFileName(p), Path = Path.Join(folder.VirtualPath, Path.GetFileName(p)), SharedId = null, Permission = folder.Permission, Deletable = true, })); }
public static PathPart[] GetPathParts(InternalFolder folder) { return(GetPathParts(folder.VirtualPath, folder.BaseName)); }