Fix: Robust web password handling for insight images

This commit is contained in:
Marcos
2026-03-22 12:58:11 -03:00
parent 029b8973b3
commit 3cfb6fb3d2

View File

@@ -1041,14 +1041,17 @@
const panel = document.getElementById('insights-panel');
if (!panel) return;
// Garante que temos a senha (tenta pegar do global ou do localStorage se precisar)
const activePwd = webPassword || localStorage.getItem('vps_web_password') || '';
// Transforma caminhos da VPS (![alt](/host_root/...) em links da nossa API segura
// Ex: /host_root/root/img.jpg -> /api/host_file?pwd=...&path=/host_root/root/img.jpg
let mdWithAuth = markdown.replace(/!\[(.*?)\]\((\/host_root\/.*?)\)/g, (match, alt, path) => {
return `![${alt}](/api/host_file?pwd=${encodeURIComponent(webPassword)}&path=${encodeURIComponent(path)})`;
return `![${alt}](/api/host_file?pwd=${encodeURIComponent(activePwd)}&path=${encodeURIComponent(path)})`;
});
// Fallback para qualquer outro caso que tenha sobrado do prefixo antigo
mdWithAuth = mdWithAuth.replace(/\/api\/host_file\?path=/g, '/api/host_file?pwd=' + encodeURIComponent(webPassword) + '&path=');
mdWithAuth = mdWithAuth.replace(/\/api\/host_file\?path=/g, '/api/host_file?pwd=' + encodeURIComponent(activePwd) + '&path=');
// Renderiza o Markdown para HTML usando marked.js
panel.innerHTML = `<div class="animate-fade-in">${marked.parse(mdWithAuth)}</div>`;