public Response.IResponse Execute(CommandArgs args)
        {
            var pa = args.As <uploadArgs>();

            if (string.IsNullOrWhiteSpace(pa.target))
            {
                return(new Response.ErrorResponse("target not specified"));
            }

            // get volume for our target
            var vol = _volumeManager.GetByHash(pa.target);

            if (vol == null)
            {
                return(new Response.ErrorResponse("invalid target"));
            }

            if (args.Files == null || args.Files.Count == 0)
            {
                return(new Response.ErrorResponse("no files"));
            }
            //return new Response.UploadResponse( new Model.FileModel[ 0 ] );

            var savedFiles = vol.SaveFiles(pa.target, args.Files);

            return(new Response.UploadResponse(savedFiles));
        }
Ejemplo n.º 2
0
        public Response.IResponse Execute(CommandArgs args)
        {
            var pa = args.As <mkdirArgs>();

            if (string.IsNullOrWhiteSpace(pa.target))
            {
                return(new Response.ErrorResponse("target not specified"));
            }

            // get volume for our target
            var vol = _volumeManager.GetByHash(pa.target);
            // try to get directory for our target
            var cwd = (vol != null ? vol.GetDirectoryByHash(pa.target) : null);

            // if we still haven't got volume service, then something is wrong
            if (cwd == null || cwd.IsReadable.IsFalse())
            {
                return(new Response.ErrorResponse("target dir not found or access denied"));
            }

            var created = vol.CreateDirectory(cwd, pa.name);

            if (created == null)
            {
                return(new Response.ErrorResponse("errMkdir"));
            }

            return(new Response.MkdirResponse(created));
        }
Ejemplo n.º 3
0
        public Response.IResponse Execute(CommandArgs args)
        {
            var pa = args.As <fileArgs>();

            if (string.IsNullOrWhiteSpace(pa.target))
            {
                return(new Response.ErrorResponse("target not specified"));
            }

            // get volume for our target
            var vol = _volumeManager.GetByHash(pa.target);

            if (vol == null)
            {
                return(new Response.ErrorResponse("invalid target"));
            }
            // ensure that the file is valid
            var fileToGet = vol.GetFileByHash(pa.target);

            if (fileToGet == null)
            {
                return(new Response.ErrorResponse("invalid target"));
            }
            // now get path
            string filePath = vol.DecodeHashToPath(pa.target);

            return(new Response.BinaryFileResponse(filePath));
        }
