public object FileOperations([FromBody] FileManagerDirectoryContent args)
        {
            if (args.Action is "delete" or "rename")
            {
                if ((args.TargetPath == null) && (args.Path == ""))
                {
                    FileManagerResponse response = new()
                    {
                        Error = new ErrorDetails {
                            Code = "401", Message = "Restricted to modify the root folder."
                        }
                    };
                    return(operation.ToCamelCase(response));
                }
            }

            return(args.Action switch
            {
                "read" => operation.ToCamelCase(operation.GetFiles(args.Path, args.ShowHiddenItems)),
                "delete" => operation.ToCamelCase(operation.Delete(args.Path, args.Names)),
                "copy" => operation.ToCamelCase(operation.Copy(args.Path, args.TargetPath, args.Names,
                                                               args.RenameFiles, args.TargetData)),
                "move" => operation.ToCamelCase(operation.Move(args.Path, args.TargetPath, args.Names,
                                                               args.RenameFiles, args.TargetData)),
                "details" => operation.ToCamelCase(operation.Details(args.Path, args.Names, args.Data)),
                "create" => operation.ToCamelCase(operation.Create(args.Path, args.Name)),
                "search" => operation.ToCamelCase(operation.Search(args.Path, args.SearchString,
                                                                   args.ShowHiddenItems, args.CaseSensitive)),
                "rename" => operation.ToCamelCase(operation.Rename(args.Path, args.Name, args.NewName)),
                _ => null
            });
        public async Task <IActionResult> FileOperations([FromBody] FileManagerDirectoryContent args)
        {
            //if(args.Action == "delete" || args.Action == "rename")
            //{
            //    if(string.IsNullOrEmpty(args.TargetPath) && string.IsNullOrEmpty(args.Path))
            //    {
            //        FileManagerResponse response = new FileManagerResponse();

            //        response.Error = new ErrorDetails
            //        {
            //            Code = "401",
            //            Message = "عدم دسترسی به فولدر مورد نظر"
            //        };
            //        return Unauthorized(opration.ToCamelCase(response));
            //    }
            //}
            switch (args.Action)
            {
            case "read":
                return(Ok(opration.ToCamelCase(opration.GetFiles(args.Path, args.ShowHiddenItems))));

            case "delete":
                return(Ok(opration.ToCamelCase(opration.Delete(args.Path, args.Names))));

            case "copy":
                return(Ok(opration.ToCamelCase(opration.Copy(args.Path, args.TargetPath, args.Names, args.RenameFiles, args.TargetData))));

            case "move":
                return(Ok(opration.ToCamelCase(opration.Move(args.Path, args.TargetPath, args.Names, args.RenameFiles, args.TargetData))));

            case "details":
                return(Ok(opration.ToCamelCase(opration.Details(args.Path, args.Names))));

            case "create":
                return(Ok(opration.ToCamelCase(opration.Create(args.Path, args.Name))));

            case "search":
                return(Ok(opration.ToCamelCase(opration.Search(args.Path, args.SearchString, args.ShowHiddenItems, args.CaseSensitive))));

            case "rename":
                return(Ok(opration.ToCamelCase(opration.Rename(args.Path, args.Name, args.NewName))));
            }
            return(Ok());
        }
Beispiel #3
0
        public object FileOperations([FromBody] FileManagerDirectoryContent args)
        {
            // cannot edit files and attempts to edit => error
            if (!permissionVerificationService.HasPermission(User.Identity.Name !, "File.Edit") &&
                (args.Action == "delete" || args.Action == "rename" || args.Action == "copy" || args.Action == "move" ||
                 args.Action == "create"))
            {
                FileManagerResponse response = new FileManagerResponse();
                response.Error = new ErrorDetails()
                {
                    Code    = "401",
                    Message = "Unauthorized."
                };
                return(operation.ToCamelCase(response));
            }

            // Restricting modification of the root folder
            if ((args.Action == "delete" || args.Action == "rename") && args.TargetPath == null && args.Path == string.Empty)
            {
                FileManagerResponse response = new FileManagerResponse();
                response.Error = new ErrorDetails()
                {
                    Code    = "401",
                    Message = "Restricted to modify the root folder."
                };
                return(operation.ToCamelCase(response));
            }
            // Processing the File Manager operations
            FileManagerResponse diskResponse;

            switch (args.Action)
            {
            case "read":
                // Path - Current path; ShowHiddenItems - Boolean value to show/hide hidden items
                diskResponse = operation.GetFiles(args.Path, args.ShowHiddenItems);
                break;

            case "delete":
                // Path - Current path where of the folder to be deleted; Names - Name of the files to be deleted
                diskResponse = operation.Delete(args.Path, args.Names);
                break;

            case "copy":
                //  Path - Path from where the file was copied; TargetPath - Path where the file/folder is to be copied; RenameFiles - Files with same name in the copied location that is confirmed for renaming; TargetData - Data of the copied file
                diskResponse = operation.Copy(args.Path, args.TargetPath, args.Names, args.RenameFiles, args.TargetData);
                break;

            case "move":
                // Path - Path from where the file was cut; TargetPath - Path where the file/folder is to be moved; RenameFiles - Files with same name in the moved location that is confirmed for renaming; TargetData - Data of the moved file
                diskResponse = operation.Move(args.Path, args.TargetPath, args.Names, args.RenameFiles, args.TargetData);
                break;

            case "details":
                // Path - Current path where details of file/folder is requested; Name - Names of the requested folders
                diskResponse = operation.Details(args.Path, args.Names);
                break;

            case "create":
                // Path - Current path where the folder is to be created; Name - Name of the new folder
                diskResponse = operation.Create(args.Path, args.Name);
                break;

            case "search":
                // Path - Current path where the search is performed; SearchString - String typed in the searchbox; CaseSensitive - Boolean value which specifies whether the search must be casesensitive
                diskResponse = operation.Search(args.Path, args.SearchString, args.ShowHiddenItems, args.CaseSensitive);
                break;

            case "rename":
                // Path - Current path of the renamed file; Name - Old file name; NewName - New file name
                diskResponse = operation.Rename(args.Path, args.Name, args.NewName);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(args.Action));
            }

            return(operation.ToCamelCase(diskResponse));
        }