mirror of
https://git.srhtnin.garden/sarah/SaraView.git
synced 2026-10-14 02:38:11 +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
@@ -114,6 +114,7 @@ class Source:
|
||||
def LocalFile(self, Root: str, RelativePath: str) -> Path: ...
|
||||
def Book(self, Root: str, RelativePath: str) -> dict: ...
|
||||
def Graph(self, Root: str, RelativePath: str) -> dict: ...
|
||||
def Diagram(self, Source: str, ThemePalette: dict[str, str], FontSize: int) -> bytes: ...
|
||||
|
||||
@property
|
||||
def CanWrite(self) -> bool:
|
||||
@@ -275,6 +276,9 @@ class LocalSource(Source):
|
||||
|
||||
return BuildLocalGraph(self, Root, RelativePath)
|
||||
|
||||
def Diagram(self, Source: str, ThemePalette: dict[str, str], FontSize: int) -> bytes:
|
||||
raise SourceError("Diagrams are drawn by a SaraView server.")
|
||||
|
||||
|
||||
class ServerSource(Source):
|
||||
"""A SaraView server, through the same /api endpoints the web frontend
|
||||
@@ -464,6 +468,11 @@ class ServerSource(Source):
|
||||
# A big root takes the server a while to read through.
|
||||
return self._Json("GET", "/graph", params=self._At(Root, RelativePath), timeout=120)
|
||||
|
||||
def Diagram(self, Source: str, ThemePalette: dict[str, str], FontSize: int) -> bytes:
|
||||
"""A ```mermaid block as a PNG, drawn by the server (Diagrams.py)."""
|
||||
Body = {"Source": Source, "Palette": ThemePalette, "FontSize": FontSize}
|
||||
return self._Request("POST", "/diagram", json=Body).content
|
||||
|
||||
|
||||
def MakeSource(Config: AppConfig, Token: str = "") -> Source:
|
||||
return ServerSource(Config, Token) if Config.Mode == "Server" else LocalSource(Config)
|
||||
Reference in new issue
Block a user