import os from flask import jsonify, make_response, request, send_file from ki.models import Skill from app import app def models_to_list(models): models_list = [] for model in models: models_list.append(model.to_dict()) return models_list @app.route("/") def hello_world(): return "KI" @app.route("/skills") def get_skills(): skills_query = Skill.query if "search" in request.args: skills_query = skills_query.filter(Skill.name.startswith(request.args.get("search"))) skills = skills_query.order_by(Skill.name) \ .limit(10) \ .all() api_skills = models_to_list(skills) response_data = {"skills": api_skills} return response_data @app.route("/skills//icon") def get_skill_icon(skill_id): skill = Skill.query.get(skill_id) if skill is None: return make_response(jsonify([]), 404) icons_base_path = app.config["KI_DATA_PATH"] + "/skill_icons/" icon_base_path = icons_base_path + str(skill.id) icon_svg_path = icon_base_path + ".svg" if os.path.exists(icon_svg_path): return send_file(icon_svg_path, mimetype="image/svg") fallback_icon_path = app.config["KI_DATA_PATH"] + "/skill_icons/placeholder.svg" return send_file(fallback_icon_path, mimetype="image/svg")