diff --git a/app.py b/app.py index 90c92ed..664ca26 100644 --- a/app.py +++ b/app.py @@ -182,6 +182,31 @@ def api_update_note(note_id): return jsonify(note) + +@app.route('/api/notes//rename', methods=['POST']) +def api_rename_note(note_id): + """重命名笔记标题""" + data = request.get_json() + new_title = data.get('title', '').strip() + + if not new_title: + return jsonify({'error': '标题不能为空'}), 400 + + notes = load_notes() + note = next((n for n in notes if n['id'] == note_id), None) + + if not note: + return jsonify({'error': 'Note not found'}), 404 + + note['title'] = new_title + note['updated_at'] = datetime.now().strftime('%Y-%m-%d %H:%M:%S') + + # 重新排序 + notes = sorted(notes, key=lambda x: (not x.get('pinned', False), x.get('updated_at', '')), reverse=True) + save_notes(notes) + + return jsonify({'success': True, 'title': new_title, 'note': note}) + @app.route('/api/notes//title', methods=['POST']) def api_regenerate_title(note_id): """手动重新生成标题""" diff --git a/templates/index.html b/templates/index.html index 99bb401..82c646a 100644 --- a/templates/index.html +++ b/templates/index.html @@ -151,6 +151,10 @@