Mise à jour doc

This commit is contained in:
2025-11-10 18:44:59 +01:00
parent db4f0508cb
commit 96f895b254
4 changed files with 173 additions and 12 deletions

View File

@ -21,7 +21,15 @@ The server (`cmd/server/main.go`) coordinates these components:
1. Loads initial index from notes directory
2. Starts filesystem watcher for automatic re-indexing
3. Pre-parses HTML templates from `templates/`
4. Serves routes: `/` (main page), `/api/search`, `/api/notes/*`, `/api/tree`, `/api/folders/create`, `/api/files/move`
4. Serves routes:
- `/` (main page)
- `/api/v1/notes` and `/api/v1/notes/*` (REST API - JSON responses)
- `/api/search` (HTML search results)
- `/api/notes/*` (HTML editor for notes)
- `/api/tree` (HTML file tree)
- `/api/folders/create` (Folder management)
- `/api/files/move` (File/folder moving)
- `/api/home` (Home page)
5. Handles static files from `static/` directory
### Frontend
@ -40,6 +48,7 @@ The frontend uses a modern build system with Vite and CodeMirror 6:
frontend/src/
├── main.js # Entry point - imports all modules
├── editor.js # CodeMirror 6 editor implementation with slash commands
├── search.js # Search modal with Ctrl/Cmd+K keyboard shortcut
├── file-tree.js # Drag-and-drop file organization
└── ui.js # Sidebar toggle functionality
```
@ -214,15 +223,64 @@ Rich search supports multiple query formats:
- Quoted phrases: `"exact phrase"` preserves spaces
- Results are scored and ranked by relevance (title matches score highest)
### REST API (v1)
The application includes a full REST API for programmatic access:
**Implementation**: `internal/api/rest_handler.go`
**Endpoints**:
- `GET /api/v1/notes` - List all notes with metadata (JSON)
- `GET /api/v1/notes/{path}` - Get a specific note (JSON or Markdown based on Accept header)
- `PUT /api/v1/notes/{path}` - Create or update a note (accepts JSON or raw Markdown)
- `DELETE /api/v1/notes/{path}` - Delete a note
**Content Negotiation**:
- `Accept: application/json` → Returns JSON with full metadata
- `Accept: text/markdown` → Returns raw Markdown content
- `Content-Type: application/json` → Accepts structured JSON request
- `Content-Type: text/markdown` → Accepts raw Markdown body
**Key Features**:
- Automatic front matter generation for new notes
- Front matter update (last_modified) on PUT operations
- Background re-indexing after modifications
- Path validation (same security as HTML endpoints)
- Supports nested folders (creates parent directories automatically)
**Documentation**: See `API.md` for full REST API documentation with examples.
### Search Modal
A modern command-palette style search modal is available:
**Implementation**: `frontend/src/search.js`
**Features**:
- Keyboard shortcut: `Ctrl/Cmd+K` to open anywhere
- Real-time search with 300ms debounce
- Keyboard navigation: `↑`/`↓` to navigate, `Enter` to open, `Esc` to close
- Highlighting of search terms in results
- Uses existing search API (`/api/search`)
- Displays results with icons, titles, paths, snippets, tags, and dates
**Styling**: Custom styles in `static/theme.css` with Material Darker theme integration.
### Security Considerations
File path validation in `handler.go`:
File path validation in `handler.go` and `rest_handler.go`:
- `filepath.Clean()` to normalize paths
- Reject paths starting with `..` or absolute paths (directory traversal prevention)
- Enforce `.md` extension for notes
- Use `filepath.Join()` to construct safe paths within notes directory
- DOMPurify sanitizes Markdown-rendered HTML to prevent XSS attacks
**REST API Security**:
- No authentication currently implemented
- Recommend using reverse proxy (nginx, Caddy) with auth for public exposure
- CORS not configured (same-origin only)
- No rate limiting (add middleware if needed)
### Template System
Templates are pre-parsed at startup. The API handler returns HTML fragments that htmx inserts into the page. Out-of-band swaps update the file tree sidebar without full page reload.