mirror of
https://git.srhtnin.garden/sarah/SaraView.git
synced 2026-10-15 02:43:17 +02:00
Client: Mermaid diagrams, drawn by the server
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
292614c696
commit
f99b227cc3
9 files changed
+446
-16
No files matched your search
@@ -29,6 +29,7 @@ from Auth import (
|
||||
from BookReader import ReadBookForFile
|
||||
from Blame import LoadBlame, RenameUserInBlame, UpdateBlameOnSave
|
||||
from Core import NormalizeRelativePath, ResolvePath
|
||||
from Diagrams import DiagramError, DiagramsUnavailable, RenderDiagram
|
||||
from Embeds import BuildOgTags
|
||||
from Editor import WriteTextFile
|
||||
from Explorer import (
|
||||
@@ -833,6 +834,25 @@ def PutSettingsEndpoint(NewSettings: dict, CurrentUser: dict = Depends(GetCurren
|
||||
return SaveSettings(CurrentUser["Username"], NewSettings)
|
||||
|
||||
|
||||
class DiagramRequest(BaseModel):
|
||||
Source: str
|
||||
Palette: dict[str, str] = {}
|
||||
FontSize: int = 14
|
||||
|
||||
|
||||
# A ```mermaid block as a PNG, for the desktop client (the web view draws its
|
||||
# own). Palette is the client's theme by role, so it matches the client.
|
||||
@Application.post("/api/diagram")
|
||||
async def PostDiagramEndpoint(Body: DiagramRequest, CurrentUser: dict = Depends(GetCurrentUserOrGuest)) -> Response:
|
||||
try:
|
||||
Png = await RenderDiagram(Body.Source, Body.Palette, Body.FontSize)
|
||||
except DiagramError as Error:
|
||||
raise HTTPException(status_code=422, detail=str(Error))
|
||||
except DiagramsUnavailable as Error:
|
||||
raise HTTPException(status_code=503, detail=str(Error))
|
||||
return Response(content=Png, media_type="image/png")
|
||||
|
||||
|
||||
@Application.get("/api/themes")
|
||||
def GetThemesEndpoint(CurrentUser: dict = Depends(GetCurrentUser)) -> list[str]:
|
||||
return ListThemeNames()
|
||||
|
||||
Reference in new issue
Block a user