revert and farm fix
This commit is contained in:
@@ -231,3 +231,27 @@ def upload_market_data():
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return jsonify({'ok': True})
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# POST/GET /api/farm_status — TM reports warehouse_full; dashboard reads it
|
||||
# ------------------------------------------------------------------
|
||||
@api.route('/api/farm_status', methods=['POST', 'GET'])
|
||||
def farm_status():
|
||||
player_id = request.args.get('player_id')
|
||||
if not player_id:
|
||||
return jsonify({'error': 'no player_id'}), 400
|
||||
kv_key = f'farm_status_{player_id}'
|
||||
conn = get_db()
|
||||
if request.method == 'POST':
|
||||
data = request.get_json(silent=True) or {}
|
||||
conn.execute('''
|
||||
INSERT INTO kv_store (key, value, updated_at) VALUES (?, ?, ?)
|
||||
ON CONFLICT(key) DO UPDATE SET value=excluded.value, updated_at=excluded.updated_at
|
||||
''', (kv_key, json.dumps(data), datetime.utcnow().isoformat()))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return jsonify({'ok': True})
|
||||
else:
|
||||
row = conn.execute('SELECT value FROM kv_store WHERE key=?', (kv_key,)).fetchone()
|
||||
conn.close()
|
||||
return jsonify(json.loads(row['value']) if row else {'warehouse_full': False})
|
||||
|
||||
Reference in New Issue
Block a user