diff --git a/qt/aqt/mediasrv.py b/qt/aqt/mediasrv.py index a3a38d1e2..66fb2ecb9 100644 --- a/qt/aqt/mediasrv.py +++ b/qt/aqt/mediasrv.py @@ -14,6 +14,7 @@ from typing import Optional import aqt from anki.collection import Collection +from anki.rsbackend import from_json_bytes from anki.utils import devMode from aqt.qt import * from aqt.utils import aqt_data_folder @@ -78,7 +79,7 @@ class MediaServer(threading.Thread): class RequestHandler(http.server.SimpleHTTPRequestHandler): - timeout = 1 + timeout = 10 mw: Optional[aqt.main.AnkiQt] = None def do_GET(self): @@ -181,7 +182,9 @@ class RequestHandler(http.server.SimpleHTTPRequestHandler): cmd = self.path[len("/_anki/") :] if cmd == "graphData": - data = graph_data(self.mw.col) + content_length = int(self.headers['Content-Length']) + body = self.rfile.read(content_length) + data = graph_data(self.mw.col, **from_json_bytes(body)) else: self.send_error(HTTPStatus.NOT_FOUND, "Method not found") return @@ -195,10 +198,13 @@ class RequestHandler(http.server.SimpleHTTPRequestHandler): self.wfile.write(data) -def graph_data(col: Collection) -> bytes: - graphs = col.backend.graphs(search="", days=0) - return graphs - +def graph_data(col: Collection, search: str, days: str) -> bytes: + try: + return col.backend.graphs(search=search, days=days) + except Exception as e: + # likely searching error + print(e) + return b'' # work around Windows machines with incorrect mime type RequestHandler.extensions_map[".css"] = "text/css" diff --git a/ts/package.json b/ts/package.json index 5c1fb531f..9f2cbd610 100644 --- a/ts/package.json +++ b/ts/package.json @@ -10,6 +10,7 @@ "@types/d3-selection": "^1.4.1", "@types/d3-shape": "^1.3.2", "@types/d3-transition": "^1.1.6", + "@types/lodash.debounce": "^4.0.6", "@types/lodash.throttle": "^4.1.6", "@types/long": "^4.0.1", "@typescript-eslint/eslint-plugin": "^2.11.0", @@ -47,6 +48,7 @@ "d3-selection": "^1.4.1", "d3-shape": "^1.3.7", "d3-transition": "^1.3.2", + "lodash.debounce": "^4.0.8", "lodash.throttle": "^4.1.1", "protobufjs": "^6.9.0" }, diff --git a/ts/src/html/graphs.html b/ts/src/html/graphs.html index 33a634c71..cb91994c1 100644 --- a/ts/src/html/graphs.html +++ b/ts/src/html/graphs.html @@ -4,9 +4,11 @@
- +