add babycode preview

This commit is contained in:
2026-05-28 10:00:10 +03:00
parent daf205f200
commit 27314f34a5
6 changed files with 104 additions and 7 deletions

21
app/routes/api.py Normal file
View File

@@ -0,0 +1,21 @@
from flask import Blueprint, request
from ..auth import is_logged_in, hard_login_required, get_active_user
from ..lib.babycode import babycode_to_html
from ..models import APIRateLimits
bp = Blueprint('api', __name__, url_prefix='/api/')
@bp.post('/babycode-preview/')
@hard_login_required
def babycode_preview():
user = get_active_user()
if not APIRateLimits.is_allowed(user.id, 'babycode_preview', 5):
return {'error': 'too many requests'}, 429
markup = str(request.json.get('markup', ''))
if not markup:
return {'error': 'markup field missing or invalid type'}, 400
banned_tags = request.json.get('banned_tags', [])
if not isinstance(banned_tags, list):
return {'error': 'banned_tags field is invalid type'}, 400
rendered = babycode_to_html(markup, banned_tags).result
return {'html': rendered}