mirror of
https://github.com/R0m1k3/Loki.git
synced 2026-10-22 14:38:12 +02:00
web: endpoint OpenAI = adresse LAN detectee cote serveur (jamais le domaine du relais dans le tunnel)
This commit is contained in:
1 parent
9a93702313
commit
b818e253c2
2 files changed
+22
-2
No files matched your search
+5
-2
@@ -757,8 +757,11 @@ function copyApiKey(){ copyText(OAI_KEY, OAI_KEY?'clé copiée':'aucune clé');
|
|||||||
function renderApiKey(d){
|
function renderApiKey(d){
|
||||||
OAI_KEY = d.key || '';
|
OAI_KEY = d.key || '';
|
||||||
// URL de l'endpoint : llama-server tourne sur d.port (≠ port de l'UI web).
|
// URL de l'endpoint : llama-server tourne sur d.port (≠ port de l'UI web).
|
||||||
const proto = location.protocol==='https:' ? 'https:' : 'http:';
|
// On prend l'hôte annoncé par le serveur (IP LAN détectée côté Go) : dans le
|
||||||
document.getElementById('oai-url').value = proto+'//'+location.hostname+':'+d.port+'/v1';
|
// tunnel ajean.link, location.hostname serait le domaine du relais (faux) —
|
||||||
|
// l'accès OpenAI reste TOUJOURS l'adresse locale de la machine.
|
||||||
|
const host = d.host || location.hostname;
|
||||||
|
document.getElementById('oai-url').value = 'http://'+host+':'+d.port+'/v1';
|
||||||
const inp=document.getElementById('oai-key');
|
const inp=document.getElementById('oai-key');
|
||||||
if(!d.set){ inp.value='(aucune clé — serveur ouvert)'; inp.style.opacity=.6; }
|
if(!d.set){ inp.value='(aucune clé — serveur ouvert)'; inp.style.opacity=.6; }
|
||||||
else { inp.style.opacity=1; inp.value = OAI_REVEAL ? OAI_KEY : d.masked; }
|
else { inp.style.opacity=1; inp.value = OAI_REVEAL ? OAI_KEY : d.masked; }
|
||||||
|
|||||||
@@ -547,9 +547,26 @@ func handleAPIKey(w http.ResponseWriter, r *http.Request) {
|
|||||||
"key": k,
|
"key": k,
|
||||||
"masked": maskAPIKey(k),
|
"masked": maskAPIKey(k),
|
||||||
"port": LLMPort(),
|
"port": LLMPort(),
|
||||||
|
"host": localIP(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// localIP best-effort renvoie l'IPv4 LAN primaire de la machine (l'IP source du
|
||||||
|
// trafic sortant), ou "localhost" à défaut. Sert à annoncer l'endpoint OpenAI
|
||||||
|
// avec une adresse correcte sur le réseau local MÊME quand l'UI est atteinte via
|
||||||
|
// le tunnel ajean.link (où location.hostname serait le domaine du relais, faux).
|
||||||
|
func localIP() string {
|
||||||
|
conn, err := net.Dial("udp", "8.8.8.8:80")
|
||||||
|
if err != nil {
|
||||||
|
return "localhost"
|
||||||
|
}
|
||||||
|
defer conn.Close()
|
||||||
|
if a, ok := conn.LocalAddr().(*net.UDPAddr); ok && a.IP != nil {
|
||||||
|
return a.IP.String()
|
||||||
|
}
|
||||||
|
return "localhost"
|
||||||
|
}
|
||||||
|
|
||||||
func handleInternet(w http.ResponseWriter, r *http.Request) {
|
func handleInternet(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.Method == http.MethodPost {
|
if r.Method == http.MethodPost {
|
||||||
var req struct {
|
var req struct {
|
||||||
|
|||||||
Reference in new issue
Block a user