heystreamer/views/dashboard.ejs
Bashy c481ca92cb Stats per stream and period, public stats page, dashboard settings, Card alert style
Statistics
- Per day and per stream statistics (src/periodstats.js, one generic stat_day table), backfilled
  once from the older tables; Stream / Week / Month / Year / All time views, Community and Streams tabs.
- Viewer count every 5 minutes and title / category history per stream (EventSub channel.update):
  viewer graph, games played (donut), games in the streams list.
- Twitch sync (src/twitchsync.js): followers with follow dates, current subs, mods, VIPs, all-time
  bits, channel emotes, past streams from VODs. Twitch analytics CSV import (src/twitchcsv.js).
- Public stats page on its own host (Settings -> Stats and data): no message text, no bots,
  !hideme / !showme opt-out. Viewer page: roles, follow age, sub status, bits, a menu for rarely used actions.
- StreamElements watch-time importer removed (already imported minutes stay as a baseline).

Dashboard
- Settings and Actions with a left sidebar; each settings page saves only its own fields.
  Connections (Twitch, StreamElements token now set here, HUDFX), OBS links (hidden behind an eye
  toggle) with a link builder, Chat (sound picked from the media library), TTS, Stats and data,
  Backup (export / import the whole setup), Advanced. Time zone setting for the stats pages.
- Actions -> Alerts: alert style, pictures, sounds, bits tiers and card colours, stored in the
  database (src/theme.js); an old file-based theme is imported once. Alert preview page
  (/actions/alerts/preview, tools/preview/export.js for a static copy).
- Old /actions page removed; Actions = Redeems / Alerts / TTS voices / Media.

Alerts
- New plain Card style for everyone (public/alerts/card.js); Polaroid, Cassette and the TTS letter
  stay as optional looks. Redeem variations can be Card, Cassette, Sound only or Video.

Repo
- No channel data in git: the channel's art, stickers and sounds stay on disk (gitignored) and are
  picked in the dashboard; examples for the server config (apache.example.sh, .env.example).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 11:22:49 +02:00

126 lines
6.9 KiB
Text

