重构: 切换存储至SQLite,启用INI配置与API Key校验

This commit is contained in:
2026-02-09 17:10:11 +08:00
parent d5edbc0723
commit b9828a1b13
30 changed files with 2721 additions and 612 deletions

View File

@ -64,17 +64,21 @@ def main():
from waitress import serve
print("✓ Waitress WSGI server imported")
# Server configuration from environment variables
# Server configuration from INI file (with environment variable fallbacks)
host = Config.HOST
port = Config.PORT
threads = Config.THREADS
connection_limit = Config.CONNECTION_LIMIT
channel_timeout = Config.CHANNEL_TIMEOUT
base_url = Config.BASE_URL
print(f"Starting Waitress server on {host}:{port}")
print(f"- Threads: {threads}")
print(f"- Connection limit: {connection_limit}")
print(f"- Channel timeout: {channel_timeout}s")
print(f"- Base URL: {base_url}")
print(f"- Upload folder: {Config.UPLOAD_FOLDER}")
print(f"- Output folder: {Config.OUTPUT_FOLDER}")
print("Press Ctrl+C to stop the server")
print("=" * 50)
print("Available API endpoints:")
@ -93,7 +97,31 @@ def main():
print(" GET /config - Configuration")
print(" GET / - Web interface")
print("=" * 50)
print(f"Configuration: {Config.to_dict()}")
# Display configuration source info
try:
from src.gasflux.config_reader import config_reader
print("Configuration loaded from INI file:")
print(f" - Config file: {config_reader._get_config_file_path() or 'gasflux.ini (default)'}")
print(f" - Uploads path: {config_reader.uploads_path}")
print(f" - Outputs path: {config_reader.outputs_path}")
# Check API keys
from src.gasflux.app import app
with app.app_context():
from src.gasflux.db import get_db
db = get_db()
key_count = db.execute("SELECT COUNT(*) FROM api_keys WHERE revoked = 0").fetchone()[0]
print(f" - API keys: {key_count} active")
if key_count == 0:
print("\n⚠️ No active API keys found!")
print(" Run 'python create_api_key.py' to create your first API key")
print(" Or use bootstrap key in API requests: -H 'X-Admin-Bootstrap-Key: bootstrap_key_2024'")
except Exception as e:
print(f"Configuration info error: {e}")
print(f"\nFull configuration: {Config.to_dict()}")
# Start the server with valid Waitress parameters
serve(