diff options
Diffstat (limited to 'lib/api')
| -rw-r--r-- | lib/api/preferences.py | 41 | ||||
| -rw-r--r-- | lib/api/server.py | 2 | ||||
| -rw-r--r-- | lib/api/stitch_plan.py | 20 |
3 files changed, 12 insertions, 51 deletions
diff --git a/lib/api/preferences.py b/lib/api/preferences.py deleted file mode 100644 index bc8328b8..00000000 --- a/lib/api/preferences.py +++ /dev/null @@ -1,41 +0,0 @@ -# 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 26efa521..5625d77d 100644 --- a/lib/api/server.py +++ b/lib/api/server.py @@ -18,7 +18,6 @@ from werkzeug.serving import make_server from ..utils.json import InkStitchJSONProvider from .simulator import simulator from .stitch_plan import stitch_plan -from .preferences import preferences from .page_specs import page_specs from .lang import languages # this for electron axios @@ -50,7 +49,6 @@ 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(preferences, url_prefix="/preferences") self.app.register_blueprint(page_specs, url_prefix="/page_specs") self.app.register_blueprint(languages, url_prefix="/languages") diff --git a/lib/api/stitch_plan.py b/lib/api/stitch_plan.py index c70efd98..5e9a57c1 100644 --- a/lib/api/stitch_plan.py +++ b/lib/api/stitch_plan.py @@ -5,9 +5,9 @@ from flask import Blueprint, g, jsonify +from ..exceptions import InkstitchException, format_uncaught_exception from ..stitch_plan import stitch_groups_to_stitch_plan - stitch_plan = Blueprint('stitch_plan', __name__) @@ -16,10 +16,14 @@ def get_stitch_plan(): if not g.extension.get_elements(): return dict(colors=[], stitch_blocks=[], commands=[]) - metadata = g.extension.get_inkstitch_metadata() - collapse_len = metadata['collapse_len_mm'] - min_stitch_len = metadata['min_stitch_len_mm'] - patches = g.extension.elements_to_stitch_groups(g.extension.elements) - stitch_plan = stitch_groups_to_stitch_plan(patches, collapse_len=collapse_len, min_stitch_len=min_stitch_len) - - return jsonify(stitch_plan) + try: + metadata = g.extension.get_inkstitch_metadata() + collapse_len = metadata['collapse_len_mm'] + min_stitch_len = metadata['min_stitch_len_mm'] + patches = g.extension.elements_to_stitch_groups(g.extension.elements) + stitch_plan = stitch_groups_to_stitch_plan(patches, collapse_len=collapse_len, min_stitch_len=min_stitch_len) + return jsonify(stitch_plan) + except InkstitchException as exc: + return jsonify({"error_message": str(exc)}), 500 + except Exception: + return jsonify({"error_message": format_uncaught_exception()}), 500 |
