From 440aa129d96805b6b0e9479929b35309f2b33d42 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Tue, 4 Aug 2020 09:54:17 +1000 Subject: [PATCH] disable media get / posts when collection closed https://forums.ankiweb.net/t/countdown-to-events-exams-addon-official-thread/1093/4?u=dae --- qt/aqt/mediasrv.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/qt/aqt/mediasrv.py b/qt/aqt/mediasrv.py index 96a3ec83c..32414a457 100644 --- a/qt/aqt/mediasrv.py +++ b/qt/aqt/mediasrv.py @@ -124,6 +124,10 @@ def allroutes(pathin): try: if flask.request.method == "POST": + if not aqt.mw.col: + print(f"collection not open, ignore request for {path}") + return flask.make_response(f"Collection not open", HTTPStatus.NOT_FOUND) + if path == "graphData": body = request.data data = graph_data(aqt.mw.col, **from_json_bytes(body)) @@ -196,6 +200,13 @@ def _redirectWebExports(path): if re.fullmatch(pattern, subPath): return addMgr.addonsFolder(), addonPath + print(f"couldn't locate item in add-on folder {path}") + return None + + if not aqt.mw.col: + print(f"collection not open, ignore request for {path}") + return None + return aqt.mw.col.media.dir(), path