Add 5 new tools: QR-Code, Markdown, Color Converter, JSON Formatter, Regex Tester
- backend/tools/qrcode_gen.py: POST /api/qrcode/generate, returns base64 PNG (qrcode[pil]) - backend/tools/markdown_tool.py: POST /api/markdown/render, extensions: tables/fenced_code/nl2br - backend/tools/colorconverter.py: POST /api/color/convert, HEX/RGB/HSL via colorsys (no deps) - backend/tools/jsonformatter.py: POST /api/json/format, returns formatted JSON with line/col errors - backend/tools/regextester.py: POST /api/regex/test, flags i/m/s, returns matches with positions - QrCodeTool.jsx: generate + download PNG button - MarkdownTool.jsx: split editor/preview, debounce 500ms, white preview bg - ColorConverterTool.jsx: color swatch preview, per-format copy buttons - JsonFormatterTool.jsx: indent toggle 2/4, pre result box with copy - RegexTesterTool.jsx: debounce 400ms, yellow match highlighting, flag checkboxes - All blueprints registered in app.py; qrcode[pil] + markdown added to requirements.txt Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
from flask import Blueprint, request, jsonify
|
||||
import re
|
||||
from util.logger import logger
|
||||
from auth.token import verify_token
|
||||
|
||||
regex_blueprint = Blueprint('regex_tool', __name__)
|
||||
|
||||
_FLAG_MAP = {"i": re.IGNORECASE, "m": re.MULTILINE, "s": re.DOTALL}
|
||||
|
||||
|
||||
@regex_blueprint.route('/api/regex/test', methods=['POST'])
|
||||
def test_regex():
|
||||
user = verify_token()
|
||||
if not user:
|
||||
return jsonify({"message": "Nicht autorisiert"}), 401
|
||||
try:
|
||||
data = request.get_json(silent=True) or {}
|
||||
pattern = data.get("pattern", "")
|
||||
text = data.get("text", "")
|
||||
flags_list = data.get("flags", [])
|
||||
|
||||
combined = 0
|
||||
for f in flags_list:
|
||||
if f in _FLAG_MAP:
|
||||
combined |= _FLAG_MAP[f]
|
||||
|
||||
try:
|
||||
compiled = re.compile(pattern, combined)
|
||||
except re.error as e:
|
||||
return jsonify({"matches": [], "count": 0, "error": str(e)})
|
||||
|
||||
matches = [
|
||||
{"match": m.group(), "start": m.start(), "end": m.end(), "groups": list(m.groups())}
|
||||
for m in compiled.finditer(text)
|
||||
]
|
||||
|
||||
logger.info(f"Regex getestet von {user['username']}")
|
||||
return jsonify({"matches": matches, "count": len(matches), "error": None})
|
||||
except Exception as e:
|
||||
logger.error(f"Fehler Regex-Tester: {e}")
|
||||
return jsonify({"message": "Fehler beim Testen"}), 500
|
||||
Reference in New Issue
Block a user