commit 25ea18b8715022da687b9a26b33d5387f27ffd29 Author: SoulGateKey Date: Sat Oct 5 08:14:31 2024 +0800 Initial Commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f1e9216 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/frontend/node_modules/ diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..359bb53 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# 默认忽略的文件 +/shelf/ +/workspace.xml diff --git a/backend/app.py b/backend/app.py new file mode 100644 index 0000000..d17b60a --- /dev/null +++ b/backend/app.py @@ -0,0 +1,46 @@ +from flask import Flask, jsonify, request +from flask_cors import CORS +from models import db, AimeCard, Mai2ProfileDetail, Mai2ItemCard +import yaml + +with open('config.yaml', 'r') as file: + config = yaml.safe_load(file) +app = Flask(__name__) +app.config['SQLALCHEMY_DATABASE_URI'] = config['database']['uri'] +db.init_app(app) +CORS(app) + + +@app.route('/api/query', methods=['GET']) +def query_info(): + access_code = request.args.get('accesscode') + card = AimeCard.query.filter_by(access_code=access_code).first() + + if not card: + return jsonify({'message': 'Access code not found'}), 404 + + latest_detail = Mai2ProfileDetail.query.filter_by(user=card.user).order_by(Mai2ProfileDetail.id.desc()).first() + + item_cards = Mai2ItemCard.query.filter_by(user=card.user).all() + items = [ + {'cardId': item.cardId, 'cardTypeId': item.cardTypeId, 'startDate': item.startDate, 'endDate': item.endDate} for + item in item_cards] + + response_data = { + 'user': card.user, + 'details': { + 'userName': latest_detail.userName if latest_detail else None, + 'playerRating': latest_detail.playerRating if latest_detail else None, + 'playCount': latest_detail.playCount if latest_detail else None, + 'lastRomVersion': latest_detail.lastRomVersion if latest_detail else None, + 'lastDataVersion': latest_detail.lastDataVersion if latest_detail else None, + 'banstate': latest_detail.banstate if latest_detail else None, + }, + 'items': items, + } + + return jsonify(response_data) + + +if __name__ == '__main__': + app.run(host=config['flask']['host'], port=config['flask']['port'], debug=True) # 允许从外部访问 diff --git a/backend/models.py b/backend/models.py new file mode 100644 index 0000000..9e7dd97 --- /dev/null +++ b/backend/models.py @@ -0,0 +1,29 @@ +from flask_sqlalchemy import SQLAlchemy + +db = SQLAlchemy() + +class AimeCard(db.Model): + __tablename__ = 'aime_card' + id = db.Column(db.Integer, primary_key=True) + access_code = db.Column(db.String(50), unique=True) + user = db.Column(db.String(50)) + +class Mai2ProfileDetail(db.Model): + __tablename__ = 'mai2_profile_detail' + id = db.Column(db.Integer, primary_key=True) + user = db.Column(db.Integer, nullable=False) + userName = db.Column(db.String, nullable=False) + playerRating = db.Column(db.Integer, nullable=False) + playCount = db.Column(db.Integer, nullable=False) + lastRomVersion = db.Column(db.String, nullable=True) + lastDataVersion = db.Column(db.String, nullable=True) + banstate = db.Column(db.Integer, nullable=False) + +class Mai2ItemCard(db.Model): + __tablename__ = 'mai2_item_card' + id = db.Column(db.Integer, primary_key=True) + cardId = db.Column(db.String, nullable=False) + cardTypeId = db.Column(db.Integer, nullable=False) + startDate = db.Column(db.String, nullable=False) + endDate = db.Column(db.String, nullable=False) + user = db.Column(db.Integer, nullable=False) diff --git a/config_example.yaml b/config_example.yaml new file mode 100644 index 0000000..111fab6 --- /dev/null +++ b/config_example.yaml @@ -0,0 +1,6 @@ +database: + uri: 'mysql+pymysql://aime:YOURPASSWORD@DATABASEIP:3306/aime' + +flask: + host: '0.0.0.0' + port: 5000 diff --git a/frontend/index.html b/frontend/index.html new file mode 100644 index 0000000..5d687e2 --- /dev/null +++ b/frontend/index.html @@ -0,0 +1,13 @@ + + + + + + 数据查询 + + + +
+ + + diff --git a/frontend/package.json b/frontend/package.json new file mode 100644 index 0000000..bd999ae --- /dev/null +++ b/frontend/package.json @@ -0,0 +1,16 @@ +{ + "name": "frontend", + "version": "1.0.0", + "scripts": { + "dev": "vite", + "build": "vite build", + "serve": "vite preview" + }, + "dependencies": { + "vue": "^3.0.0" + }, + "devDependencies": { + "@vitejs/plugin-vue": "^5.1.4", + "vite": "^5.4.8" + } +} diff --git a/frontend/src/App.vue b/frontend/src/App.vue new file mode 100644 index 0000000..5882722 --- /dev/null +++ b/frontend/src/App.vue @@ -0,0 +1,168 @@ + + + + + diff --git a/frontend/src/main.js b/frontend/src/main.js new file mode 100644 index 0000000..684d042 --- /dev/null +++ b/frontend/src/main.js @@ -0,0 +1,4 @@ +import { createApp } from 'vue'; +import App from './App.vue'; + +createApp(App).mount('#app'); diff --git a/frontend/vite.config.js b/frontend/vite.config.js new file mode 100644 index 0000000..1ebc4fc --- /dev/null +++ b/frontend/vite.config.js @@ -0,0 +1,6 @@ +import { defineConfig } from 'vite'; +import vue from '@vitejs/plugin-vue'; + +export default defineConfig({ + plugins: [vue()], +});