From 220a17d8cb6c98ca92f9a9bbfbcf5bc606a42f76 Mon Sep 17 00:00:00 2001 From: LeonspaceX Date: Sun, 7 Dec 2025 18:33:42 +0800 Subject: [PATCH] =?UTF-8?q?Feat:=E5=A2=9E=E5=8A=A0=E6=B8=85=E9=99=A4?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E6=8C=89=E9=92=AE=EF=BC=8C=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=BC=80=E5=85=B3=E5=85=AC=E5=91=8A=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api_server.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/api_server.py b/api_server.py index 2d80a6c..7d89ea9 100644 --- a/api_server.py +++ b/api_server.py @@ -454,11 +454,31 @@ def get_notice(): """公开接口:获取当前公告内容与版本""" try: ensure_default_notice() - return jsonify(get_current_notice()), 200 + notice_data = get_current_notice() + # 获取显示状态,默认为开启 + display = get_config("show_notice", "true") + notice_data["display"] = display + return jsonify(notice_data), 200 except Exception as e: return jsonify({"error": str(e)}), 500 +@app.route('/admin/notice_switch', methods=['POST']) +@require_admin +def admin_notice_switch(): + """管理员接口:开关公告显示""" + try: + data = request.get_json() or {} + val = str(data.get('value', 'true')).lower() + if val not in ['true', 'false']: + return jsonify({"status": "Fail", "reason": "Invalid value"}), 400 + + set_config("show_notice", val) + return jsonify({"status": "OK"}), 200 + except Exception as e: + return jsonify({"status": "Fail", "reason": str(e)}), 500 + + @app.route('/admin/modify_notice', methods=['POST']) @require_admin def admin_modify_notice(): @@ -1240,3 +1260,4 @@ def initialize_database(): # === 启动 === if __name__ == '__main__': app.run(host='127.0.0.1', port=5000) # 监听IP&端口,建议监听127.0.0.1并配置反向代理 +