From 97528be0f4d7352fffcdfe2f154139ba3660525a Mon Sep 17 00:00:00 2001
From: Boody <69832947+bitboody@users.noreply.github.com>
Date: Tue, 2 Jun 2026 06:55:15 +0300
Subject: [PATCH] Add custom web search result count
* fixed confusing credentials prompt
* fix(setup): return status from create_default_admin function
* fix(setup): initialize admin creation status in main function
* fix(setup): enhance admin creation feedback and status handling
* Enhance admin user login messages with conditional feedback based on creation status
* Refine admin user creation feedback messages for clarity and actionability and formatted code
* Add fallback error message for admin creation failure in setup script
* Add run script for Uvicorn with dotenv integration
* Refactor server runner to use argparse for host and port configuration
* Remove captured output print statement from server runner
* Fix server runner to ensure cross-platform compatibility and improve log handling
* Remove run.py script to match main repo
* feat: add custom option for search result count in settings
* fix: enforce minimum and maximum values for custom search result count
---
static/index.html | 16 ++++++++++------
static/js/settings.js | 38 ++++++++++++++++++++++++++++++++++++--
2 files changed, 46 insertions(+), 8 deletions(-)
diff --git a/static/index.html b/static/index.html
index e170718..d427c53 100644
--- a/static/index.html
+++ b/static/index.html
@@ -1602,12 +1602,16 @@
-
+
+
+
+
diff --git a/static/js/settings.js b/static/js/settings.js
index 69602fa..1677947 100644
--- a/static/js/settings.js
+++ b/static/js/settings.js
@@ -1075,6 +1075,7 @@ var _searchKeyFields = {
async function initSearchSettings() {
var provSel = el('set-searchProvider');
var countSel = el('set-searchResultCount');
+ var countCustomInput = el('set-searchResultCountCustom');
var urlInput = el('set-searchUrl');
var urlRow = el('set-searchUrlRow');
var keyInput = el('set-searchApiKey');
@@ -1106,15 +1107,37 @@ async function initSearchSettings() {
loadKeyForProvider(prov);
}
+ function updateCountDisplay() {
+ var val = _settings.search_result_count || 5;
+ var presets = ['3', '5', '10', '20'];
+ if (presets.includes(String(val))) {
+ countSel.value = String(val);
+ countCustomInput.style.display = 'none';
+ } else {
+ countSel.value = 'custom';
+ countCustomInput.value = Math.max(1, Math.min(100, val));
+ countCustomInput.style.display = 'block';
+ }
+ }
+
try {
var res = await fetch('/api/auth/settings', { credentials: 'same-origin' });
_settings = await res.json();
if (_settings.search_provider) provSel.value = _settings.search_provider;
- if (_settings.search_result_count) countSel.value = String(_settings.search_result_count);
+ updateCountDisplay();
if (_settings.search_url) urlInput.value = _settings.search_url;
if (_settings.google_pse_cx) cxInput.value = _settings.google_pse_cx;
} catch (e) { console.warn('Failed to load search settings', e); }
+ countSel.addEventListener('change', function() {
+ if (this.value === 'custom') {
+ countCustomInput.style.display = 'block';
+ countCustomInput.focus();
+ } else {
+ countCustomInput.style.display = 'none';
+ }
+ });
+
updateVisibility();
async function refreshStatus() {
@@ -1142,9 +1165,20 @@ async function initSearchSettings() {
async function saveSearch() {
try {
var prov = provSel.value;
+ var resultCount;
+ if (countSel.value === 'custom') {
+ var customVal = parseInt(countCustomInput.value, 10);
+ if (isNaN(customVal) || customVal < 1 || customVal > 100) {
+ resultCount = _settings.search_result_count || 5;
+ } else {
+ resultCount = customVal;
+ }
+ } else {
+ resultCount = parseInt(countSel.value, 10);
+ }
var payload = {
search_provider: prov,
- search_result_count: parseInt(countSel.value, 10),
+ search_result_count: resultCount,
search_url: urlInput.value.trim(),
google_pse_cx: cxInput.value.trim(),
};