from flask import Flask, request, jsonify import os from datetime import datetime app = Flask(__name__) # Ensure output folder exists os.makedirs("markdown_files", exist_ok=True) @app.route("/create-md", methods=["POST"]) def create_markdown(): data = request.get_json() if not data or "title" not in data or "content" not in data: return jsonify({"error": "Missing 'title' or 'content'"}), 400 title = data["title"].strip() content = data["content"] # Sanitize filename filename = f"{title.replace(' ', '_')}_{int(datetime.utcnow().timestamp())}.md" filepath = os.path.join("markdown_files", filename) # Write markdown content with open(filepath, "w", encoding="utf-8") as f: f.write(f"# {title}\n\n{content}") return jsonify({ "message": "Markdown file created", "filename": filename, "path": filepath }), 201 if __name__ == "__main__": app.run(host="0.0.0.0", port=7860)