send2streamer/public/dashboard.html
vrubelroman b669c2d0b7
All checks were successful
CI/CD Pipeline / build-and-deploy (push) Successful in 30s
Add streamer dashboard stats; fix TTS overlap race properly
Dashboard now shows unique visitors (via sender link), total messages,
and unique senders per streamer, tracked via new viewer_visits/messages
tables.

The previous overlay TTS-overlap fix had a race: audio not having
arrived yet was treated the same as "no audio at all", letting the
queue advance before slow-to-synthesize audio (e.g. a long question)
ever started playing. Now "not arrived yet" is explicitly distinct
from "finished playing", with a grace-period fallback for genuine TTS
failures.

Also drop the hardcoded AI name from ai-prompt.txt since it's now
injected dynamically from the streamer's configured ai_name.
2026-07-08 18:04:02 +00:00

218 lines
5.8 KiB
HTML

<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8" />
<title>Ваши ссылки — Send2Streamer</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style>
body {
font-family: system-ui, sans-serif;
max-width: 640px;
margin: 60px auto;
padding: 0 20px;
line-height: 1.5;
}
h1 { font-size: 28px; }
.card {
background: #f6f6f6;
border-radius: 12px;
padding: 20px 24px;
margin-bottom: 20px;
}
.card h2 {
font-size: 16px;
margin: 0 0 4px;
}
.card p {
color: #666;
font-size: 14px;
margin: 0 0 12px;
}
.url-row {
display: flex;
gap: 8px;
}
.url-row input {
flex: 1;
padding: 8px 10px;
font-size: 14px;
border: 1px solid #ccc;
border-radius: 6px;
background: #fff;
}
.url-row button {
padding: 8px 16px;
cursor: pointer;
}
#logout {
color: #888;
cursor: pointer;
font-size: 14px;
}
.settings-row {
display: flex;
align-items: center;
gap: 8px;
}
.settings-row input {
width: 80px;
padding: 8px 10px;
font-size: 14px;
border: 1px solid #ccc;
border-radius: 6px;
}
.settings-row input#ai-name {
width: 220px;
}
.settings-row button {
padding: 8px 16px;
cursor: pointer;
}
#settings-status {
font-size: 13px;
color: #888;
margin-top: 8px;
min-height: 16px;
}
.stats-row {
display: flex;
gap: 24px;
}
.stat {
flex: 1;
}
.stat .value {
font-size: 24px;
font-weight: 600;
}
.stat .label {
font-size: 13px;
color: #666;
}
</style>
</head>
<body>
<h1>Ваши ссылки</h1>
<div class="card">
<h2>Статистика</h2>
<div class="stats-row">
<div class="stat">
<div class="value" id="stat-visitors"></div>
<div class="label">заходили по ссылке</div>
</div>
<div class="stat">
<div class="value" id="stat-messages"></div>
<div class="label">сообщений отправлено</div>
</div>
<div class="stat">
<div class="value" id="stat-unique-senders"></div>
<div class="label">уникальных отправителей</div>
</div>
</div>
</div>
<div class="card">
<h2>Ссылка для OBS / StreamLabs</h2>
<p>Вставьте в свойства Browser Source (URL).</p>
<div class="url-row">
<input id="overlay-url" readonly />
<button data-copy="overlay-url">Копировать</button>
</div>
</div>
<div class="card">
<h2>Ссылка для зрителей</h2>
<p>Опубликуйте её — зрители авторизуются через Google и смогут слать вам сообщения на стрим.</p>
<div class="url-row">
<input id="sender-url" readonly />
<button data-copy="sender-url">Копировать</button>
</div>
</div>
<div class="card">
<h2>Длительность показа сообщения</h2>
<p>Сколько секунд сообщение зрителя остаётся на экране.</p>
<div class="settings-row">
<input id="display-duration" type="number" min="1" max="120" />
<span>сек.</span>
</div>
</div>
<div class="card">
<h2>Имя ИИ-помощника</h2>
<p>Как зовут вашего ИИ-помощника, который отвечает зрителям (по умолчанию «Альтушка Ирина»).</p>
<div class="settings-row">
<input id="ai-name" type="text" maxlength="60" />
</div>
</div>
<div class="settings-row">
<button id="save-settings">Сохранить</button>
</div>
<div id="settings-status"></div>
<p id="logout">выйти</p>
<script>
async function init() {
const meRes = await fetch('/me');
const { user } = await meRes.json();
if (!user) {
window.location.href = '/';
return;
}
const res = await fetch('/api/dashboard');
if (!res.ok) {
window.location.href = '/';
return;
}
const data = await res.json();
document.getElementById('overlay-url').value = data.overlayUrl;
document.getElementById('sender-url').value = data.senderUrl;
document.getElementById('display-duration').value = data.displayDurationSeconds;
document.getElementById('ai-name').value = data.aiName;
document.getElementById('stat-visitors').textContent = data.stats.visitors;
document.getElementById('stat-messages').textContent = data.stats.messages;
document.getElementById('stat-unique-senders').textContent = data.stats.uniqueSenders;
}
document.getElementById('save-settings').addEventListener('click', async () => {
const statusEl = document.getElementById('settings-status');
const seconds = Number(document.getElementById('display-duration').value);
const aiName = document.getElementById('ai-name').value;
const res = await fetch('/api/settings', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ displayDurationSeconds: seconds, aiName }),
});
if (res.ok) {
statusEl.textContent = 'Сохранено';
} else {
const { error } = await res.json();
statusEl.textContent = 'Ошибка: ' + error;
}
setTimeout(() => { statusEl.textContent = ''; }, 2000);
});
document.querySelectorAll('[data-copy]').forEach((btn) => {
btn.addEventListener('click', () => {
const input = document.getElementById(btn.dataset.copy);
input.select();
navigator.clipboard.writeText(input.value);
btn.textContent = 'Скопировано';
setTimeout(() => { btn.textContent = 'Копировать'; }, 1500);
});
});
document.getElementById('logout').addEventListener('click', async () => {
await fetch('/auth/logout', { method: 'POST' });
window.location.href = '/';
});
init();
</script>
</body>
</html>