Ejemplo n.º 1
0
        public async Task <FullPath> ParsePathAsync(string target)
        {
            if (string.IsNullOrEmpty(target))
            {
                return(null);
            }

            int    underscoreIndex = target.IndexOf('_');
            string pathHash        = target.Substring(underscoreIndex + 1);
            string volumePrefix    = target.Substring(0, underscoreIndex + 1);

            var    root          = Roots.First(r => r.VolumeId == volumePrefix);
            var    rootDirectory = new DirectoryInfo(root.RootDirectory);
            string path          = HttpEncoder.DecodePath(pathHash);
            string dirUrl        = path != rootDirectory.Name ? path : string.Empty;
            var    dir           = new FileSystemDirectory(root.RootDirectory + dirUrl);

            if (await dir.ExistsAsync)
            {
                return(new FullPath(root, dir, target));
            }
            else
            {
                var file = new FileSystemFile(root.RootDirectory + dirUrl);
                return(new FullPath(root, file, target));
            }
        }
Ejemplo n.º 2
0
        public async Task <FullPath> ParsePathAsync(string target)
        {
            if (string.IsNullOrEmpty(target))
            {
                return(null);
            }

            string volumePrefix = null;
            string pathHash     = null;

            for (int i = 0; i < target.Length; i++)
            {
                if (target[i] == '_')
                {
                    pathHash     = target.Substring(i + 1);
                    volumePrefix = target.Substring(0, i + 1);
                    break;
                }
            }

            var    root   = Roots.First(r => r.VolumeId == volumePrefix);
            string path   = HttpEncoder.DecodePath(pathHash);
            string dirUrl = path != root.RootDirectory ? path : string.Empty;
            var    dir    = new AzureStorageDirectory(root.RootDirectory + dirUrl);

            if (await dir.ExistsAsync)
            {
                return(new FullPath(root, dir, target));
            }
            else
            {
                var file = new AzureStorageFile(root.RootDirectory + dirUrl);
                return(new FullPath(root, file, target));
            }
        }
Ejemplo n.º 3
0
        public async Task <JsonResult> InitAsync(FullPath path, IEnumerable <string> mimeTypes)
        {
            if (path == null)
            {
                var root = Roots.FirstOrDefault(r => r.StartDirectory != null);
                if (root == null)
                {
                    root = Roots.First();
                }

                path = new FullPath(root, new FileSystemDirectory(root.StartDirectory ?? root.RootDirectory), null);
            }

            var response = new InitResponseModel(await BaseModel.CreateAsync(path.Directory, path.RootVolume), new Options(path));

            foreach (var item in await path.Directory.GetFilesAsync(mimeTypes))
            {
                if (!item.Attributes.HasFlag(FileAttributes.Hidden))
                {
                    response.Files.Add(await BaseModel.CreateAsync(item, path.RootVolume));
                }
            }
            foreach (var item in await path.Directory.GetDirectoriesAsync())
            {
                if (!item.Attributes.HasFlag(FileAttributes.Hidden))
                {
                    response.Files.Add(await BaseModel.CreateAsync(item, path.RootVolume));
                }
            }

            foreach (var item in Roots)
            {
                response.Files.Add(await BaseModel.CreateAsync(new FileSystemDirectory(item.RootDirectory), item));
            }

            if (path.RootVolume.RootDirectory != path.Directory.FullName)
            {
                var dirInfo = new DirectoryInfo(path.RootVolume.RootDirectory);
                foreach (var item in dirInfo.GetDirectories())
                {
                    var attributes = item.Attributes;
                    if (!attributes.HasFlag(FileAttributes.Hidden))
                    {
                        response.Files.Add(await BaseModel.CreateAsync(new FileSystemDirectory(item), path.RootVolume));
                    }
                }
            }

            if (path.RootVolume.MaxUploadSize.HasValue)
            {
                response.Options.UploadMaxSize = $"{path.RootVolume.MaxUploadSizeInKb.Value}K";
            }
            return(await Json(response));
        }
Ejemplo n.º 4
0
        public async Task <FullPath> ParsePathAsync(string target)
        {
            if (string.IsNullOrEmpty(target))
            {
                return(null);
            }

            var split = StringHelpers.Split('_', target);

            var root   = Roots.First(r => r.VolumeId == split.Prefix);
            var path   = HttpEncoder.DecodePath(split.Content);
            var dirUrl = path != root.RootDirectory ? path : string.Empty;
            var dir    = new AzureBlobDirectory(root.RootDirectory + dirUrl);

            if (await dir.ExistsAsync)
            {
                return(new FullPath(root, dir, target));
            }

            var file = new AzureBlobFile(root.RootDirectory + dirUrl);

            return(new FullPath(root, file, target));
        }
