Add fullscreen file editor for email templates, project docs and agent files

This commit is contained in:
eric 2026-02-23 10:23:02 +00:00
parent 7844e82c95
commit 5c75ad575d
3 changed files with 274 additions and 66 deletions

85
app.py
View file

@ -3494,6 +3494,91 @@ def delete_project_file(filename):
return redirect(url_for('files'))
@app.route('/files/project/save/<filename>', methods=['POST'])
@login_required
def save_project_file(filename):
"""Speichert den Inhalt einer Projektdatei (JSON POST)."""
base_dir = os.path.dirname(__file__)
filepath = os.path.join(base_dir, filename)
if os.path.dirname(os.path.abspath(filepath)) != os.path.abspath(base_dir):
return jsonify({'ok': False, 'error': 'Zugriff verweigert'}), 403
if not filename.lower().endswith(('.md', '.txt')):
return jsonify({'ok': False, 'error': 'Nur .md und .txt Dateien editierbar'}), 400
try:
data = request.get_json()
content = data.get('content', '') if data else ''
with open(filepath, 'w', encoding='utf-8') as f:
f.write(content)
return jsonify({'ok': True})
except Exception as e:
return jsonify({'ok': False, 'error': str(e)}), 500
@app.route('/files/agent/<agent_key>/save/<filename>', methods=['POST'])
@login_required
def save_agent_file(agent_key, filename):
"""Speichert den Inhalt einer Agent-Datei (JSON POST)."""
agents_base = os.path.join(os.path.dirname(__file__), 'agents')
work_dir = os.path.join(agents_base, agent_key, 'work')
filepath = os.path.join(work_dir, filename)
if not os.path.abspath(filepath).startswith(os.path.abspath(work_dir)):
return jsonify({'ok': False, 'error': 'Zugriff verweigert'}), 403
if not filename.lower().endswith(('.md', '.txt', '.json', '.csv')):
return jsonify({'ok': False, 'error': 'Dateityp nicht editierbar'}), 400
try:
data = request.get_json()
content = data.get('content', '') if data else ''
with open(filepath, 'w', encoding='utf-8') as f:
f.write(content)
return jsonify({'ok': True})
except Exception as e:
return jsonify({'ok': False, 'error': str(e)}), 500
@app.route('/files/editor')
@login_required
def file_editor():
"""Vollbild-Editor für Dateien (Email-Vorlagen, Projektdokumente, Agent-Dateien)."""
file_type = request.args.get('type', 'email') # email | project | agent
filename = request.args.get('name', '')
agent_key = request.args.get('agent', '')
# Inhalt laden
content = ''
error = ''
try:
base = os.path.dirname(__file__)
if file_type == 'email':
fp = os.path.join(base, 'emails', filename)
safe = os.path.abspath(fp).startswith(os.path.abspath(os.path.join(base, 'emails')))
elif file_type == 'project':
fp = os.path.join(base, filename)
safe = os.path.dirname(os.path.abspath(fp)) == os.path.abspath(base)
elif file_type == 'agent':
fp = os.path.join(base, 'agents', agent_key, 'work', filename)
safe = os.path.abspath(fp).startswith(os.path.abspath(os.path.join(base, 'agents', agent_key, 'work')))
else:
safe = False
if not safe:
error = 'Zugriff verweigert'
elif not os.path.isfile(fp):
error = 'Datei nicht gefunden'
else:
with open(fp, 'r', encoding='utf-8', errors='replace') as f:
content = f.read()
except Exception as e:
error = str(e)
return render_template('file_editor.html',
file_type=file_type,
filename=filename,
agent_key=agent_key,
content=content,
error=error,
)
@app.route('/emails', methods=['GET', 'POST'])
@login_required
def emails():