<h2>Dashboard</h2>
<div class="dash-status">
<a href="/settings/connections" title="Settings → Connections">
Twitch <% if (eventsubStatus.connected) { %><span class="badge badge-green">connected</span><% } else if (eventsubStatus.running) { %><span class="badge badge-grey">connecting…</span><% } else { %><span class="badge badge-red">not running</span><% } %>
</a>
<a href="/settings/connections" title="Settings → Connections">
StreamElements <% if (!seStatus.enabled) { %><span class="badge badge-grey">off</span><% } else if (seStatus.subscribed) { %><span class="badge badge-green">connected</span><% } else { %><span class="badge badge-grey">connecting…</span><% } %>
</a>
<a href="/settings/obs" title="Browser source links for OBS">OBS links →</a>
<% if (eventsubStatus.failed.length) { %><a href="/settings/connections" style="color:#f88">Some Twitch permissions are missing: log in again</a><% } %>
</div>
<style>
.dash-status { display:flex; gap:1.4rem; flex-wrap:wrap; align-items:center; margin:0 0 1.4rem; padding:.6rem .9rem;
border:1px solid var(--pico-muted-border-color); border-radius:12px; }
.dash-status a { text-decoration:none; font-size:.92rem; }
</style>
<div style="display:flex; gap:.8rem; align-items:center; margin-bottom:1.5rem;">
<button type="button" id="skip-alert" class="outline" style="width:auto; margin:0;"
title="Stops the alert that is on screen right now (sound and TTS voice too). Queued alerts carry on.">⏭ Skip current alert</button>
<small id="skip-status"></small>
</div>
<script>
document.getElementById('skip-alert').addEventListener('click', async () => {
const st = document.getElementById('skip-status');
try { const r = await fetch('/alerts/skip', { method: 'POST' }); st.textContent = r.ok ? 'Skipped' : `Failed (${r.status})`; }
catch (e) { st.textContent = 'Failed: ' + e.message; }
setTimeout(() => { st.textContent = ''; }, 3000);
});
</script>
<h3>Raid</h3>
<p><small>Start the raid here and the send-off card stays on stream (silent) until the raid happens. Same as Twitch's Raid button.</small></p>
<div style="display:flex; gap:.5rem; align-items:center; flex-wrap:wrap; margin-bottom:.4rem;">
<input id="raid-target" placeholder="channel name" style="width:16rem; margin:0;">
<button type="button" id="raid-start" style="width:auto; margin:0;">Start raid</button>
<button type="button" id="raid-cancel" class="outline" style="width:auto; margin:0;">Cancel raid</button>
<small id="raid-status"></small>
</div>
<script>
(() => {
const out = document.getElementById('raid-status');
const call = async (url, body) => {
try {
const r = await fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body || {}) });
const j = await r.json().catch(() => ({}));
out.textContent = j.ok ? (j.target ? `Raiding ${j.target}${j.viewers != null ? ' with ' + j.viewers : ''}…` : 'Raid cancelled') : `Failed: ${j.error || r.status}`;
} catch (e) { out.textContent = 'Failed: ' + e.message; }
};
document.getElementById('raid-start').addEventListener('click', () => call('/alerts/raid/start', { target: document.getElementById('raid-target').value }));
document.getElementById('raid-cancel').addEventListener('click', () => call('/alerts/raid/cancel'));
})();
</script>
<h3>Test alerts</h3>
<p><small>Sends a sample alert to the overlay (OBS). Not logged, no actions fired. Looks and sounds: <a href="/actions/alerts">Actions → Alerts</a>.</small></p>
<div id="test-alerts" style="display:flex; flex-wrap:wrap; gap:.4rem; margin-bottom:.5rem;">
<% for (const key of testKeys) { %>
<button type="button" class="outline" data-key="<%= key %>" style="width:auto; padding:.3rem .8rem; margin:0;"><%= key %></button>
<% } %>
</div>
<p><small id="test-status"></small></p>
<script>
document.querySelectorAll('#test-alerts button').forEach(b => b.addEventListener('click', async () => {
const out = document.getElementById('test-status');
try {
const r = await fetch('/alerts/test/' + encodeURIComponent(b.dataset.key), { method: 'POST' });
out.textContent = r.ok ? `Sent: ${b.dataset.key}` : `Failed (${r.status})`;
} catch (e) { out.textContent = 'Failed: ' + e.message; }
}));
</script>
<div style="display:flex; align-items:center; gap:1rem; flex-wrap:wrap;">
<h3 style="margin:0;">Recent activity</h3>
<button type="button" id="activity-reload" class="outline" style="width:auto; padding:.3rem .8rem; margin:0;">Reload</button>
<label style="margin:0;"><input type="checkbox" id="activity-auto"> auto-refresh (15 s)</label>
<small id="activity-updated"></small>
</div>
<div id="activity"><%- include('_activity') %></div>
<script>
(() => {
const box = document.getElementById('activity');
const stamp = document.getElementById('activity-updated');
const auto = document.getElementById('activity-auto');
let timer = null;
// times are stored in UTC: show them in this browser's time zone
function localTimes() {
box.querySelectorAll('time[datetime]').forEach(t => {
const d = new Date(t.getAttribute('datetime'));
if (!isNaN(d)) { t.title = t.textContent; t.textContent = d.toLocaleString([], { month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit', second: '2-digit' }); }
});
}
// Replay buttons (the table is re-rendered on reload, so listen on the box)
box.addEventListener('click', async ev => {
const b = ev.target.closest('.activity-replay'); if (!b) return;
const st = b.parentElement.querySelector('.activity-replay-status');
b.disabled = true; st.textContent = '…';
try {
const r = await fetch('/activity/' + encodeURIComponent(b.dataset.id) + '/replay', { method: 'POST' });
const j = await r.json().catch(() => ({}));
st.textContent = j.ok ? 'sent' : (j.error || `failed (${r.status})`);
} catch (e) { st.textContent = 'failed: ' + e.message; }
b.disabled = false;
});
localTimes();
async function reload() {
try {
const r = await fetch('/activity', { headers: { 'Accept': 'text/html' } });
if (r.redirected || !r.ok) { stamp.textContent = 'Reload failed (logged out?)'; return; }
box.innerHTML = await r.text();
localTimes();
stamp.textContent = 'Updated ' + new Date().toLocaleTimeString();
} catch (e) { stamp.textContent = 'Reload failed: ' + e.message; }
}
function setAuto(on) {
clearInterval(timer);
if (on) timer = setInterval(reload, 15000);
try { localStorage.setItem('activityAuto', on ? '1' : '0'); } catch {}
}
document.getElementById('activity-reload').addEventListener('click', reload);
auto.addEventListener('change', () => setAuto(auto.checked));
try { auto.checked = localStorage.getItem('activityAuto') === '1'; } catch {}
setAuto(auto.checked);
})();
</script>