Ejemplo n.º 4
0
        public Response.IResponse Execute(CommandArgs args)
        {
            var pa = args.As <getArgs>();

            if (string.IsNullOrWhiteSpace(pa.target))
            {
                return(new Response.ErrorResponse("target not specified"));
            }

            // get volume for our target
            var vol = _volumeManager.GetByHash(pa.target);

            if (vol == null)
            {
                return(new Response.ErrorResponse("invalid target"));
            }

            var fileToGet = vol.GetFileByHash(pa.target);

            if (fileToGet == null)
            {
                return(new Response.ErrorResponse("invalid target"));
            }

            var content = vol.GetTextFileContent(fileToGet);

            if (content == null)
            {
                return(new Response.ErrorResponse("error getting file content"));
            }
            return(new Response.GetResponse(content));
        }
        public Response.IResponse Execute(CommandArgs args)
        {
            var pa = args.As <putArgs>();

            if (string.IsNullOrWhiteSpace(pa.target))
            {
                return(new Response.ErrorResponse("target not specified"));
            }

            // get volume for our target
            var vol = _volumeManager.GetByHash(pa.target);

            if (vol == null)
            {
                return(new Response.ErrorResponse("invalid target"));
            }

            var fileToModify = vol.GetFileByHash(pa.target);

            if (fileToModify == null)
            {
                return(new Response.ErrorResponse("invalid target"));
            }

            Model.FileModel modifiedFile = vol.SetTextFileContent(fileToModify, pa.content);
            if (modifiedFile == null)
            {
                return(new Response.ErrorResponse("error setting file content"));
            }
            return(new Response.PutResponse(new Model.FileModel[] { modifiedFile }));
        }
        public Response.IResponse Execute(CommandArgs args)
        {
            var pa = args.As <tmbArgs>();

            if (pa.targets == null || pa.targets.Length == 0)
            {
                return(new Response.ErrorResponse("target(s) not specified"));
            }

            string thumbsDestPath = _config.LocalFSThumbsDirectoryPath;             //TODO: this directory CAN'T be set in CONFIG!

            if (string.IsNullOrWhiteSpace(thumbsDestPath))
            {
                return(new Response.ErrorResponse("thumbs target directory not specified in config"));
            }

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

            foreach (var fileHash in pa.targets)
            {
                // get volume for our target
                var vol = _volumeManager.GetByHash(fileHash);
                if (vol == null)
                {
                    return(new Response.ErrorResponse("invalid target"));
                }
                var fileToProcess = vol.GetFileByHash(fileHash);
                if (fileToProcess == null)
                {
                    return(new Response.ErrorResponse("invalid target"));
                }

                // check if we can generate thumbnail
                if (!_imageEditorService.CanGenerateThumbnail(fileToProcess.Name))
                {
                    continue;
                }

                string generatedFileName = _imageEditorService.CreateThumbnail(vol.DecodeHashToPath(fileHash), thumbsDestPath, fileHash,
                                                                               _config.ThumbsSize, false);
                if (generatedFileName != null)
                {
                    images.Add(fileHash, generatedFileName);
                }
            }

            return(new Response.TmbResponse(images));
        }
        public Response.IResponse Execute(CommandArgs args)
        {
            var pa = args.As <parentsArgs>();

            if (string.IsNullOrWhiteSpace(pa.target))
            {
                return(new Response.ErrorResponse("target not specified"));
            }

            // get volume for our target
            var vol = _volumeManager.GetByHash(pa.target);
            // try to get directory for our target
            var cwd = (vol != null ? vol.GetDirectoryByHash(pa.target) : null);

            // if we still haven't got volume service, then something is wrong
            if (cwd == null || cwd.IsReadable.IsFalse())
            {
                return(new Response.ErrorResponse("target dir not found or access denied"));
            }

            HashSet <Model.DirectoryModel> tree = new HashSet <Model.DirectoryModel>();

            tree.Add(cwd);
            var rootDir = vol.GetRootDirectory();

            // now get parent untill we reach root
            while (cwd != null && cwd.Hash != rootDir.Hash)
            {
                if (cwd.ParentHash == null)
                {
                    break;
                }
                var parentDir = vol.GetDirectoryByHash(cwd.ParentHash);
                if (parentDir == null)
                {
                    return(new Response.ErrorResponse("error getting parent dir: not found or access denied"));
                }
                tree.Add(parentDir);
                var subDirs = vol.GetSubdirectoriesFlat(parentDir, 0);
                foreach (var sd in subDirs)
                {
                    tree.Add(sd);
                }
                cwd = parentDir;
            }
            return(new Response.TreeResponse(tree.ToArray()));
        }
