98bb34f094
- Fix AttributeError crash on empty request body in md5, hasher, textdiff,
jwtdecoder, timestamp, passwordgen (get_json without silent=True / or {})
- Fix memory exhaustion in ipcalc: replace list(network.hosts()) with direct
arithmetic — safe for /8 and larger networks
- Fix O(1M) loop in cronexplainer.get_next_runs: rewrite to skip by
month/day/hour instead of iterating every minute
- Fix connection leak in notes.ensure_table: add try/finally around conn.close
- Fix admin._ensure_tables / notes._ensure_table running DDL on every request:
guard with module-level flags (_tables_initialized, _table_ready)
- Fix update_website returning 200 when no row matched; delete_website returning
success when nothing was deleted; add rowcount checks for both
- Add role validation in admin create_user / update_user (_VALID_ROLES guard)
- Add delimiter length guard in csvviewer (csv.reader requires single char)
- Fix loremipsum: wrap int(count) in try/except ValueError → 400 response
- Fix auth/token: use auth_header[7:] instead of fragile .replace()
- Fix app.py: remove duplicate import sys; cache DB liveness check with 30s TTL
to avoid a new TCP connection on every frontend page load; move api/setup
path guard before DB check
- Replace FileHandler with RotatingFileHandler (5 MB / 3 backups) in logger;
fix relative log paths to absolute paths anchored to __file__
- Wrap all DB connections in try/finally conn.close() throughout admin and notes
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
53 lines
1.6 KiB
Python
53 lines
1.6 KiB
Python
from flask import Blueprint, request, jsonify
|
|
import csv
|
|
import io
|
|
from util.logger import logger
|
|
from auth.token import verify_token
|
|
|
|
csv_blueprint = Blueprint('csv_tool', __name__)
|
|
|
|
MAX_ROWS = 500
|
|
|
|
|
|
@csv_blueprint.route('/api/csv/parse', methods=['POST'])
|
|
def parse_csv():
|
|
user = verify_token()
|
|
if not user:
|
|
return jsonify({"message": "Nicht autorisiert"}), 401
|
|
try:
|
|
data = request.get_json(silent=True) or {}
|
|
text = data.get("text", "")
|
|
delimiter = data.get("delimiter", ",")
|
|
|
|
# Handle escaped tab
|
|
if delimiter == "\\t" or delimiter == "\t":
|
|
delimiter = "\t"
|
|
if not delimiter:
|
|
delimiter = ","
|
|
if len(delimiter) != 1:
|
|
return jsonify({"message": "Delimiter muss genau ein Zeichen sein"}), 400
|
|
|
|
reader = csv.reader(io.StringIO(text), delimiter=delimiter)
|
|
all_rows = list(reader)
|
|
|
|
if not all_rows:
|
|
return jsonify({"headers": [], "rows": [], "total_rows": 0, "truncated": False})
|
|
|
|
headers = all_rows[0]
|
|
data_rows = all_rows[1:]
|
|
total_rows = len(data_rows)
|
|
truncated = total_rows > MAX_ROWS
|
|
|
|
return jsonify({
|
|
"headers": headers,
|
|
"rows": data_rows[:MAX_ROWS],
|
|
"total_rows": total_rows,
|
|
"truncated": truncated,
|
|
})
|
|
|
|
except csv.Error as e:
|
|
return jsonify({"message": f"Ungültiges CSV: {e}"}), 400
|
|
except Exception as e:
|
|
logger.error(f"Fehler csvviewer: {e}")
|
|
return jsonify({"message": "Fehler beim Verarbeiten des CSV"}), 500
|