Таблица graph_history с ежедневными снимками (карточки, связи, персоны). GET /snapshot делает снимок, GET /history отдаёт ряд и прирост. Cron 23:30. Панель показывает рост за период, бот в команде «граф» — тоже. Проверено на имитированном недельном снимке: было 250/380, стало 310/455, прирост 60 карточек и 75 связей. В /ask.html добавлено автодополнение через GET /suggest.
108 lines
4.4 KiB
HTML
108 lines
4.4 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="ru">
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||
<title>Агент по медиатеке</title>
|
||
<style>
|
||
:root { --bg:#0d1117; --fg:#c9d1d9; --dim:#8b949e; --line:#30363d; --acc:#58a6ff; }
|
||
* { box-sizing: border-box; }
|
||
body { margin:0; background:var(--bg); color:var(--fg);
|
||
font:15px/1.6 -apple-system,"Segoe UI",Roboto,sans-serif; }
|
||
.wrap { max-width:820px; margin:0 auto; padding:32px 20px 80px; }
|
||
h1 { font-size:20px; margin:0 0 6px; }
|
||
.sub { color:var(--dim); font-size:13px; margin-bottom:24px; }
|
||
form { display:flex; gap:10px; }
|
||
input[type=text] { flex:1; background:#161b22; border:1px solid var(--line);
|
||
color:var(--fg); border-radius:8px; padding:12px 14px; font-size:15px; outline:none; }
|
||
input[type=text]:focus { border-color:var(--acc); }
|
||
button { background:var(--acc); color:#0d1117; border:0; border-radius:8px;
|
||
padding:12px 20px; font-size:15px; font-weight:600; cursor:pointer; }
|
||
button:disabled { opacity:.5; cursor:default; }
|
||
.chips { display:flex; flex-wrap:wrap; gap:8px; margin:14px 0 26px; }
|
||
.chip { background:#161b22; border:1px solid var(--line); color:var(--dim);
|
||
border-radius:999px; padding:6px 12px; font-size:13px; cursor:pointer; }
|
||
.chip:hover { border-color:var(--acc); color:var(--fg); }
|
||
#out { margin-top:8px; }
|
||
.card { background:#161b22; border:1px solid var(--line); border-radius:10px;
|
||
padding:16px 18px; margin-bottom:14px; }
|
||
.plan { color:var(--dim); font-size:12px; margin-top:10px;
|
||
border-top:1px dashed var(--line); padding-top:10px; }
|
||
pre { margin:0; white-space:pre-wrap; font-family:inherit; }
|
||
</style>
|
||
</head>
|
||
<body>
|
||
<div class="wrap">
|
||
<h1>Агент по медиатеке</h1>
|
||
<div class="sub">Понимает вопрос словами и отвечает по графу контента</div>
|
||
<form id="f">
|
||
<input id="q" type="text" list="hints" placeholder="например: фильмы Нолана про космос с высоким рейтингом" autofocus>
|
||
<datalist id="hints"></datalist>
|
||
<button id="b">Спросить</button>
|
||
</form>
|
||
<div class="chips" id="chips"></div>
|
||
<div id="out"></div>
|
||
</div>
|
||
<script>
|
||
const EXAMPLES = [
|
||
"фильмы Нолана",
|
||
"когда были фильмы про искусственный интеллект",
|
||
"похоже на Дюну",
|
||
"высокорейтинговые фильмы 80-х",
|
||
"фильмография Keanu Reeves",
|
||
"настроение эпичное",
|
||
"что экранизировали у Frank Herbert"
|
||
];
|
||
|
||
const chips = document.getElementById("chips");
|
||
EXAMPLES.forEach(t => {
|
||
const el = document.createElement("span");
|
||
el.className = "chip"; el.textContent = t;
|
||
el.onclick = () => { document.getElementById("q").value = t; ask(); };
|
||
chips.appendChild(el);
|
||
});
|
||
|
||
const out = document.getElementById("out");
|
||
const btn = document.getElementById("b");
|
||
document.getElementById("f").addEventListener("submit", e => { e.preventDefault(); ask(); });
|
||
|
||
let hintTimer = null;
|
||
document.getElementById("q").addEventListener("input", e => {
|
||
const v = e.target.value.trim();
|
||
clearTimeout(hintTimer);
|
||
if (v.length < 2) return;
|
||
hintTimer = setTimeout(async () => {
|
||
try {
|
||
const r = await fetch("suggest?q=" + encodeURIComponent(v));
|
||
const d = await r.json();
|
||
const dl = document.getElementById("hints");
|
||
dl.innerHTML = (d.items || []).map(i =>
|
||
"<option value='" + String(i.title).replace(/'/g, "’") + "'>").join("");
|
||
} catch (err) {}
|
||
}, 250);
|
||
});
|
||
|
||
async function ask(){
|
||
const q = document.getElementById("q").value.trim();
|
||
if (!q) return;
|
||
btn.disabled = true;
|
||
out.innerHTML = '<div class="card" style="color:#8b949e">думаю…</div>';
|
||
try {
|
||
const r = await fetch("ask?q=" + encodeURIComponent(q));
|
||
const d = await r.json();
|
||
if (d.error) throw new Error(d.error);
|
||
out.innerHTML = '<div class="card"><pre>' + escapeHtml(d.answer || "") +
|
||
'</pre><div class="plan">понял так: ' + escapeHtml(d.plan || "") + '</div></div>';
|
||
} catch (e) {
|
||
out.innerHTML = '<div class="card" style="color:#f85149">Ошибка: ' + escapeHtml(String(e)) + '</div>';
|
||
} finally { btn.disabled = false; }
|
||
}
|
||
|
||
function escapeHtml(s){
|
||
return String(s).replace(/[&<>]/g, c => ({"&":"&","<":"<",">":">"}[c]))
|
||
.replace(/\*\*(.+?)\*\*/g, '<b>$1</b>');
|
||
}
|
||
</script>
|
||
</body>
|
||
</html>
|