diff options
| author | Lex Neva <github.com@lexneva.name> | 2022-07-29 18:17:50 -0400 |
|---|---|---|
| committer | Lex Neva <github.com@lexneva.name> | 2023-02-18 22:34:47 -0500 |
| commit | 98bc2e2ff9c843a64c3db355290ed541e6708312 (patch) | |
| tree | 593edf118780f9902437a306323595c6846acb24 /lib/api | |
| parent | a0834e2e7c2f2b6734877a8ee922c01e8c9330ba (diff) | |
add preferences UI including cache settings
Diffstat (limited to 'lib/api')
| -rw-r--r-- | lib/api/preferences.py | 41 | ||||
| -rw-r--r-- | lib/api/server.py | 2 |
2 files changed, 43 insertions, 0 deletions
diff --git a/lib/api/preferences.py b/lib/api/preferences.py new file mode 100644 index 00000000..bc8328b8 --- /dev/null +++ b/lib/api/preferences.py @@ -0,0 +1,41 @@ +# Authors: see git history +# +# Copyright (c) 2010 Authors +# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details. + +from flask import Blueprint, g, jsonify, request + +from ..utils.cache import get_stitch_plan_cache +from ..utils.settings import global_settings + +preferences = Blueprint('preferences', __name__) + + +@preferences.route('/', methods=["POST"]) +def update_preferences(): + metadata = g.extension.get_inkstitch_metadata() + metadata.update(request.json['this_svg_settings']) + global_settings.update(request.json['global_settings']) + + # cache size may have changed + stitch_plan_cache = get_stitch_plan_cache() + stitch_plan_cache.size_limit = global_settings['cache_size'] * 1024 * 1024 + stitch_plan_cache.cull() + + return jsonify({"status": "success"}) + + +@preferences.route('/', methods=["GET"]) +def get_preferences(): + metadata = g.extension.get_inkstitch_metadata() + return jsonify({"status": "success", + "this_svg_settings": metadata, + "global_settings": global_settings + }) + + +@preferences.route('/clear_cache', methods=["POST"]) +def clear_cache(): + stitch_plan_cache = get_stitch_plan_cache() + stitch_plan_cache.clear(retry=True) + return jsonify({"status": "success"}) diff --git a/lib/api/server.py b/lib/api/server.py index 93b08ff1..626e412e 100644 --- a/lib/api/server.py +++ b/lib/api/server.py @@ -18,6 +18,7 @@ from ..utils.json import InkStitchJSONEncoder from .install import install from .simulator import simulator from .stitch_plan import stitch_plan +from .preferences import preferences class APIServer(Thread): @@ -45,6 +46,7 @@ class APIServer(Thread): self.app.register_blueprint(simulator, url_prefix="/simulator") self.app.register_blueprint(stitch_plan, url_prefix="/stitch_plan") self.app.register_blueprint(install, url_prefix="/install") + self.app.register_blueprint(preferences, url_prefix="/preferences") @self.app.before_request def store_extension(): |
