diff --git a/src/dlw/admin.py b/src/dlw/admin.py index 792cf95..6bb6c8e 100644 --- a/src/dlw/admin.py +++ b/src/dlw/admin.py @@ -1,129 +1,24 @@ -from flask import Flask, render_template_string, request, redirect, url_for -from werkzeug.utils import secure_filename -import os -import time -from . import git_ops - -app = Flask(__name__) -app.config['UPLOAD_FOLDER'] = os.path.join(os.getcwd(), 'downloads') -app.secret_key = 'sehr_geheimer_schluessel' # Muss für Flash-Messages gesetzt werden - -# --- Hilfsfunktionen für die Content-Erzeugung --- - -def generate_markdown_content(data, article_slug): - """Erzeugt den Markdown-Inhalt inklusive YAML Frontmatter.""" - - # Pfade, wie sie im fertigen SSG-Blog verwendet werden - pdf_path = f"/downloads/{article_slug}.pdf" - audio_path = f"/downloads/{article_slug}.mp3" - - markdown_template = f""" ---- -Title: {data['title']} -Date: {time.strftime("%Y-%m-%d %H:%M")} -Slug: {article_slug} -Description: {data['description']} -Abstract: {data['abstract']} -PDF_Download: {pdf_path} -Audio_Download: {audio_path} ---- - -{data['article_body']} -""" - return markdown_template.strip() - -# --- Flask Routen --- - -@app.route('/', methods=['GET']) -def new_article_form(): - # Einfache HTML-Formular-Definition (in einem echten Template besser) - form_html = """ -
{data['abstract']}
- -... Gerenderter Artikeltext hier (simuliert) ...
- - - """ - return preview_html - -@app.route('/publish', methods=['POST']) -def publish_article(): - # ACHTUNG: Daten aus der Vorschau sind möglicherweise im POST-Body - markdown_content = request.form.get('content_data') - - if not markdown_content: - return "Fehler: Keine Inhaltsdaten zur Veröffentlichung.", 400 - - # Daten extrahieren (simplifiziert) - lines = markdown_content.split('\n') - title_line = [l for l in lines if l.startswith('Title:')][0] - article_title = title_line.split(':', 1)[1].strip() - - # Slug aus dem Titel ableiten - article_slug = secure_filename(article_title).lower().replace('-', '_') - filename = f"{article_slug}.md" - article_path = os.path.join(os.getcwd(), 'content', filename) - - download_paths = [] - - # 1. Speichern des Markdown-Artikels - try: - with open(article_path, 'w', encoding='utf-8') as f: - f.write(markdown_content) - except IOError as e: - return f"Fehler beim Speichern der Datei: {e}", 500 - - # 2. Speichern der Uploads (Muss hier noch integriert werden, da Uploads in /preview gehandhabt wurden. - # In einem Produktivsystem müsste Flask die Uploads in einer Session zwischenspeichern.) - - # WICHTIG: Die Logic zum Verschieben der tatsächlichen PDF/MP3 Dateien - # muss hier implementiert werden, um sie in das 'downloads' Verzeichnis - # zu verschieben, bevor der Git-Commit erfolgt. - - # 3. Git-Operation: Commit und Push - success, message = git_ops.commit_and_push_article(article_path, download_paths, article_title) - - if success: - return f"{message}
Forgejo Action läuft jetzt.
" - else: - return f"Veröffentlichung fehlgeschlagen: {message}
", 500 - +from flask import Flask, request, flash +from .marvin_ops import MarvinClient +import os + +app = Flask(__name__) +# ... (Konfiguration wie zuvor) ... + +@app.route('/publish', methods=['POST']) +def publish_article(): + # ... (Markdown Generierung wie zuvor) ... + + # Datei-Upload Handling + download_paths = [] + for key in ['pdf_file', 'audio_file']: + file = request.files.get(key) + if file and file.filename: + path = os.path.join(app.config['UPLOAD_FOLDER'], file.filename) + file.save(path) + download_paths.append(path) + + # Git Push + from .import git_ops + success, msg = git_ops.commit_and_push_article(article_path, download_paths, "Titel") + return f"Status: {msg}" \ No newline at end of file