Rename an existing session title
(self, session_id: str)
| 1023 | self.send_json_response({'error': str(e)}, status_code=500) |
| 1024 | |
| 1025 | def handle_rename_session(self, session_id: str): |
| 1026 | """Rename an existing session title""" |
| 1027 | try: |
| 1028 | session = db.get_session(session_id) |
| 1029 | if not session: |
| 1030 | self.send_json_response({"error": "Session not found"}, status_code=404) |
| 1031 | return |
| 1032 | |
| 1033 | content_length = int(self.headers.get('Content-Length', 0)) |
| 1034 | if content_length == 0: |
| 1035 | self.send_json_response({"error": "Request body required"}, status_code=400) |
| 1036 | return |
| 1037 | |
| 1038 | post_data = self.rfile.read(content_length) |
| 1039 | data = json.loads(post_data.decode('utf-8')) |
| 1040 | new_title: str = data.get('title', '').strip() |
| 1041 | |
| 1042 | if not new_title: |
| 1043 | self.send_json_response({"error": "Title cannot be empty"}, status_code=400) |
| 1044 | return |
| 1045 | |
| 1046 | db.update_session_title(session_id, new_title) |
| 1047 | updated_session = db.get_session(session_id) |
| 1048 | |
| 1049 | self.send_json_response({ |
| 1050 | "message": "Session renamed successfully", |
| 1051 | "session": updated_session |
| 1052 | }) |
| 1053 | |
| 1054 | except json.JSONDecodeError: |
| 1055 | self.send_json_response({"error": "Invalid JSON"}, status_code=400) |
| 1056 | except Exception as e: |
| 1057 | self.send_json_response({"error": f"Failed to rename session: {str(e)}"}, status_code=500) |
| 1058 | |
| 1059 | def send_json_response(self, data, status_code: int = 200): |
| 1060 | """Send a JSON (UTF-8) response with CORS headers. Safe against client disconnects.""" |
no test coverage detected