import logging
import os
-from typing import List
+from typing import List, Literal
from auth import (
FLATNOTES_PASSWORD,
@app.get("/api/notes", response_model=List[NoteModel])
async def get_notes(
- include_content: bool = False, _: str = Depends(validate_token)
+ start: int = 0,
+ limit: int = None,
+ sort: Literal["filename", "lastModified"] = "filename",
+ order: Literal["asc", "desc"] = "asc",
+ include_content: bool = False,
+ _: str = Depends(validate_token),
):
"""Get all notes."""
+ notes = flatnotes.get_notes()
+ notes.sort(
+ key=lambda note: note.last_modified
+ if sort == "lastModified"
+ else note.filename,
+ reverse=order == "desc",
+ )
return [
NoteModel.dump(note, include_content=include_content)
- for note in flatnotes.get_notes()
+ for note in notes[start : None if limit is None else start + limit]
]