deduplicate admin HTML escaping

This commit is contained in:
Daniel 2026-05-08 04:45:02 +02:00
parent acbd42aa43
commit 03285532cb

View file

@ -2,6 +2,11 @@
// ADMIN.JS — Admin panel: users, settings, stats
// ============================================================
function adminEscapeHtml(str) {
if (!str) return '';
return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
}
(function() {
var loaded = false;
@ -253,10 +258,7 @@
.catch(function() { showToast('Request failed', 'error'); });
}
function esc(str) {
if (!str) return '';
return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
}
var esc = adminEscapeHtml;
})();
@ -830,7 +832,7 @@
}
function getValue(id) { var el = document.getElementById(id); return el ? el.value.trim() : ''; }
function setValue(id, value) { var el = document.getElementById(id); if (el) el.value = value; }
function escAssistant(str) { return String(str || '').replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;'); }
var escAssistant = adminEscapeHtml;
})();
// ============================================================
@ -863,10 +865,7 @@
}
});
function esc(str) {
if (!str) return '';
return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
}
var esc = adminEscapeHtml;
function loadAdminModels() {
fetch('/api/admin/config/models', { headers: getAuthHeaders() })
@ -1194,10 +1193,7 @@
if (e.target.id === 'admin-tts-search' && e.key === 'Enter') { e.preventDefault(); discoverTTS(); }
});
function esc(str) {
if (!str) return '';
return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
}
var esc = adminEscapeHtml;
function loadTTSConfig() {
fetch('/api/admin/config/tts', { headers: getAuthHeaders() })
@ -1382,10 +1378,7 @@
if (e.target.id === 'admin-stt-search' && e.key === 'Enter') { e.preventDefault(); discoverSTT(); }
});
function esc(str) {
if (!str) return '';
return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
}
var esc = adminEscapeHtml;
function loadSTTConfig() {
fetch('/api/admin/config/stt', { headers: getAuthHeaders() })
@ -1568,10 +1561,7 @@
if (e.target.id === 'admin-embed-search' && e.key === 'Enter') { e.preventDefault(); discoverEmbeddings(); }
});
function esc(str) {
if (!str) return '';
return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
}
var esc = adminEscapeHtml;
function loadEmbeddingConfig() {
fetch('/api/admin/config/embeddings', { headers: getAuthHeaders() })