Commit 35faddad authored by yxli's avatar yxli
parents cb51a624 58d17d33
Pipeline #35939 passed with stages
in 2 minutes and 4 seconds
from datetime import timedelta
import os
import random
import sys
......@@ -6,6 +7,9 @@ from flask import Flask, render_template, request, redirect, url_for, session, j
from data_utils import load_card_database, card_to_tags, compare_tags
from flask_session import Session
import redis
base_path = getattr(sys, "_MEIPASS", os.path.dirname(__file__))
template_folder = os.path.join(base_path, "templates")
......@@ -16,6 +20,19 @@ app.secret_key = os.getenv("SECRET_KEY", "你自己的随机 Secret Key")
db = load_card_database()
redis_url = os.getenv("REDIS_URL", None)
if redis_url:
app.config['SESSION_TYPE'] = 'redis'
app.config['SESSION_REDIS'] = redis.from_url(redis_url)
app.config['SESSION_PERMANENT'] = False
app.config['SESSION_USE_SIGNER'] = True
app.config['SESSION_KEY_PREFIX'] = 'session:'
app.config['PERMANENT_SESSION_LIFETIME'] = timedelta(hours=1)
Session(app)
print("✅ Redis session 已启用")
else:
print("⚠️ 未设置 REDIS_URL,使用默认 cookie session")
def filter_db(mode):
"""
......@@ -50,6 +67,8 @@ def start():
# 3. 初始化 session
session.clear()
if redis_url:
session.permanent = True
session["mode"] = mode
session["max_attempts"] = max_attempts
session["guess_count"] = 0
......
Flask==3.1.0
flask_cors==5.0.1
Flask_SocketIO==5.5.1
pandas==2.2.3
redis==3.5.3
Requests==2.32.3
bidict==0.23.1
blinker==1.9.0
cachelib==0.13.0
certifi==2025.4.26
charset-normalizer==3.4.2
click==8.1.8
Flask==3.1.0
flask-cors==5.0.1
Flask-Session==0.8.0
Flask-SocketIO==5.5.1
h11==0.16.0
idna==3.10
itsdangerous==2.2.0
Jinja2==3.1.6
MarkupSafe==3.0.2
msgspec==0.19.0
numpy==2.2.5
pandas==2.2.3
python-dateutil==2.9.0.post0
python-engineio==4.12.0
python-socketio==5.13.0
pytz==2025.2
redis==3.5.3
requests==2.32.3
simple-websocket==1.1.0
six==1.17.0
tzdata==2025.2
urllib3==2.4.0
Werkzeug==3.1.3
wsproto==1.2.0
......@@ -196,7 +196,14 @@
{% endif %}
<script>
async function fetchSuggestions() {
function debounce(fn, delay) {
let timeout = null;
return function (...args) {
clearTimeout(timeout);
timeout = setTimeout(() => fn.apply(this, args), delay);
};
}
async function _fetchSuggestions() {
const input = document.getElementById("guess");
const hid = document.getElementById("guess_id");
const sug = document.getElementById("suggestions");
......@@ -219,6 +226,7 @@
}
sug.hidden = false;
}
const fetchSuggestions = debounce(_fetchSuggestions, 300);
document.addEventListener('click', e => {
if (!e.target.closest('#guess')) {
document.getElementById("suggestions").hidden = true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment