diff --git a/app.py b/app.py index fea7e62..ea10b9b 100644 --- a/app.py +++ b/app.py @@ -22,6 +22,8 @@ from flask import ( send_from_directory, jsonify, Response, + redirect, + url_for, ) from flask_socketio import SocketIO, emit, join_room, leave_room @@ -365,6 +367,25 @@ def search_page(): # Call the function to search messages search_results = search_messages(keywords) + # If there's exactly one search result, redirect directly to that room + if len(search_results) == 1: + room_result = search_results[0] + room_name = room_result["room_name"] + + # Build the redirect URL with current parameters + redirect_params = {} + if username and username != "guest": + redirect_params["username"] = username + + # Preserve other URL parameters like model, voice, etc. + for param in ["model", "voice"]: + value = request.args.get(param) + if value: + redirect_params[param] = value + + redirect_url = url_for("chat", room_name=room_name, **redirect_params) + return redirect(redirect_url) + return render_template( "search.html", rooms=rooms, diff --git a/static/js/utils.js b/static/js/utils.js new file mode 100644 index 0000000..afb4d86 --- /dev/null +++ b/static/js/utils.js @@ -0,0 +1,12 @@ +/** + * Utility functions for the OpenCompletion application + */ + +/** + * Convert a string to a URL-friendly slug + * @param {string} str - The string to slugify + * @returns {string} - The slugified string + */ +function slugify(str) { + return str.toLowerCase().replace(/\s+/g, '-').replace(/[^\w-]+/g, ''); +} \ No newline at end of file diff --git a/templates/base.html b/templates/base.html index 65560ea..7ed5d62 100644 --- a/templates/base.html +++ b/templates/base.html @@ -22,6 +22,9 @@ + + + +