From 6b7af1301fb4aa931ea6607f5161f63418f0b4c4 Mon Sep 17 00:00:00 2001 From: Tiger Date: Sun, 8 Feb 2026 20:55:19 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0description.py?= =?UTF-8?q?=EF=BC=8C=E4=BF=AE=E5=A4=8D=E4=B8=AD=E6=96=87=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/__init__.py | 1 + app/models/__Init__.py | 0 app/routes/assets.py | 4 ++-- app/routes/cards.py | 6 +++--- app/routes/matters.py | 6 +++--- app/routes/pages.py | 9 +++++++-- app/routes/reactions.py | 10 +++++----- app/utils/index.py | 12 ++++++++++++ resources/description.json | 5 +++++ 9 files changed, 38 insertions(+), 15 deletions(-) delete mode 100644 app/models/__Init__.py create mode 100644 app/utils/index.py create mode 100644 resources/description.json diff --git a/app/__init__.py b/app/__init__.py index 8fb305d..4e31aec 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -3,6 +3,7 @@ from flask import Flask def create_app(config_class='config.Config'): app = Flask(__name__) app.config.from_object(config_class) + app.json.ensure_ascii = False # type: ignore # 注册蓝图 from app.routes.pages import page_bp diff --git a/app/models/__Init__.py b/app/models/__Init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/app/routes/assets.py b/app/routes/assets.py index 9255fde..4b28cc6 100644 --- a/app/routes/assets.py +++ b/app/routes/assets.py @@ -1,14 +1,14 @@ ''' 资源文件读取路由 ''' -from flask import Blueprint, send_file +from flask import Blueprint, send_file, jsonify from ..utils import assets asset_bp = Blueprint("asset", __name__, "/asset") @asset_bp.route("/list") def asset_list(): - return assets.readAssetsList() + return jsonify(assets.readAssetsList()) @asset_bp.route("/pic/") def find_pic(id: str): diff --git a/app/routes/cards.py b/app/routes/cards.py index fd92f42..881acb2 100644 --- a/app/routes/cards.py +++ b/app/routes/cards.py @@ -1,15 +1,15 @@ ''' 卡牌定义文件读取路由 ''' -from flask import Blueprint +from flask import Blueprint, jsonify from ..utils import cards card_bp = Blueprint("card", __name__, "/card") @card_bp.route("/list") def card_list(): - return cards.readCardList() + return jsonify(cards.readCardList()) @card_bp.route("/id/") def search_card(id): - return cards.readCard(id) \ No newline at end of file + return jsonify(cards.readCard(id)) \ No newline at end of file diff --git a/app/routes/matters.py b/app/routes/matters.py index 7d17378..2dfa4f1 100644 --- a/app/routes/matters.py +++ b/app/routes/matters.py @@ -1,15 +1,15 @@ ''' 物质定义文件读取路由 ''' -from flask import Blueprint +from flask import Blueprint, jsonify from ..utils import matters matter_bp = Blueprint("matter", __name__, "/matter") @matter_bp.route("/list") def matter_list(): - return matters.readMatterList() + return jsonify(matters.readMatterList()) @matter_bp.route("/id/") def search_matter(id): - return matters.readMatter(id) \ No newline at end of file + return jsonify(matters.readMatter(id)) \ No newline at end of file diff --git a/app/routes/pages.py b/app/routes/pages.py index 2d54d4a..e86eff1 100644 --- a/app/routes/pages.py +++ b/app/routes/pages.py @@ -2,9 +2,14 @@ 网页路由 ''' from flask import Blueprint, jsonify +from ..utils import index page_bp = Blueprint("page", __name__, "/") @page_bp.route("/") -def index(): - return jsonify({"code": "200", "message": "Service normal"}) \ No newline at end of file +def index_page(): + return jsonify({"code": "200", "message": "Service normal"}) + +@page_bp.route("/index") +def description(): + return jsonify(index.readIndex()) \ No newline at end of file diff --git a/app/routes/reactions.py b/app/routes/reactions.py index aa5ab5d..13aeb8b 100644 --- a/app/routes/reactions.py +++ b/app/routes/reactions.py @@ -1,23 +1,23 @@ ''' 反应定义文件读取路由 ''' -from flask import Blueprint +from flask import Blueprint, jsonify from ..utils import reactions reaction_bp = Blueprint("reaction", __name__, "/reaction") @reaction_bp.route("list") def reaction_list(): - return reactions.readReactionList() + return jsonify(reactions.readReactionList()) @reaction_bp.route("/match") def match_list(): - return reactions.readMatchList() + return jsonify(reactions.readMatchList()) @reaction_bp.route("/id/") def search_reaction(id): - return reactions.readReaction(id) + return jsonify(reactions.readReaction(id)) @reaction_bp.route("/match/") def select_reaction(id): - return reactions.selectReaction(id) \ No newline at end of file + return jsonify(reactions.selectReaction(id)) \ No newline at end of file diff --git a/app/utils/index.py b/app/utils/index.py new file mode 100644 index 0000000..4b6e846 --- /dev/null +++ b/app/utils/index.py @@ -0,0 +1,12 @@ +''' +读取 description.json 的内容 +''' +import json + +def readIndex() -> dict: + + with open("resources/description.json", "r", encoding="utf8") as f: + text = f.read() + result = json.loads(text) + + return result \ No newline at end of file diff --git a/resources/description.json b/resources/description.json new file mode 100644 index 0000000..50bc002 --- /dev/null +++ b/resources/description.json @@ -0,0 +1,5 @@ +{ + "name": "Offical Example", + "author": "Paper Chemis Community Team", + "uuid": "6b3d2702c1c345499fc8617d664b3627" +} \ No newline at end of file