File size: 970 Bytes
f7150c2
184de22
f7150c2
341331a
f7150c2
83787dd
f7150c2
 
184de22
f7150c2
 
 
 
 
62d1bab
f7150c2
 
c631550
f7150c2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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)