diff --git a/app.py b/app.py index 2bf8db0..f030561 100644 --- a/app.py +++ b/app.py @@ -10,6 +10,7 @@ load_dotenv(find_dotenv()) app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = os.getenv("SQLALCHEMY_DATABASE_URI") app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False +app.config["KI_DATA_PATH"] = os.path.dirname(__file__) + "/data" db = SQLAlchemy(app) migrate = Migrate(app, db) diff --git a/ki/routes.py b/ki/routes.py index 616250f..20c12cf 100644 --- a/ki/routes.py +++ b/ki/routes.py @@ -1,4 +1,5 @@ -from flask import request +import os +from flask import jsonify, make_response, request, send_file from ki.models import Skill from app import app @@ -32,3 +33,21 @@ def get_skills(): 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") +