Ejemplo n.º 8
0
        public Response.IResponse Execute(CommandArgs args)
        {
            var pa = args.As <duplicateArgs>();

            if (pa.targets == null || pa.targets.Length == 0)
            {
                return(new Response.ErrorResponse("source file(s) not specified"));
            }

            IList <Model.ObjectModel> addedElements = new List <Model.ObjectModel>();

            // now copy each element
            foreach (string elemHash in pa.targets)
            {
                var vol = _volumeManager.GetByHash(elemHash);
                if (vol == null)
                {
                    continue;
                }
                // check if this is directory or a file
                var dirToCopy = vol.GetDirectoryByHash(elemHash);
                if (dirToCopy == null)
                {
                    var fileToCopy = vol.GetFileByHash(elemHash);
                    if (fileToCopy == null)
                    {
                        continue;
                    }

                    var duplicated = vol.DuplicateFile(fileToCopy);
                    if (duplicated != null)
                    {
                        addedElements.Add(duplicated);
                    }
                }
                else
                {
                    var duplicated = vol.DuplicateDirectory(dirToCopy);
                    if (duplicated != null)
                    {
                        addedElements.Add(duplicated);
                    }
                }
            }

            return(new Response.DuplicateResponse(addedElements.ToArray()));
        }
        public Response.IResponse Execute(CommandArgs args)
        {
            var ra = args.As <rmArgs>();

            if (ra.targets == null || ra.targets.Length == 0)
            {
                return(new Response.ErrorResponse("target(s) not specified"));
            }

            IList <string> removeHashes = new List <string>();

            foreach (var toRemove in ra.targets)
            {
                var vol = _volumeManager.GetByHash(toRemove);
                if (vol == null)
                {
                    continue;
                }

                var dirToRemove = vol.GetDirectoryByHash(toRemove);
                if (dirToRemove == null)
                {
                    var fileToRemove = vol.GetFileByHash(toRemove);
                    if (fileToRemove == null)
                    {
                        continue;
                    }

                    if (vol.DeleteFile(fileToRemove))
                    {
                        removeHashes.Add(toRemove);
                    }
                }
                else
                {
                    if (vol.DeleteDirectory(dirToRemove))
                    {
                        removeHashes.Add(toRemove);
                    }
                }
            }

            return(new Response.RmResponse(removeHashes.ToArray()));
        }
        public Response.IResponse Execute(CommandArgs args)
        {
            var pa = args.As <renameArgs>();

            if (string.IsNullOrWhiteSpace(pa.target))
            {
                return(new Response.ErrorResponse("target not specified"));
            }

            // get volume for our target
            var vol = _volumeManager.GetByHash(pa.target);

            if (vol == null)
            {
                return(new Response.ErrorResponse("invalid target"));
            }
            // rename this object and change first if this is directory or a file
            var dirToChange = vol.GetDirectoryByHash(pa.target);

            if (dirToChange == null)
            {
                var fileToChange = vol.GetFileByHash(pa.target);
                if (fileToChange == null)
                {
                    return(new Response.ErrorResponse("target not found"));
                }

                var newFile = vol.RenameFile(fileToChange, pa.name);
                if (newFile == null)
                {
                    return(new Response.ErrorResponse("errRename"));
                }
                return(new Response.RenameResponse(pa.target, newFile));
            }
            else
            {
                var newDir = vol.RenameDirectory(dirToChange, pa.name);
                if (newDir == null)
                {
                    return(new Response.ErrorResponse("errRename"));
                }
                return(new Response.RenameResponse(pa.target, newDir));
            }
        }
Ejemplo n.º 11
0
        public Response.IResponse Execute(CommandArgs args)
        {
            var pa = args.As <treeArgs>();

            if (string.IsNullOrWhiteSpace(pa.target))
            {
                return(new Response.ErrorResponse("target not specified"));
            }

            // get volume for our target
            var vol = _volumeManager.GetByHash(pa.target);
            // try to get directory for our target
            var cwd = (vol != null ? vol.GetDirectoryByHash(pa.target) : null);

            // if we still haven't got volume service, then something is wrong
            if (cwd == null || cwd.IsReadable.IsFalse())
            {
                return(new Response.ErrorResponse("target dir not found or access denied"));
            }

            var tree = vol.GetSubdirectoriesFlat(cwd, 0);

            return(new Response.TreeResponse(tree.ToArray()));
        }
