Spaces:
Running
Running
sunheycho
commited on
Commit
·
6a00dc7
1
Parent(s):
68329d1
Fix API endpoint errors
Browse files- Added missing /api/heartbeat endpoint to handle session keepalive
- Removed @fresh_login_required from /api/status to prevent 302 redirects
- Added manual session validation for /api/status endpoint
- Fixed 405 Method Not Allowed and 302 redirect errors
api.py
CHANGED
@@ -1569,24 +1569,17 @@ def login():
|
|
1569 |
@app.route('/logout')
|
1570 |
def logout():
|
1571 |
logout_user()
|
1572 |
-
|
1573 |
-
|
1574 |
-
|
1575 |
-
|
1576 |
-
|
1577 |
-
|
1578 |
-
|
1579 |
-
|
1580 |
-
|
1581 |
-
|
1582 |
-
|
1583 |
-
samesite='None',
|
1584 |
-
secure=True,
|
1585 |
-
httponly=True,
|
1586 |
-
)
|
1587 |
-
except Exception as e:
|
1588 |
-
print(f"[DEBUG] Error deleting remember_token cookie: {e}")
|
1589 |
-
return resp
|
1590 |
|
1591 |
@app.route('/product-comparison-lite', methods=['GET'])
|
1592 |
@login_required
|
@@ -2363,8 +2356,14 @@ def vision_rag_query():
|
|
2363 |
})
|
2364 |
|
2365 |
@app.route('/api/status', methods=['GET'])
|
2366 |
-
@fresh_login_required
|
2367 |
def status():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2368 |
return jsonify({
|
2369 |
"status": "online",
|
2370 |
"models": {
|
@@ -2373,7 +2372,7 @@ def status():
|
|
2373 |
"vit": vit_model is not None and vit_processor is not None
|
2374 |
},
|
2375 |
"device": "GPU" if torch.cuda.is_available() else "CPU",
|
2376 |
-
"user":
|
2377 |
})
|
2378 |
|
2379 |
# Root route is now handled by serve_react function
|
|
|
1569 |
@app.route('/logout')
|
1570 |
def logout():
|
1571 |
logout_user()
|
1572 |
+
session.clear()
|
1573 |
+
return redirect(url_for('login'))
|
1574 |
+
|
1575 |
+
@app.route('/api/heartbeat', methods=['POST'])
|
1576 |
+
def heartbeat():
|
1577 |
+
"""Keep session alive"""
|
1578 |
+
user_id = session.get('user_id')
|
1579 |
+
if user_id:
|
1580 |
+
return jsonify({"status": "alive", "user_id": user_id})
|
1581 |
+
else:
|
1582 |
+
return jsonify({"status": "no_session"}), 401
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1583 |
|
1584 |
@app.route('/product-comparison-lite', methods=['GET'])
|
1585 |
@login_required
|
|
|
2356 |
})
|
2357 |
|
2358 |
@app.route('/api/status', methods=['GET'])
|
|
|
2359 |
def status():
|
2360 |
+
# Manual session check instead of @fresh_login_required
|
2361 |
+
user_id = session.get('user_id')
|
2362 |
+
username = session.get('username')
|
2363 |
+
|
2364 |
+
if not user_id or not username:
|
2365 |
+
return jsonify({"error": "Not authenticated"}), 401
|
2366 |
+
|
2367 |
return jsonify({
|
2368 |
"status": "online",
|
2369 |
"models": {
|
|
|
2372 |
"vit": vit_model is not None and vit_processor is not None
|
2373 |
},
|
2374 |
"device": "GPU" if torch.cuda.is_available() else "CPU",
|
2375 |
+
"user": username
|
2376 |
})
|
2377 |
|
2378 |
# Root route is now handled by serve_react function
|