Commit Graph
11 Commits
Author SHA1 Message Date
AlexKucera d56cb98d51 Refactors path conversion to simplify logic
Replaces manual conversion of absolute paths to vault-relative paths with a utility method to improve code readability and maintainability across various modules. Removes redundant code and streamlines path handling operations.

This refactoring helps ensure consistent path management and reduces potential errors related to path conversion.

Relates to obsidian-bot-review
2025-11-08 19:01:42 +01:00
AlexKucera ec36b6334f Refactors path handling in EmbedProcessor
Introduces toVaultRelativePath method to centralize path conversions,
reducing code duplication and improving maintainability. Extracts
image download completion logic into handleDownloadComplete for clarity.

Relates to obsidian-bot-review
2025-11-08 18:52:27 +01:00
Jarvis 87f3894bf1 Fixes path doubling issues in directory creation and file operations
Resolves critical bugs where directories and files were being created with
doubled paths (e.g., /vault/vault/path) due to incorrect handling of absolute
vs vault-relative paths when using Obsidian's vault adapter.

## Root Cause
The vault.adapter methods (mkdir, write, readBinary, etc.) expect vault-relative
paths, but many parts of the codebase were passing absolute filesystem paths.
This caused the adapter to prepend the vault path again, resulting in doubled
paths like: /Users/user/vault/Users/user/vault/exports

## Changes

### Core Path Handling
- **TempDirectoryManager**: Switched to Node's fs module for temp directory
  operations since external tools (pdf2img, ImageMagick, Pandoc) require
  absolute filesystem paths and cannot use vault adapter
- **PathUtils.ensureDir()**: Enhanced error messages to provide context about
  missing parent directories and permission issues

### Path Conversion Pattern
Implemented consistent pattern throughout codebase: convert absolute paths to
vault-relative before vault.adapter operations by:
1. Checking if path starts with vault base path
2. Stripping vault base path
3. Removing leading slash/backslash
4. Passing vault-relative path to vault.adapter

### Fixed Locations
- **ImageOptimizer**: Convert paths before vault.adapter operations (3 locations)
- **EmbedProcessor**:
  - downloadRemoteImage(): path conversion for writeBinary
  - copyImageToVaultTemp(): path conversion for vault.adapter operations
  - processImageEmbeds(): WebP conversion temp directory
- **PandocTypstConverter**: Use fs module for temp markdown file operations
- **PathResolver**: Convert output folder paths before ensureDir
- **PdfToImageConverter**: Convert output directory path before ensureDir
- **EmbeddedTemplateManager**: Convert template directory paths (2 locations)

### Additional Improvements
- **PathResolver**: Added validation for empty/missing output folder with
  clear error message guiding users to plugin settings
- **ESLint**: Changed sentence-case rule from error to warning to reduce
  linter noise during development

## Impact
- Fixes directories being created in wrong locations with doubled paths
- Ensures temp directories are accessible by external CLI tools
- Improves error messages for directory creation failures
- Maintains compatibility with both Obsidian's vault adapter and Node's fs

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-05 19:17:37 +01:00
AlexKucera 2c4076f3c9 Applies Obsidian linter and fixes code issues
Applies linting rules to the codebase and resolves identified issues.

Addresses:
- Renamed headings in settings tabs to improve UI consistency and style.
- Resolved require() style imports
- Added void operator to ensure correct promise handling.
- Replaced deprecated Obsidian API calls.
- Enforces sentence case to enhance UI text consistency.
2025-11-05 13:46:06 +01:00
AlexKucera 281c02210a Add Docstrings 2025-11-05 08:03:52 +01:00
AlexKucera 2e1d2673b1 Simplifies path joining logic
Simplifies the path joining logic by leveraging the built-in `path.join` method directly.
This change removes the manual iteration and absolute path handling, resulting in more concise and readable code.

Ensures correct path handling on Windows.
2025-11-04 11:10:53 +01:00
AlexKucera 8329c9dd48 Fixes path handling and adds remote image support
Addresses issues with path construction on Windows by using `path.isAbsolute()` to correctly handle absolute paths.  Improves cross-platform compatibility in temp directory management and binary location.

Adds support for downloading and embedding remote images (http/https URLs) in markdown, enhancing content integration. Provides fallback mechanism with placeholder text upon download failure.
2025-11-04 10:55:24 +01:00
Jarvis ff8e9f9ea3 fix(PathUtils): Improve cross-platform absolute path detection
Replace complex heuristic with precise pattern matching for absolute paths:
- Unix paths: starts with /
- Windows drive letters: C:\ or C:/ using regex /^[a-zA-Z]:[/\\]/
- Windows UNC paths: \\server\share

Removes unreliable temp/tmp path indicators and file: URL checks while
maintaining fs fallback behavior for proper external file processing.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-25 16:44:46 +02:00
Jarvis 4e3ef6ce9c fix(PathUtils): Improve cross-platform absolute path detection without Node.js path module
- Replaced problematic heuristic path.includes('/') && !path.startsWith('.')
- Added explicit checks for Windows drive letters (C:), UNC paths, and Unix absolute paths
- Enhanced detection for temp directories and file URLs across platforms
- Maintains Obsidian API-first approach without importing Node.js path module
- Better handles Windows absolute paths like 'C:\Users\...' and '\UNC\paths'
- Preserves existing fs.access fallback behavior for external files

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-25 16:26:11 +02:00
Jarvis 37015c8ed6 fix: resolve embedded file path resolution issue in PathUtils.fileExists
- Fix pathUtils.fileExists() to handle absolute filesystem paths
- Add proper conversion from absolute to vault-relative paths
- Add fs fallback for external files outside vault
- Resolves 'File not found' errors for embedded PDF, image, and document files
- Maintains compatibility with both vault-relative and absolute paths

This fixes the path resolution issue that occurred after migrating to vault.adapter,
where embedded files were showing as 'not found' because absolute paths were being
passed to vault.adapter.exists() which only accepts vault-relative paths.
2025-09-25 12:43:00 +02:00
Jarvis 5598e0e538 feat: add PathUtils helper class for centralized path operations
- Add ABOUTME comments following guidelines
- Implement safe FileSystemAdapter access with proper type checking
- Use vault.adapter methods (exists, mkdir, list, remove)
- Use normalizePath() consistently for all paths
- Match existing patterns (cleanupDir only removes files, returns boolean)
- Add user-friendly error messages with Notice
- Place in src/core/ alongside other core utilities

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-25 11:44:00 +02:00