feat: 实现资源(图片、音频)查询,完善README
This commit is contained in:
@@ -16,5 +16,8 @@ def create_app(config_class='config.Config'):
|
||||
|
||||
from app.routes.matters import matter_bp
|
||||
app.register_blueprint(matter_bp, url_prefix="/matter")
|
||||
|
||||
from app.routes.assets import asset_bp
|
||||
app.register_blueprint(asset_bp, url_prefix="/asset")
|
||||
|
||||
return app
|
||||
@@ -0,0 +1,14 @@
|
||||
from flask import Blueprint, send_file
|
||||
from ..utils import assets
|
||||
|
||||
asset_bp = Blueprint("asset", __name__, "/asset")
|
||||
|
||||
@asset_bp.route("/pic/<id>")
|
||||
def search_matter(id: str):
|
||||
path = "../resources/assets/pics/" + assets.readPicPath(id)
|
||||
return send_file(path)
|
||||
|
||||
@asset_bp.route("/sound/<id>")
|
||||
def select_matter(id: str):
|
||||
path = "../resources/assets/sounds/" + assets.readSoundPath(id)
|
||||
return send_file(path)
|
||||
@@ -0,0 +1,16 @@
|
||||
import json
|
||||
|
||||
def readAssetsList() -> dict:
|
||||
with open("resources/assets/index.json", "r", encoding="utf8") as f:
|
||||
text = f.read()
|
||||
result = json.loads(text)
|
||||
|
||||
return result
|
||||
|
||||
assets_list = readAssetsList()
|
||||
|
||||
def readPicPath(id: str):
|
||||
return assets_list["pics"][id]
|
||||
|
||||
def readSoundPath(id: str):
|
||||
return assets_list["sounds"][id]
|
||||
+3
-1
@@ -7,8 +7,10 @@ def readCardList() -> dict:
|
||||
|
||||
return result
|
||||
|
||||
card_list = readCardList()
|
||||
|
||||
def readCard(id: str):
|
||||
path = readCardList().get(id, -1)
|
||||
path = card_list.get(id, -1)
|
||||
if (path == -1):
|
||||
return {"message": f"No Card {id}"}
|
||||
with open(f"resources/cards/{path}.json", "r", encoding="utf8") as f:
|
||||
|
||||
@@ -14,8 +14,11 @@ def readMatchList() -> dict:
|
||||
|
||||
return result
|
||||
|
||||
matter_list = readMatterList()
|
||||
match_list = readMatchList()
|
||||
|
||||
def readMatter(id: str):
|
||||
path = readMatterList().get(id, -1)
|
||||
path = matter_list.get(id, -1)
|
||||
if (path == -1):
|
||||
return {"message": f"No Matter {id}"}
|
||||
with open(f"resources/matters/{path}.json", "r", encoding="utf8") as f:
|
||||
@@ -25,7 +28,7 @@ def readMatter(id: str):
|
||||
return {"message": "OK", "content": result}
|
||||
|
||||
def selectMatter(id: str):
|
||||
matter_id = readMatchList().get(id, -1)
|
||||
matter_id = match_list.get(id, -1)
|
||||
if (matter_id == -1):
|
||||
return {"message": f"No Matter {id}"}
|
||||
|
||||
|
||||
@@ -7,8 +7,10 @@ def readReactionList() -> dict:
|
||||
|
||||
return result
|
||||
|
||||
reaction_list = readReactionList()
|
||||
|
||||
def readReaction(id: str):
|
||||
path = readReactionList().get(id, -1)
|
||||
path = reaction_list.get(id, -1)
|
||||
if (path == -1):
|
||||
return {"message": f"No Reaction {id}"}
|
||||
with open(f"resources/reactions/{path}.json", "r", encoding="utf8") as f:
|
||||
|
||||
Reference in New Issue
Block a user