7f9c5c874a
- backend/tools/hasher.py: POST /api/hash/sha256 and /api/hash/bcrypt (bcrypt added to requirements) - backend/tools/base64tool.py: POST /api/base64/encode and /api/base64/decode - backend/tools/jwtdecoder.py: POST /api/jwt/decode (signature verification disabled) - backend/tools/passwordgen.py: POST /api/password/generate with charset and length options - backend/tools/timestamp.py: POST /api/timestamp/convert (unix<->date, ISO 8601 + German format) - backend/tools/textdiff.py: POST /api/text/diff returning structured added/removed/unchanged lines - All blueprints registered in app.py and tools/__init__.py - React components with copy button, dark/light mode support via CSS variables - ToolOverview rebuilt as card grid; App.jsx routes added for all tools Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
38 lines
1.3 KiB
Python
38 lines
1.3 KiB
Python
from flask import Blueprint, request, jsonify
|
|
import difflib
|
|
from util.logger import logger
|
|
from auth.token import verify_token
|
|
|
|
textdiff_blueprint = Blueprint('textdiff_tool', __name__)
|
|
|
|
|
|
@textdiff_blueprint.route('/api/text/diff', methods=['POST'])
|
|
def text_diff():
|
|
user = verify_token()
|
|
if not user:
|
|
return jsonify({"message": "Nicht autorisiert"}), 401
|
|
try:
|
|
data = request.get_json()
|
|
text1 = data.get("text1", "")
|
|
text2 = data.get("text2", "")
|
|
|
|
lines1 = text1.splitlines(keepends=True)
|
|
lines2 = text2.splitlines(keepends=True)
|
|
|
|
result = []
|
|
for line in difflib.unified_diff(lines1, lines2, lineterm=''):
|
|
if line.startswith('+++') or line.startswith('---') or line.startswith('@@'):
|
|
continue
|
|
if line.startswith('+'):
|
|
result.append({"type": "added", "text": line[1:]})
|
|
elif line.startswith('-'):
|
|
result.append({"type": "removed", "text": line[1:]})
|
|
else:
|
|
result.append({"type": "unchanged", "text": line[1:] if line.startswith(' ') else line})
|
|
|
|
logger.info(f"Text-Diff erstellt von {user['username']}")
|
|
return jsonify({"diff": result})
|
|
except Exception as e:
|
|
logger.error(f"Fehler Text-Diff: {e}")
|
|
return jsonify({"message": "Fehler beim Vergleich"}), 500
|