private Connector GetConnector() { var driver = new AzureBlobDriver(); var absoluteUrl = UriHelper.BuildAbsolute(Request.Scheme, Request.Host); var uri = new Uri(absoluteUrl); var root = new RootVolume($"{AzureBlobStorageApi.ContainerName}", $"{AzureBlobStorageApi.OriginHostName}/{AzureBlobStorageApi.ContainerName}/", $"{uri.Scheme}://{uri.Authority}/el-finder/azure-blob-storage/thumb/", '/') { ThumbnailSize = _thumbnailSize, //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 //MaxUploadSizeInMb = 85, // Comment it to taker thw web.config value //LockedFolders = new List<string>(new string[] { "Folder1" }) }; driver.AddRoot(root); return(new Connector(driver)); }
private static byte GetFlag(this IFile file, RootVolume volume, Func <AccessControlAttributeSet, bool> fieldSelector) { if (volume.AccessControlAttributes != null) { var attributeSet = volume.AccessControlAttributes.FirstOrDefault(x => x.FullName == file.FullName); if (attributeSet != null) { return(fieldSelector(attributeSet) ? (byte)1 : (byte)0); } var parentDirectory = file.Directory; while (parentDirectory != null && parentDirectory.FullName != volume.RootDirectory) { attributeSet = volume.AccessControlAttributes.FirstOrDefault(x => x.FullName == parentDirectory.FullName); if (attributeSet != null) { return(fieldSelector(attributeSet) ? (byte)1 : (byte)0); } parentDirectory = parentDirectory.Parent; } } return(fieldSelector(volume.DefaultAccessControlAttributes) ? (byte)1 : (byte)0); }
public FileSystemDriver GetFileSystemDriver(RootVolume rootVolume) { var driver = new FileSystemDriver(); driver.AddRoot(rootVolume); return(driver); }
private Connector GetConnector() { var driver = new FileSystemDriver(); string absoluteUrl = UriHelper.BuildAbsolute(Request.Scheme, Request.Host); var uri = new Uri(absoluteUrl); var root = new RootVolume( Startup.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 //LockedFolders = new List<string>(new string[] { "Folder1" }) }; driver.AddRoot(root); return(new Connector(driver) { // This allows support for the "onlyMimes" option on the client. MimeDetect = MimeDetectOption.Internal }); }
public FileDestinationMetadata(RootVolume rootVolume = null, string sourceUrl = null, string rootPath = null) { RootVolume = rootVolume; SourceUrl = sourceUrl; RootPath = rootPath; }
private Connector GetConnector() { var driver = new AzureStorageDriver(); string absoluteUrl = UriHelper.BuildAbsolute(Request.Scheme, Request.Host); var uri = new Uri(absoluteUrl); string rootDirectory = "test"; // TODO: Change this to the name of your own Azure file share. var root = new RootVolume( rootDirectory, $"{uri.Scheme}://{uri.Authority}/el-finder/azure-storage/files/{rootDirectory}/", $"{uri.Scheme}://{uri.Authority}/el-finder/azure-storage/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 //LockedFolders = new List<string>(new string[] { "Folder1" }) }; driver.AddRoot(root); return(new Connector(driver) { // This allows support for the "onlyMimes" option on the client. //MimeDetect = MimeDetectOption.Internal }); }
public static byte GetLockedFlag(this IDirectory directory, RootVolume volume) { if (volume.IsLocked) { return(1); } return(GetFlag(directory, volume, x => x.Locked)); }
public static byte GetWriteFlag(this IDirectory directory, RootVolume volume) { if (volume.IsReadOnly) { return(0); } return(GetFlag(directory, volume, x => x.Write)); }
public static async Task <FileModel> CreateAsync(IFile file, RootVolume volume) { if (file == null) { throw new ArgumentNullException("file"); } if (volume == null) { throw new ArgumentNullException("volume"); } await file.RefreshAsync(); string parentPath = file.DirectoryName.Substring(volume.RootDirectory.Length); string relativePath = file.FullName.Substring(volume.RootDirectory.Length); var fileLength = await file.LengthAsync; FileModel response; if (volume.CanCreateThumbnail(file) && fileLength > 0) { using (var stream = await file.OpenReadAsync()) { try { var dim = volume.PictureEditor.ImageSize(stream); response = new ImageModel { Thumbnail = await volume.GenerateThumbHashAsync(file), Dimension = $"{dim.Width}x{dim.Height}" }; } catch { // Fix for non-standard formats // https://github.com/gordon-matt/elFinder.NetCore/issues/36 response = new FileModel(); } } } else { response = new FileModel(); } response.Read = file.GetReadFlag(volume); response.Write = file.GetWriteFlag(volume); response.Locked = file.GetLockedFlag(volume); response.Name = file.Name; response.Size = fileLength; response.UnixTimeStamp = (long)(await file.LastWriteTimeUtcAsync - unixOrigin).TotalSeconds; response.Mime = MimeHelper.GetMimeType(file.Extension); response.Hash = volume.VolumeId + HttpEncoder.EncodePath(relativePath); response.ParentHash = volume.VolumeId + HttpEncoder.EncodePath(parentPath.Length > 0 ? parentPath : file.Directory.Name); return(response); }
public static byte GetWriteFlag(this IFile file, RootVolume volume) { if (volume.IsReadOnly) { return(0); } return(GetFlag(file, volume, x => x.Write)); }
public static byte GetLockedFlag(this IFile file, RootVolume volume) { if (volume.IsLocked) { return(1); } return(GetFlag(file, volume, x => x.Locked)); }
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("~/Uploads"), $"{uri.Scheme}://{uri.Authority}/Uploads/", $"{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>() { new NamedAccessControlAttributeSet(PathHelper.MapPath("~/Uploads/readonly.txt")) { Write = false, Locked = true }, new NamedAccessControlAttributeSet(PathHelper.MapPath("~/Uploads/Prohibited")) { Read = false, Write = false, Locked = true }, new NamedAccessControlAttributeSet(PathHelper.MapPath("~/Uploads/Parent/Children")) { Read = true, Write = false, Locked = true } } }; driver.AddRoot(root); return(new Connector(driver) { // This allows support for the "onlyMimes" option on the client. MimeDetect = MimeDetectOption.Internal }); }
public static async Task <FileModel> CreateAsync(IFile file, RootVolume volume) { if (file == null) { throw new ArgumentNullException("file"); } if (volume == null) { throw new ArgumentNullException("volume"); } string parentPath = file.DirectoryName.Substring(volume.RootDirectory.Length); string relativePath = file.FullName.Substring(volume.RootDirectory.Length); var fileLength = await file.LengthAsync; FileModel response; if (volume.CanCreateThumbnail(file) && fileLength > 0) { using (var stream = await file.OpenReadAsync()) { var dim = volume.PictureEditor.ImageSize(stream); response = new ImageModel { Thumbnail = await volume.GenerateThumbHashAsync(file), Dimension = $"{dim.Width}x{dim.Height}" }; } } else { response = new FileModel(); } response.Read = 1; response.Write = volume.IsReadOnly ? (byte)0 : (byte)1; response.Locked = ((volume.LockedFolders != null && volume.LockedFolders.Any(f => f == file.Directory.Name)) || volume.IsLocked) ? (byte)1 : (byte)0; response.Name = file.Name; response.Size = fileLength; response.UnixTimeStamp = (long)(await file.LastWriteTimeUtcAsync - unixOrigin).TotalSeconds; response.Mime = MimeHelper.GetMimeType(file.Extension); response.Hash = volume.VolumeId + HttpEncoder.EncodePath(relativePath); response.ParentHash = volume.VolumeId + HttpEncoder.EncodePath(parentPath.Length > 0 ? parentPath : file.Directory.Name); return(response); }
protected RootVolume GetRootVolume() { var leftPart = GetAuthorityLeftPart(); var root = new RootVolume( Startup.MapPath($"~/{Settings.Instance.UploadFolderPath}"), $"{leftPart}/{Settings.Instance.UploadFolderPath}/", $"{leftPart}/{ApiEndpoint.FILE_API}/thumb/") { ThumbnailSize = 256, //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 = "home", // Beautiful name given to the root/home folder //MaxUploadSizeInKb = 2048, // Limit imposed to user uploaded file <= 2048 KB //LockedFolders = new List<string>(new string[] { "Folder1" }) }; return(root); }
private Connector GetConnector() { var driver = new AzureStorageDriver(); string absoluteUrl = UriHelper.BuildAbsolute(Request.Scheme, Request.Host); var uri = new Uri(absoluteUrl); var root = new RootVolume( "test", $"http://{uri.Authority}/Files/", $"http://{uri.Authority}/el-finder/azure-storage/thumb/") { //IsReadOnly = !User.IsInRole("Administrators") IsReadOnly = false, // Can be readonly according to user's membership permission Alias = "Files", // Beautiful name given to the root/home folder MaxUploadSizeInKb = 500, // Limit imposed to user uploaded file <= 500 KB //LockedFolders = new List<string>(new string[] { "Folder1" }) }; driver.AddRoot(root); return(new Connector(driver)); }
private Connector GetConnector(string folderPath = "", string folderName = "Files") { var driver = new FileSystemDriver(); string absoluteUrl = UriHelper.BuildAbsolute(Request.Scheme, Request.Host); var uri = new Uri(absoluteUrl); folderPath = folderPath != "" ? ("/" + folderPath) : ""; var root = new RootVolume( Startup.MapPath($"~/Files{folderPath}"), $"http://{uri.Authority}/Files/{folderPath}", $"http://{uri.Authority}/el-finder/file-system/thumb/") { //IsReadOnly = !User.IsInRole("Administrators") IsReadOnly = false, // Can be readonly according to user's membership permission Alias = folderName, // Beautiful name given to the root/home folder MaxUploadSizeInKb = 500, // Limit imposed to user uploaded file <= 500 KB //LockedFolders = new List<string>(new string[] { "Folder1" }) }; driver.AddRoot(root); return(new Connector(driver)); }
private Connector GetConnector() { // Thư mục gốc lưu trữ là wwwwroot/files (đảm bảo có tạo thư mục này) string pathroot = "files"; var driver = new FileSystemDriver(); string absoluteUrl = UriHelper.BuildAbsolute(Request.Scheme, Request.Host); var uri = new Uri(absoluteUrl); // .. ... wwww/files string rootDirectory = Path.Combine(environment.WebRootPath, pathroot); // https://localhost:5001/files/ string url = $"{uri.Scheme}://{uri.Authority}/{pathroot}/"; string urlthumb = $"{uri.Scheme}://{uri.Authority}/file-system/thumb/"; var root = new RootVolume(rootDirectory, url, urlthumb) { 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 //LockedFolders = new List<string>(new string[] { "Folder1" } ThumbnailSize = 100, }; driver.AddRoot(root); return(new Connector(driver) { MimeDetect = MimeDetectOption.Internal }); }
public static byte GetReadFlag(this IDirectory directory, RootVolume volume) { return(GetFlag(directory, volume, x => x.Read)); }
/// <summary> /// Adds an object to the end of the roots. /// </summary> /// <param name="item"></param> public void AddRoot(RootVolume item) { Roots.Add(item); item.VolumeId = $"{VolumePrefix}{Roots.Count}_"; }
public static byte GetReadFlag(this IFile file, RootVolume volume) { return(GetFlag(file, volume, x => x.Read)); }
public static async Task <BaseModel> CreateAsync(IDriver driver, IDirectory directory, RootVolume volume) { if (directory == null) { throw new ArgumentNullException("directory"); } if (volume == null) { throw new ArgumentNullException("volume"); } if (volume.RootDirectory == directory.FullName) { bool hasSubdirs = false; var subdirs = await directory.GetDirectoriesAsync(); foreach (var item in subdirs) { if (!item.Attributes.HasFlag(FileAttributes.Hidden)) { hasSubdirs = true; break; } } var response = new RootModel { Mime = "directory", Dirs = hasSubdirs ? (byte)1 : (byte)0, Hash = volume.VolumeId + HttpEncoder.EncodePath(directory.Name), Read = 1, Write = volume.IsReadOnly ? (byte)0 : (byte)1, Locked = volume.IsLocked ? (byte)1 : (byte)0, Name = volume.Alias, Size = 0, UnixTimeStamp = (long)(DateTime.UtcNow - unixOrigin).TotalSeconds, VolumeId = volume.VolumeId }; return(response); } else { string parentPath = directory.Parent.FullName.Substring(volume.RootDirectory.Length); string relativePath = directory.FullName.Substring(volume.RootDirectory.Length).TrimEnd(Path.DirectorySeparatorChar); var response = new DirectoryModel { Mime = "directory", ContainsChildDirs = (await directory.GetDirectoriesAsync()).Count() > 0 ? (byte)1 : (byte)0, Hash = volume.VolumeId + HttpEncoder.EncodePath(relativePath), Read = 1, Write = volume.IsReadOnly ? (byte)0 : (byte)1, Locked = ((volume.LockedFolders != null && volume.LockedFolders.Any(f => f == directory.Name)) || volume.IsLocked) ? (byte)1 : (byte)0, Size = 0, Name = directory.Name, UnixTimeStamp = (long)(await directory.LastWriteTimeUtcAsync - unixOrigin).TotalSeconds, ParentHash = volume.VolumeId + HttpEncoder.EncodePath(parentPath.Length > 0 ? parentPath : directory.Parent.Name) }; return(response); } }
public static async Task <CustomFileModel> CustomCreateAsync(ICustomFile file, RootVolume volume) { if (file == null) { throw new ArgumentNullException(nameof(file)); } if (volume == null) { throw new ArgumentNullException(nameof(volume)); } var parentPath = file.DirectoryName.Substring(volume.RootDirectory.Length); var relativePath = file.FullName.Substring(volume.RootDirectory.Length); var fileProperties = await file.PropertiesAsync; var response = new CustomFileModel { UnixTimeStamp = (long)(fileProperties.LastModified.DateTime - unixOrigin).TotalSeconds, Read = 1, Write = volume.IsReadOnly ? (byte)0 : (byte)1, Locked = volume.LockedFolders != null && volume.LockedFolders.Any(f => f == file.Directory.Name) || volume.IsLocked ? (byte)1 : (byte)0, Name = file.Name, Size = fileProperties.ContentLength, Mime = MimeHelper.GetMimeType(file.Extension), Hash = volume.VolumeId + HttpEncoder.EncodePath(relativePath), ParentHash = volume.VolumeId + HttpEncoder.EncodePath(parentPath.Length > 0 ? parentPath : file.Directory.Name) }; // We don't download and create thumbnails for files bigger than 2Mb if (!volume.CanCreateThumbnail(file) || fileProperties.ContentLength <= 0L || fileProperties.ContentLength > 2000000) { return(response); } var filePath = $"{file.Directory.FullName}/{Path.GetFileNameWithoutExtension(file.Name)}"; // Remove first segment of the path before the first '/' filePath = filePath.Substring(filePath.IndexOf('/')); // Add ticks to be sure that the thumbnail will be re-created if an image with the same filename will be uploaded again var str = filePath + "_" + fileProperties.CreatedOn.Ticks + file.Extension; response.Thumbnail = HttpEncoder.EncodePath(str); return(response); }
/// <summary> /// Adds an object to the end of the roots. /// </summary> /// <param name="item"></param> public void AddRoot(RootVolume item) { Roots.Add(item); item.VolumeId = VolumePrefix + Roots.Count + "_"; }