# -*- coding: utf-8 -*-
from flask import Flask, request, render_template_string, jsonify
import os
app = Flask(__name__)
app.secret_key = "memo3211"
MEMO_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), "memo.txt")
# 如果文件不存在则创建
if not os.path.exists(MEMO_PATH):
with open(MEMO_PATH, "w", encoding="utf-8") as f:
f.write("")
# ===================== HTML 模板 =====================
HTML = '''
📒 在线备忘录
'''
# ===================== 路由 =====================
@app.route("/", methods=["GET"])
def memo_page():
with open(MEMO_PATH, "r", encoding="utf-8") as f:
content = f.read()
return render_template_string(HTML, content=content)
@app.route("/save", methods=["POST"])
def save_memo():
data = request.get_json()
content = data.get("content", "")
with open(MEMO_PATH, "w", encoding="utf-8") as f:
f.write(content)
return jsonify({"status": "ok"})
# ===================== 启动 =====================
if __name__ == "__main__":
app.run(host="0.0.0.0", port=3211, debug=False)