public object Patch([FromBody] dynamic model, string id) { FileId fileId = FileId.FromUuid(id); if (!_provider.FileExists(fileId.PhysicalPath) && !_provider.DirectoryExists(fileId.PhysicalPath)) { return(NotFound()); } dynamic result = null; switch (FilesHelper.GetFileType(fileId.PhysicalPath)) { case FileType.File: result = PatchFile(model, fileId); break; case FileType.Directory: result = PatchDirectory(model, fileId); break; default: return(new StatusCodeResult((int)HttpStatusCode.MethodNotAllowed)); } if (result.id != id) { return(LocationChanged(FilesHelper.GetLocation(result.id), result)); } return(result); }
public IActionResult Delete(string id) { FileId fileId = FileId.FromUuid(id); if (_provider.FileExists(fileId.PhysicalPath) || _provider.DirectoryExists(fileId.PhysicalPath)) { switch (FilesHelper.GetFileType(fileId.PhysicalPath)) { case FileType.File: case FileType.Directory: _provider.Delete(fileId.PhysicalPath); break; default: break; } } return(new NoContentResult()); }
public object Post([FromBody] dynamic model) { string name; FileType fileType; FileId fileId, parentId; _helper.EnsurePostModelValid(model, out name, out fileId, out parentId); try { fileType = FilesHelper.GetFileType(fileId.PhysicalPath); } catch (FileNotFoundException) { throw new NotFoundException("file"); } if (!_fileService.DirectoryExists(parentId.PhysicalPath)) { throw new NotFoundException("parent"); } var src = fileType == FileType.File ? _fileService.GetFile(fileId.PhysicalPath) : _fileService.GetDirectory(fileId.PhysicalPath); string destPath = Path.Combine(parentId.PhysicalPath, name == null ? src.Name : name); if (PathUtil.IsAncestor(src.Path, destPath) || src.Path.Equals(destPath, StringComparison.OrdinalIgnoreCase)) { throw new ApiArgumentException("parent", "The destination folder is a subfolder of the source"); } if (fileType == FileType.File && _fileService.DirectoryExists(destPath) || fileType == FileType.Directory && _fileService.FileExists(destPath)) { throw new AlreadyExistsException("name"); } MoveOperation copy = InitiateCopy(src, destPath); Context.Response.StatusCode = (int)HttpStatusCode.Accepted; Context.Response.Headers.Add("Location", MoveHelper.GetLocation(copy.Id, true)); return(_helper.ToJsonModel(copy)); }