major update/remote host the JS and user loader

This commit is contained in:
2026-04-26 12:15:06 +03:00
parent ab1ba5c0ab
commit 037a84d6bb
9 changed files with 1106 additions and 0 deletions

View File

@@ -2,6 +2,8 @@ from flask import Blueprint, request, jsonify
from db import get_db
import json
from datetime import datetime
import os
from flask import make_response
api = Blueprint('api', __name__)
@@ -255,3 +257,34 @@ def farm_status():
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})
# ------------------------------------------------------------------
# GET /api/bot
# Serves the modular bot code concatenated into a single response
# ------------------------------------------------------------------
@api.route('/api/bot', methods=['GET'])
def serve_bot():
bot_dir = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'bot_modules')
if not os.path.exists(bot_dir):
return make_response("Bot modules directory not found", 404)
modules = sorted([f for f in os.listdir(bot_dir) if f.endswith('.js')])
combined_code = []
combined_code.append("(function() {")
combined_code.append(" 'use strict';\n")
for module in modules:
with open(os.path.join(bot_dir, module), 'r', encoding='utf-8') as f:
combined_code.append(f" // --- BEGIN {module} ---")
combined_code.append(f.read())
combined_code.append(f" // --- END {module} ---\n")
combined_code.append("})();")
response = make_response("\\n".join(combined_code))
response.headers['Content-Type'] = 'application/javascript'
# Prevent caching so updates are instant
response.headers['Cache-Control'] = 'no-cache, no-store, must-revalidate'
return response