feat: add file persistence and autosave backend system#81
Closed
woydarko wants to merge 1 commit into
Closed
Conversation
Closes kodykebab#57 ## What was added ### server/routes/file_routes.py (new) Five endpoints registered under /api/files/: POST /api/files/save - Creates or overwrites a file in the session workspace - Validates session ownership, path traversal, blocked extensions (.exe etc) - Creates parent directories automatically (mkdir -p) - Returns size, path, created (bool) - Max file size: 5MB GET /api/files/load - Loads file contents from session workspace - Path traversal protection, file size check - Returns content, path, size GET /api/files/list - Lists all files recursively in session workspace - Skips hidden files (.env, .git) and __pycache__ - Optional subdir filter - Returns [{path, size, is_dir}] + total count DELETE /api/files/delete - Deletes a single file from session workspace - Path traversal protection POST /api/files/mkdir - Creates a directory (idempotent) - Path traversal protection All endpoints validate session ownership via session_id + user_id. ### server/start.py Registered files_bp blueprint ### server/tests/test_file_routes.py (new) 37 tests covering all endpoints: - _safe_path: valid path, parent traversal blocked, absolute path blocked - _validate_filename: null byte, absolute, hidden root, valid cases - POST /api/files/save: missing fields, session not found, traversal blocked, blocked extension, successful save, overwrite, creates parent dirs, size - GET /api/files/load: missing fields, session not found, file not found, traversal blocked, successful load - GET /api/files/list: missing session, not found, lists files, excludes hidden, returns total - DELETE /api/files/delete: missing session, file not found, deletes file, traversal - POST /api/files/mkdir: missing session, creates dir, idempotent ## Results Tests: 148 passed, 0 failed (37 new + all existing)
Collaborator
|
Issue already resolved, hence closing the PR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #57
Adds the backend file persistence system for the autosave feature — five REST endpoints that allow the frontend to save, load, list, delete, and create files inside the session workspace (
instance_dir), following the same pattern used by the existing Soroban routes.What was added
server/routes/file_routes.py(new)POST /api/files/save.exe,.bin,.so,.dll,.dylib)mkdir -p){success, path, size, created}GET /api/files/load{success, path, content, size}GET /api/files/list.env,.git) and__pycache__subdirfilter{success, files: [{path, size, is_dir}], total}DELETE /api/files/deletePOST /api/files/mkdirAll endpoints validate session ownership via
session_id+user_id.server/start.pyRegistered
files_bpblueprintserver/tests/test_file_routes.py(new)37 tests covering all endpoints:
_safe_path: valid path, parent traversal blocked, absolute path_validate_filename: null byte, absolute, hidden root, valid casesResults