Ejemplo n.º 12
0
        public Response.IResponse Execute(CommandArgs args)
        {
            var pa = args.As <resizeArgs>();

            if (string.IsNullOrWhiteSpace(pa.target))
            {
                return(new Response.ErrorResponse("target not specified"));
            }

            // get volume for our target
            var vol = _volumeManager.GetByHash(pa.target);

            if (vol == null)
            {
                return(new Response.ErrorResponse("invalid target"));
            }

            var fileToModify = vol.GetFileByHash(pa.target);

            if (fileToModify == null)
            {
                return(new Response.ErrorResponse("invalid target"));
            }

            // check if we can generate thumbnail for this file
            if (!_imageEditorService.CanGenerateThumbnail(fileToModify.Name))
            {
                return(new Response.ErrorResponse("unsupported extension"));
            }

            // check what operation we want to perform
            string sourceFilePath = vol.DecodeHashToPath(pa.target);

            switch (pa.mode)
            {
            case imageEditMode.crop:
                if (!_imageEditorService.CropImage(
                        sourceFilePath,
                        new System.Drawing.Point(pa.x ?? 0, pa.y ?? 0),
                        new System.Drawing.Size(pa.width, pa.height)))
                {
                    return(new Response.ErrorResponse("other error"));
                }
                break;

            case imageEditMode.resize:
                if (!_imageEditorService.ResizeImage(
                        sourceFilePath,
                        new System.Drawing.Size(pa.width, pa.height)))
                {
                    return(new Response.ErrorResponse("other error"));
                }
                break;

            case imageEditMode.rotate:
                if (!_imageEditorService.RotateImage(sourceFilePath, pa.degree ?? 0))
                {
                    return(new Response.ErrorResponse("other error"));
                }
                break;
            }


            // hmm since we need to recreate the thumbnail, then we need to delete existing
            vol.DeleteThumbnailFor(fileToModify);
            // and set that thumbnail is supported
            fileToModify.Thumbnail = Model.FileModel.ThumbnailIsSupported;

            return(new Response.ResizeResponse(new Model.FileModel[] { fileToModify }));
        }
        public Response.IResponse Execute(CommandArgs args)
        {
            var pa = args.As <pasteArgs>();

            if (pa.targets == null || pa.targets.Length == 0)
            {
                return(new Response.ErrorResponse("source file(s) not specified"));
            }
            if (string.IsNullOrWhiteSpace(pa.dst))
            {
                return(new Response.ErrorResponse("destination directory not specified"));
            }

            var dstVol = _volumeManager.GetByHash(pa.dst);

            if (dstVol == null)
            {
                return(new Response.ErrorResponse("invalid target"));
            }

            string dstPath = dstVol.DecodeHashToPath(pa.dst);

            bool cut = pa.cut.IsTrue();
            IList <Model.ObjectModel> changedElements = new List <Model.ObjectModel>();
            IList <string>            removedElements = new List <string>();

            // now copy each element
            foreach (string elemHash in pa.targets)
            {
                var vol = _volumeManager.GetByHash(elemHash);
                if (vol == null || dstVol != vol)
                {
                    continue;
                }
                // check if this is directory or a file
                var dirToCopy = vol.GetDirectoryByHash(elemHash);
                if (dirToCopy == null)
                {
                    var fileToCopy = vol.GetFileByHash(elemHash);
                    if (fileToCopy == null)
                    {
                        continue;
                    }

                    var copied = vol.CopyFile(fileToCopy, dstPath, cut);
                    if (copied != null)
                    {
                        changedElements.Add(copied);
                        if (cut)                          // if we are cutting element, then it was removed (or at least should be)
                        {
                            removedElements.Add(elemHash);
                        }
                    }
                }
                else
                {
                    var copied = vol.CopyDirectory(dirToCopy, dstPath, cut);
                    if (copied != null)
                    {
                        changedElements.Add(copied);
                        if (cut)                          // if we are cutting element, then it was removed (or at least should be)
                        {
                            removedElements.Add(elemHash);
                        }
                    }
                }
            }

            return(new Response.PasteResponse(changedElements.ToArray(), removedElements.ToArray()));
        }
Ejemplo n.º 14
0
        public Response.IResponse Execute(CommandArgs args)
        {
            var oa = args.As <openArgs>();

            if (string.IsNullOrWhiteSpace(oa.target) && oa.init.IsFalse())
            {
                return(new Response.ErrorResponse("target not specified"));
            }

            // get volume for our target
            var vol = _volumeManager.GetByHash(oa.target);
            // try to get directory for our target
            var cwd = (vol != null ? vol.GetDirectoryByHash(oa.target) : null);

            if ((cwd == null || cwd.IsReadable.IsFalse()) && oa.init.IsTrue())
            {
                // get default volume
                vol = _volumeManager.DefaultVolume;
                if (vol != null)
                {
                    cwd = vol.GetRootDirectory();
                }
            }

            // if we still haven't got volume service, then something is wrong
            if (cwd == null || cwd.IsReadable.IsFalse())
            {
                return(new Response.ErrorResponse("target dir not found or access denied"));
            }

            var subItems = new List <Model.ObjectModel>();

            // get sub directories
            if (oa.tree.IsTrue())
            {
                subItems.AddRange(vol.GetSubdirectoriesFlat(cwd));
            }
            else
            {
                subItems.AddRange(vol.GetSubdirectoriesFlat(cwd, 0));
            }

            // get files in our CWD
            subItems.AddRange(vol.GetFiles(cwd));

            if (oa.init.IsTrue())
            {
                return(new Response.InitDirectoryResponse(_config.ApiVersion,
                                                          new string[0], //TODO
                                                          _config.UploadMaxSize,
                                                          cwd,
                                                          subItems.ToArray(),
                                                          new Model.OptionsModel(vol.GetPathToRoot(cwd), _config.BaseUrl, _config.BaseThumbsUrl)));
            }
            else
            {
                return(new Response.DirectoryResponse(cwd,
                                                      subItems.ToArray(),
                                                      new Model.OptionsModel(vol.GetPathToRoot(cwd), _config.BaseUrl, _config.BaseThumbsUrl)));
            }
        }