62 lines
1.6 KiB
Python
62 lines
1.6 KiB
Python
# routes/main_routes.py - Main Application Routes
|
|
|
|
import os
|
|
from flask import Blueprint, jsonify, send_from_directory, session
|
|
|
|
from config import DATABASE, VOICES
|
|
from auth import login_required, get_current_user
|
|
|
|
main_bp = Blueprint('main', __name__)
|
|
|
|
|
|
@main_bp.route('/')
|
|
@login_required
|
|
def index():
|
|
"""Serve main application page."""
|
|
return send_from_directory('templates', 'index.html')
|
|
|
|
|
|
@main_bp.route('/static/<path:filename>')
|
|
def serve_static(filename):
|
|
"""Serve static files."""
|
|
return send_from_directory('static', filename)
|
|
|
|
|
|
@main_bp.route('/api/voices', methods=['GET'])
|
|
@login_required
|
|
def get_voices():
|
|
"""Get available TTS voices."""
|
|
return jsonify({'voices': VOICES})
|
|
|
|
|
|
@main_bp.route('/api/stats', methods=['GET'])
|
|
@login_required
|
|
def get_stats():
|
|
"""Get database statistics."""
|
|
from db import get_db
|
|
|
|
db = get_db()
|
|
cursor = db.cursor()
|
|
|
|
cursor.execute('SELECT COUNT(*) as count FROM projects')
|
|
project_count = cursor.fetchone()['count']
|
|
|
|
cursor.execute('SELECT COUNT(*) as count FROM chapters')
|
|
chapter_count = cursor.fetchone()['count']
|
|
|
|
cursor.execute('SELECT COUNT(*) as count FROM markdown_blocks')
|
|
block_count = cursor.fetchone()['count']
|
|
|
|
cursor.execute('SELECT COUNT(*) as count FROM pdf_documents')
|
|
pdf_count = cursor.fetchone()['count']
|
|
|
|
db_size = os.path.getsize(DATABASE) if os.path.exists(DATABASE) else 0
|
|
|
|
return jsonify({
|
|
'projects': project_count,
|
|
'chapters': chapter_count,
|
|
'blocks': block_count,
|
|
'pdf_documents': pdf_count,
|
|
'database_size_mb': round(db_size / (1024 * 1024), 2)
|
|
})
|