Skip to content

feat: add file persistence and autosave backend system#81

Closed
woydarko wants to merge 1 commit into
kodykebab:mainfrom
woydarko:feat/autosave-file-persistence
Closed

feat: add file persistence and autosave backend system#81
woydarko wants to merge 1 commit into
kodykebab:mainfrom
woydarko:feat/autosave-file-persistence

Conversation

@woydarko
Copy link
Copy Markdown
Contributor

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

  • Creates or overwrites a file in the session workspace
  • Validates session ownership, path traversal protection, blocked extensions (.exe, .bin, .so, .dll, .dylib)
  • Creates parent directories automatically (mkdir -p)
  • Max file size: 5MB
  • Returns {success, path, size, created}

GET /api/files/load

  • Loads file contents from session workspace
  • Path traversal protection, file size check
  • Returns {success, path, content, size}

GET /api/files/list

  • Lists all files recursively in session workspace
  • Skips hidden files (.env, .git) and __pycache__
  • Optional subdir filter
  • Returns {success, files: [{path, size, is_dir}], total}

DELETE /api/files/delete

  • Deletes a single file; 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
  • _validate_filename: null byte, absolute, hidden root, valid cases
  • All 5 endpoints: missing fields, session not found, traversal blocked, success cases

Results

Tests: 148 passed, 0 failed (37 new + all existing)

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)
@Atharv777
Copy link
Copy Markdown
Collaborator

Issue already resolved, hence closing the PR

@Atharv777 Atharv777 closed this Apr 25, 2026
@Atharv777 Atharv777 reopened this Apr 25, 2026
@Atharv777 Atharv777 closed this Apr 25, 2026
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.

[Editor] Add autosave and file persistence system

2 participants