fix: save gemini keys in settings + add AI connection test
- Add gemini_api_key and gemini_model to allowed keys in settings save handler - Add POST /admin/settings/test-ai endpoint for testing Gemini/OpenAI connection - Add "Probar conexion IA" card in settings page with live feedback Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
5277d47c14
commit
c702dbadc1
@@ -1750,8 +1750,42 @@ HTML;
|
||||
<button type="submit" class="btn-primary">Guardar configuración</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div class="card" style="margin-top:16px">
|
||||
<div class="card-h">Probar conexión IA</div>
|
||||
<div class="card-b">
|
||||
<div style="display:flex;align-items:center;gap:12px;flex-wrap:wrap">
|
||||
<button type="button" class="btn-primary" onclick="testAiConn()" id="btnTestAi">Probar conexión</button>
|
||||
<span id="aiTestResult" style="font-size:13px"></span>
|
||||
</div>
|
||||
<small style="margin-top:8px;color:#888">Guarda primero la configuración, luego prueba la conexión. Se enviará un mensaje de prueba al proveedor activo.</small>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="version-info">Los cambios se aplican inmediatamente. Los valores se almacenan en la base de datos.</div>
|
||||
</div>
|
||||
<script>
|
||||
function testAiConn() {
|
||||
var btn = document.getElementById('btnTestAi');
|
||||
var res = document.getElementById('aiTestResult');
|
||||
btn.disabled = true;
|
||||
res.textContent = 'Probando...';
|
||||
res.style.color = '#666';
|
||||
fetch('/admin/settings/test-ai', {method:'POST', headers:{'Content-Type':'application/x-www-form-urlencoded'}, body:''})
|
||||
.then(function(r){return r.json();})
|
||||
.then(function(d){
|
||||
if (d.ok) {
|
||||
res.textContent = 'Conexion exitosa (' + d.provider + '): ' + d.response;
|
||||
res.style.color = '#16a34a';
|
||||
} else {
|
||||
res.textContent = 'Error (' + d.provider + '): ' + d.error;
|
||||
res.style.color = '#dc2626';
|
||||
}
|
||||
})
|
||||
.catch(function(e){ res.textContent = 'Error de red'; res.style.color = '#dc2626'; })
|
||||
.finally(function(){ btn.disabled = false; });
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
HTML;
|
||||
|
||||
Reference in New Issue
Block a user