22 lines
856 B
Python
22 lines
856 B
Python
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}
|