Ejemplo n.º 5
0
        public async Task <JsonResult> InitAsync(FullPath path, IEnumerable <string> mimeTypes)
        {
            if (path == null)
            {
                var root = Roots.FirstOrDefault(r => r.StartDirectory != null);
                if (root == null)
                {
                    root = Roots.First();
                }

                path = new FullPath(root, new AzureStorageDirectory(root.StartDirectory ?? root.RootDirectory), null);
            }

            var response = new InitResponseModel(await BaseModel.CreateAsync(path.Directory, path.RootVolume), new Options(path));

            // Get all files and directories
            var items = await AzureStorageAPI.ListFilesAndDirectoriesAsync(path.Directory.FullName);

            // Add visible files
            foreach (var file in items.Where(i => i is CloudFile))
            {
                var f = new AzureStorageFile(file as CloudFile);
                if (!f.Attributes.HasFlag(FileAttributes.Hidden))
                {
                    if (mimeTypes != null && mimeTypes.Count() > 0 && !mimeTypes.Contains(f.MimeType) && !mimeTypes.Contains(f.MimeType.Type))
                    {
                        continue;
                    }

                    response.Files.Add(await BaseModel.CreateAsync(f, path.RootVolume));
                }
            }

            // Add visible directories
            foreach (var dir in items.Where(i => i is CloudFileDirectory))
            {
                var d = new AzureStorageDirectory(dir as CloudFileDirectory);
                if (!d.Attributes.HasFlag(FileAttributes.Hidden))
                {
                    response.Files.Add(await BaseModel.CreateAsync(d, path.RootVolume));
                }
            }

            // Add roots
            foreach (var root in Roots)
            {
                response.Files.Add(await BaseModel.CreateAsync(new AzureStorageDirectory(root.RootDirectory), root));
            }

            if (path.RootVolume.RootDirectory != path.Directory.FullName)
            {
                // Get all files and directories
                var entries = await AzureStorageAPI.ListFilesAndDirectoriesAsync(path.RootVolume.RootDirectory);

                // Add visible directories
                foreach (var dir in entries.Where(i => i is CloudFileDirectory))
                {
                    var d = new AzureStorageDirectory(dir as CloudFileDirectory);
                    if (!d.Attributes.HasFlag(FileAttributes.Hidden))
                    {
                        response.Files.Add(await BaseModel.CreateAsync(d, path.RootVolume));
                    }
                }
            }

            if (path.RootVolume.MaxUploadSize.HasValue)
            {
                response.Options.UploadMaxSize = $"{path.RootVolume.MaxUploadSizeInKb.Value}K";
            }

            return(await Json(response));
        }
Ejemplo n.º 6
0
        public async Task <JsonResult> InitAsync(FullPath path, IEnumerable <string> mimeTypes)
        {
            if (path == null)
            {
                var root = Roots.FirstOrDefault(r => r.StartDirectory != null) ?? Roots.First();

                path = new FullPath(root, new AzureBlobDirectory(root.StartDirectory ?? root.RootDirectory), null);
            }

            // todo: BaseModel.CreateAsync internally calls GetDirectoriesAsync() which calls AzureBlobStorageApi.ListFilesAndDirectoriesAsync
            // todo: AzureBlobStorageApi.ListFilesAndDirectoriesAsync is then called again here few lines below;
            // todo: we should be able to reduce it to one single call
            var response = new InitResponseModel(await BaseModel.CreateAsync(path.Directory, path.RootVolume), new Options(path));

            // Get all files and directories
            var items    = AzureBlobStorageApi.ListFilesAndDirectoriesAsync(path.Directory.FullName);
            var itemList = items.ToList();

            // Add visible files
            foreach (var file in itemList.Where(i => !i.Name.EndsWith("/")))
            {
                var f = new AzureBlobFile(file);

                if (f.Attributes.HasFlag(FileAttributes.Hidden))
                {
                    continue;
                }

                var mimeTypesList = mimeTypes.ToList();

                if (mimeTypesList.Any() && !mimeTypesList.Contains(f.MimeType) && !mimeTypesList.Contains(f.MimeType.Type))
                {
                    continue;
                }

                response.Files.Add(await CustomBaseModel.CustomCreateAsync(f, path.RootVolume));
            }

            // Add visible directories
            foreach (var dir in itemList.Where(i => i.Name.EndsWith("/")))
            {
                var d = new AzureBlobDirectory(dir);

                if (!d.Attributes.HasFlag(FileAttributes.Hidden))
                {
                    response.Files.Add(await BaseModel.CreateAsync(d, path.RootVolume));
                }
            }

            // Add roots
            foreach (var root in Roots)
            {
                response.Files.Add(await BaseModel.CreateAsync(new AzureBlobDirectory(root.RootDirectory), root));
            }

            if (path.RootVolume.RootDirectory != path.Directory.FullName)
            {
                // Get all files and directories
                var entries = AzureBlobStorageApi.ListFilesAndDirectoriesAsync(path.RootVolume.RootDirectory);

                // Add visible directories
                foreach (var dir in entries.Where(i => i.Name.EndsWith("/")))
                {
                    var d = new AzureBlobDirectory(dir);

                    if (!d.Attributes.HasFlag(FileAttributes.Hidden))
                    {
                        response.Files.Add(await BaseModel.CreateAsync(d, path.RootVolume));
                    }
                }
            }

            if (path.RootVolume.MaxUploadSizeInKb.HasValue)
            {
                response.Options.UploadMaxSize = $"{path.RootVolume.MaxUploadSizeInKb.Value}K";
            }

            return(await Json(response));
        }
Ejemplo n.º 7
0
 string FindRootPath(string path)
 {
     return(Roots.First(path.StartsWith));
 }