-
Notifications
You must be signed in to change notification settings - Fork 175
Add File Move Operation to PATCH Endpoint #177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Prevents potential error when Target header is missing by providing empty string default
- MissingTargetTypeHeader: List all valid Target-Type options with descriptions - InvalidTargetTypeHeader: Show available options when invalid type provided - MissingTargetHeader: Explain expected Target values based on Target-Type - MissingOperation: List all operations with context about when to use each - InvalidOperation: Show valid operations with their specific use cases These improved error messages guide users to correct API usage by providing helpful context and listing all available options directly in the error response.
- Implemented rename operation using PATCH with Target-Type: file, Target: name - Uses app.fileManager.renameFile() to preserve internal links - Added comprehensive error handling for missing files and existing destinations
- Test successful rename with Target-Type: file, Target: name - Test rename fails with non-existent file - Test rename fails when destination already exists - Mock fileManager.renameFile() to verify proper API usage
- Add rename operation to PATCH endpoint enum - Add file Target-Type to support file operations - Include example and description for file rename - Documents Operation: rename, Target-Type: file usage
- Add move operation to PATCH endpoint for files - Use Operation: move, Target-Type: file, Target: path - Automatically creates parent directories if needed - Preserves all internal links using FileManager.renameFile() - Validates paths and prevents overwrites - Add tests for edge cases
- Add new error codes for clearer validation messages - Use consistent returnCannedResponse pattern throughout - Reorder validation checks for better flow - Separate file operations from applyPatch operations early - Maintain upstream coding style and patterns
…ile move - Add path traversal protection to prevent access outside vault - Use returnCannedResponse consistently throughout handleMoveOperation - Add proper error codes to ErrorCode enum and ERROR_CODE_MESSAGES - Validate paths early to prevent directory path destinations - Check parent directory existence before creating - Add comprehensive security tests for path traversal attempts - Normalize paths to handle backslashes and multiple slashes
- Add move operation to PATCH endpoint enum - Update Target parameter description for move operations - Include example for file move functionality - Documents Operation: move, Target-Type: file usage
coddingtonbear
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this PR might be a good solution for the concerns I had around #176 so I think this is worth talking over more!
This PR, though, looks like it includes all of the changes of both #176 and this PR rather than being just the unique work for this particular problem. To make this PR reviewable, what you need to do is set its base branch to be the branch you made for #176 rather than main.
|
a) coddingtonbear - thanks for this plugin; it's great and much needed no notes |
|
I talked this over briefly with @duquesnay and I'm suggesting to him that he approach this via creating an API extension as the first pass. See https://github.com/coddingtonbear/obsidian-local-rest-api/wiki/Adding-your-own-API-Routes-via-an-Extension for insight into what that might look like. |
Summary
Adds file move operation to the PATCH endpoint, allowing files to be moved within the vault while preserving internal links.
Dependencies
Changes
moveoperation to PATCH endpoint for fileshandleMoveOperationmethodSecurity
../)Usage
Implementation
FileManager.renameFile()to preserve links