public IActionResult UploadFile(string folderPath) { if (!IsRestrictedPath(folderPath) && Request.Form.Files.Any() && !Request.Form.Files.Any(f => f.Name.Contains(".."))) { var folder = new PEngineFolderModel(folderPath); if (folder.Valid) { foreach (var file in Request.Form.Files) { var fullFilePath = Path.Combine(folder.FullPath, file.FileName); if (System.IO.File.Exists(fullFilePath)) { System.IO.File.Delete(fullFilePath); } using (var writeStream = System.IO.File.OpenWrite(fullFilePath)) { file.CopyTo(writeStream); //using (var reader = file.OpenReadStream()) //{ // reader.CopyTo(writeStream); //} } } return(this.Get(folderPath)); } } return(this.BadRequest()); }
public IActionResult RenameFolder(string folderPath, [FromQuery] string newName) { if (IsReadOnlyPath(folderPath)) { return(this.Conflict()); } if (IsRestrictedPath(folderPath)) { return(this.BadRequest()); } var folder = new PEngineFolderModel(folderPath); if (folder.Valid) { var parentFolderPath = folderPath.Substring(0, folderPath.Length - folder.Name.Length).TrimEnd(Path.DirectorySeparatorChar); var newFolderPath = $"{folder.Parent.FullPath.TrimEnd(Path.DirectorySeparatorChar)}{Path.DirectorySeparatorChar}{newName}"; if (!System.IO.Directory.Exists(newFolderPath)) { System.IO.Directory.Move(folder.FullPath, newFolderPath); return(this.Get(parentFolderPath)); } return(this.BadRequest()); } return(this.NotFound()); }
public IActionResult Get(string folderPath) { folderPath = folderPath ?? string.Empty; if (!IsRestrictedPath(folderPath)) { var folder = new PEngineFolderModel(folderPath); if (folder.Valid) { folder.Folders = folder.Folders.Where(f => !IsRestrictedPath(f.RelativePath)).ToList(); return(this.Ok(folder)); } } return(this.BadRequest()); }
public IActionResult CreateFolder(string parentFolderPath, [FromQuery] string newName) { if (!IsRestrictedPath(parentFolderPath)) { var parentFolder = new PEngineFolderModel(parentFolderPath); if (parentFolder.Valid) { var newFolderPath = $"{parentFolder.FullPath.TrimEnd(Path.DirectorySeparatorChar)}{Path.DirectorySeparatorChar}{newName}"; if (!System.IO.Directory.Exists(newFolderPath)) { System.IO.Directory.CreateDirectory(newFolderPath); return(this.Get(parentFolderPath)); } return(this.BadRequest()); } return(this.NotFound()); } return(this.BadRequest()); }
public IActionResult ProcessSelections(SelectionOperation operation, string targetFolderPath, [FromBody] PEngineResourceSelectionModel selections) { if (!IsRestrictedPath(targetFolderPath)) { var targetFolder = new PEngineFolderModel(targetFolderPath); if (targetFolder.Valid && selections != null) { bool valid = false; if (selections.FilePaths != null && selections.FilePaths.Any()) { foreach (var filePath in selections.FilePaths) { if (!IsRestrictedPath(filePath)) { var file = new PEngineFileModel(filePath); var targetFullPath = $"{targetFolder.FullPath}{System.IO.Path.DirectorySeparatorChar}{file.Name}"; if (file.Valid) { switch (operation) { case SelectionOperation.Copy: System.IO.File.Copy(file.FullPath, targetFullPath); break; case SelectionOperation.Move: System.IO.File.Move(file.FullPath, targetFullPath); break; case SelectionOperation.Delete: System.IO.File.Delete(file.FullPath); break; } valid = true; } } } } if (selections.FolderPaths != null && selections.FolderPaths.Any()) { foreach (var folderPath in selections.FolderPaths) { if (!IsRestrictedPath(folderPath)) { var folder = new PEngineFolderModel(folderPath); var targetFullPath = $"{targetFolder.FullPath}{System.IO.Path.DirectorySeparatorChar}{folder.Name}"; if (folder.Valid) { switch (operation) { case SelectionOperation.Copy: CopyFolder(folder.FullPath, targetFullPath); break; case SelectionOperation.Move: System.IO.Directory.Move(folder.FullPath, targetFullPath); break; case SelectionOperation.Delete: System.IO.Directory.Delete(folder.FullPath, true); break; } valid = true; } } } } if (valid) { return(Get(targetFolderPath)); } } } return(this.BadRequest()); }