Skip to content

Fixed issue on temporary folder#169

Open
kreamweb wants to merge 2 commits into
mainfrom
fix/temporary-folder-issue
Open

Fixed issue on temporary folder#169
kreamweb wants to merge 2 commits into
mainfrom
fix/temporary-folder-issue

Conversation

@kreamweb

Copy link
Copy Markdown
Contributor

Proposed changes

Fixes unreliable behavior around the editor chat temporary upload directory (uploads/nfd-chat-temp/), which is used by POST /nfd-editor-chat/v1/upload and read by MCP DocumentRead.

Problems addressed

  • nfd-chat-temp/ was only created on the first successful upload, so consumers (e.g. MCP document read via realpath()) could fail when the directory did not exist yet.

  • Upload validation relied on the browser-reported MIME type ($file['type']), which is often application/octet-stream for .csv, .md, and .pdf on production hosts.

  • ChatEditor was only bootstrapped when Permissions::is_editor() was true at plugins_loaded, so REST routes were not registered in some request contexts.

Changes

  • Always bootstrap ChatEditor from Application; gate editor UI hooks (assets, admin bar, canvas styles) behind Permissions::is_editor().
  • Add ensure_temp_upload_dir() on init to create nfd-chat-temp/ early, with a guard index.php.
  • Validate uploads by allowlisted extension + wp_check_filetype(), with a fallback when the browser sends application/octet-stream.
  • Centralize temp path helpers (TEMP_UPLOAD_SUBDIR, get_temp_upload_paths()).
  • Harden Application bootstrap when plugins_loaded has already fired; prevent double initialization.
  • Update wpunit coverage for REST route registration, directory creation, and CSV/octet-stream acceptance.

Production

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Dependency update
  • Refactoring / housekeeping (changes to files not directly related to functionality)

Development

  • Tests
  • Dependency update
  • Environment update / refactoring
  • Documentation Update

Visual

Checklist

  • I have read the CONTRIBUTING doc
  • I have viewed my change in a web-browser
  • Linting and tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Further comments

@kreamweb kreamweb requested a review from wpalani July 16, 2026 07:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant