from flask import Blueprint, render_template, send_from_directory import sqlite3 import json import os from config import MAIN_DB, UPLOADS_DIR from utils.theme_engine import render_gkachele_template public_bp = Blueprint('public', __name__) @public_bp.route('/') def landing(): """Landing page""" return render_template('landing_real.html') @public_bp.route('/site/') def public_site(slug): """Sitio público del cliente""" conn = sqlite3.connect(MAIN_DB) c = conn.cursor() c.execute('SELECT id, theme, content_json, status, user_id FROM sites WHERE slug = ?', (slug,)) site = c.fetchone() conn.close() if not site or site[3] != 'published': return "Sitio no encontrado o no publicado", 404 try: return render_gkachele_template(site[1], json.loads(site[2]), site[0], site[4]) except Exception as e: return f"Error renderizando sitio: {e}", 500 @public_bp.route('/uploads/') def serve_upload(filename): """Servir archivos subidos""" return send_from_directory(UPLOADS_DIR, filename)