示例#1
0
        public override async Task <IResponseWriter> Execute()
        {
            Dictionary <string, FsItemSize> result = new Dictionary <string, FsItemSize>();

            int  TotalDirectoryCount = 0;
            int  TotalFileCount      = 0;
            long TotalSize           = 0;

            foreach (var item in Targets.Values)
            {
                var volume = ElFinder.GetVolume(item);
                var size   = await volume.GetSize(item);

                result.Add(item, size);
                TotalDirectoryCount += size.DirectoryCount;
                TotalFileCount      += size.FileCount;
                TotalSize           += size.Size;
            }

            return(new JsonResponseWriter(new
            {
                dirCnt = TotalDirectoryCount,
                fileCnt = TotalFileCount,
                size = TotalSize,
                sizes = result
            }));
        }
        public override async Task <IResponseWriter> Execute()
        {
            var volume = ElFinder.GetVolume(Target);

            var parents = await volume.GetParents(Target, Until);

            return(new JsonResponseWriter(new { tree = parents }));
        }
示例#3
0
        public override async Task <IResponseWriter> Execute()
        {
            var volume = ElFinder.GetVolume(Target);

            var(stream, filename) = await volume.GetFile(Target);

            return(new FileResponseWriter(stream, filename));
        }
示例#4
0
        public override async Task <IResponseWriter> Execute()
        {
            var volume = ElFinder.GetVolume(Target);

            var added = await volume.Rename(Target, NewName);

            return(new JsonResponseWriter(new { added = new Fs.FsBase[] { added }, removed = new string[] { Target } }));
        }
示例#5
0
        public override async Task <IResponseWriter> Execute()
        {
            var volume = ElFinder.GetVolume(Target);

            var items = await volume.GetDirectoryItems(Target);

            return(new JsonResponseWriter(new { tree = items.OfType <Fs.FsDirectory>().ToArray() }));
        }
示例#6
0
        public override async Task <ResponseWriter.IResponseWriter> Execute()
        {
            OpenCommandResult result = new OpenCommandResult();

            var volume = ElFinder.GetVolume(Target);

            Fs.FsBase cwd = null;
            if (volume != null)
            {
                cwd = await volume.GetCurrentWorkingDirectory(Target);
            }

            string hash = Init ? "default folder" : "#" + Target;

            if ((cwd == null || !(cwd.Read == 1)) && Init)
            {
                volume = ElFinder.Default;
                Target = volume.DefaultPath;
                cwd    = await volume.GetCurrentWorkingDirectory(Target);
            }

            if (Init)
            {
                result.Api = 2.1046f;
            }

            List <Fs.FsBase> files = new List <Fs.FsBase>();

            result.Cwd = cwd;
            files.AddRange(await volume.GetDirectoryItems(Target));
            result.UplMaxSize = "1M";
            result.UplMaxFile = 3;

            if (Tree)
            {
                List <Fs.FsBase> roots = new List <Fs.FsBase>();
                foreach (var r in ElFinder.Volumes)
                {
                    if (files.FirstOrDefault(f => f.Hash == r.Root.Hash) == null)
                    {
                        files.Add(r.Root);
                    }
                }
            }

            result.Files = files.ToArray();

            result.Options.UploadMime = new Fs.UploadMimeOptions
            {
                Allow      = new string[] { "image/x-ms-bmp", "image/gif", "image/jpeg", "image/png", "image/x-icon", "text/plain" },
                Deny       = new string[] { "all" },
                FirstOrder = "deny"
            };

            var writer = new ResponseWriter.JsonResponseWriter(result);

            return(writer);
        }
示例#7
0
        public override async Task <IResponseWriter> Execute()
        {
            var volume = ElFinder.GetVolume(Target);
            var items  = await volume.GetDirectoryItems(Target);

            Dictionary <string, string> result = new Dictionary <string, string>();

            foreach (var item in items)
            {
                if (Intersect.Length == 0 || Intersect.Contains(item.Name))
                {
                    result.Add(item.Hash, item.Name);
                }
            }

            return(new JsonResponseWriter(new { list = result }));
        }
示例#8
0
        private async Task <IResponseWriter> ChunkUpload()
        {
            System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"^(.*).(\d+)_(\d+).part$");
            var match = regex.Match(Chunk);

            if (match.Success)
            {
                string filename = match.Groups[1].Value;
                int    part     = Convert.ToInt32(match.Groups[2].Value);
                int    total    = Convert.ToInt32(match.Groups[3].Value);

                string[] ranges      = Range.Split(',');
                int      startByte   = Convert.ToInt32(ranges[0]);
                int      chunkLenght = Convert.ToInt32(ranges[1]);
                int      totalBytes  = Convert.ToInt32(ranges[2]);

                byte[] chunkContent;
                using (var stream = Files[0].OpenReadStream())
                    using (var sr = new System.IO.BinaryReader(stream))
                    {
                        chunkContent = sr.ReadBytes(chunkLenght);
                    }

                bool chunkMerged = StoreChunk(filename, startByte, chunkLenght, totalBytes, chunkContent);
                if (chunkMerged)
                {
                    return(new JsonResponseWriter(new { added = new int[0], _chunkmerged = filename, _name = filename }));
                }
                else
                {
                    return(new JsonResponseWriter(new { added = new int[0] }));
                }
            }
            else
            {
                var volume   = ElFinder.GetVolume(Target);
                var hashPath = UploadPaths != null && UploadPaths.Length > 0 ? UploadPaths[0] : Target;
                var item     = chunkStorage[Chunk];
                chunkStorage.Remove(Chunk);

                var added = await volume.Upload(hashPath, Chunk, item.Stream);

                return(new JsonResponseWriter(new { added = new Fs.FsBase[] { added } }));
            }
        }
示例#9
0
        public override async Task <IResponseWriter> Execute()
        {
            Dictionary <string, string> images = new Dictionary <string, string>();

            foreach (var target in Targets)
            {
                var volume = ElFinder.GetVolume(target);
                var(stream, filename) = await volume.GetFile(target);

                using (stream)
                {
                    var tmbName = volume.CreateTmb(stream, filename);
                    images.Add(target, tmbName);
                }
            }

            return(new JsonResponseWriter(new { images }));
        }
示例#10
0
        public override async Task <IResponseWriter> Execute()
        {
            List <string> successfullyRemoved = new List <string>();

            foreach (var target in Targets)
            {
                var volume = ElFinder.GetVolume(target);
                try
                {
                    await volume.Delete(target);

                    successfullyRemoved.Add(target);
                }
                catch (Exception e)
                {
                    //log
                }
            }

            return(new JsonResponseWriter(new { removed = successfullyRemoved }));
        }
示例#11
0
        public override async Task <IResponseWriter> Execute()
        {
            if (IsChunkUpload())
            {
                return(await ChunkUpload());
            }
            var volume = ElFinder.GetVolume(Target);

            List <Fs.FsBase> uploadedFiles = new List <Fs.FsBase>();

            for (int i = 0; i < Files.Count; i++)
            {
                var file     = Files[i];
                var hashPath = UploadPaths != null && UploadPaths.Length > i ? UploadPaths[i] : Target;
                System.IO.MemoryStream ms = new System.IO.MemoryStream((int)file.Length);
                file.CopyTo(ms);
                uploadedFiles.Add(await volume.Upload(hashPath, file.FileName, ms));
            }

            return(new JsonResponseWriter(new { added = uploadedFiles.ToArray() }));
        }
示例#12
0
        public override async Task <IResponseWriter> Execute()
        {
            var result = new MkDirCommandResult();

            var volume = ElFinder.GetVolume(Target);

            if (volume != null)
            {
                if (!string.IsNullOrEmpty(DirectoryName))
                {
                    var dir = await volume.CreateDirectory(Target, DirectoryName);

                    result.Added = new Fs.FsDirectory[] { dir };
                }
                else
                {
                    result.Hashes = new Dictionary <string, string>();
                    List <Fs.FsDirectory> dirs = new List <Fs.FsDirectory>();
                    foreach (var item in Dirs)
                    {
                        var d = await volume.CreateDirectory(Target, item);

                        dirs.Add(d);
                        result.Hashes.Add(item, d.Hash);
                    }
                    result.Added = dirs.ToArray();
                }

                result.Changed = new Fs.FsDirectory[] { (Fs.FsDirectory) await volume.GetCurrentWorkingDirectory(Target) };

                return(new JsonResponseWriter(result));
            }
            else
            {
                throw new InvalidOperationException();
            }
        }