feat: browser UI — tüit CI dark theme, XSS-safe DOM, auth-aware

This commit is contained in:
2026-04-01 02:29:07 +02:00
parent 319db8c788
commit b62c3d6604
2 changed files with 292 additions and 0 deletions
+122
View File
@@ -0,0 +1,122 @@
const btn = document.getElementById('record-btn');
const statusText = document.getElementById('status-text');
const headerStatus = document.getElementById('header-status');
const preview = document.getElementById('preview');
const instructionsEl = document.getElementById('instructions');
const transcriptList = document.getElementById('transcript-list');
const userChip = document.getElementById('user-chip');
const logoutBtn = document.getElementById('logout-btn');
const STATUS_LABELS = {
idle: 'Bereit',
recording: 'Aufnahme läuft\u2026',
processing: 'Wird verarbeitet\u2026',
error: 'Fehler',
};
// Auth token is stored in sessionStorage so it's gone when the tab closes.
// On first load, if no token is present the server will redirect to /login.
const token = sessionStorage.getItem('token');
function authHeaders() {
return token ? { 'Authorization': `Bearer ${token}` } : {};
}
function apiFetch(url, options = {}) {
return fetch(url, {
...options,
headers: { 'Content-Type': 'application/json', ...authHeaders(), ...(options.headers || {}) },
});
}
logoutBtn.addEventListener('click', () => {
apiFetch('/logout', { method: 'POST' }).finally(() => {
sessionStorage.removeItem('token');
location.href = '/login';
});
});
instructionsEl.addEventListener('input', async () => {
await apiFetch('/instructions', {
method: 'POST',
body: JSON.stringify({ instructions: instructionsEl.value }),
});
});
function setStatus(status) {
btn.className = status;
headerStatus.className = `status-badge ${status}`;
const label = STATUS_LABELS[status] || status;
statusText.textContent = label;
headerStatus.textContent = label;
btn.disabled = status === 'processing';
}
btn.addEventListener('click', () => apiFetch('/toggle', { method: 'POST' }));
function connectWs() {
const proto = location.protocol === 'https:' ? 'wss:' : 'ws:';
const ws = new WebSocket(`${proto}//${location.host}/ws?token=${encodeURIComponent(token || '')}`);
ws.onmessage = (e) => {
const msg = JSON.parse(e.data);
if (msg.event === 'processing') setStatus('processing');
if (msg.event === 'transcribed' || msg.event === 'refined') {
const text = msg.raw || msg.markdown || '';
preview.textContent = text;
preview.classList.add('has-content');
}
if (msg.event === 'saved') {
setStatus('idle');
loadTranscripts();
}
if (msg.event === 'error') {
setStatus('idle');
preview.textContent = `Fehler: ${msg.message}`;
}
};
ws.onclose = () => setTimeout(connectWs, 2000);
}
async function loadTranscripts() {
const r = await apiFetch('/transcripts');
if (!r.ok) return;
const items = await r.json();
transcriptList.replaceChildren(
...items.map((t) => {
const div = document.createElement('div');
div.className = 'transcript-item';
const name = document.createElement('span');
name.textContent = t.filename.replace('.md', '');
const meta = document.createElement('span');
meta.className = 'meta';
meta.textContent = `${Math.round(t.size / 1024 * 10) / 10} KB`;
div.append(name, meta);
div.addEventListener('click', () => {
apiFetch('/open', {
method: 'POST',
body: JSON.stringify({ path: t.path }),
});
});
return div;
})
);
}
(async () => {
const r = await apiFetch('/status');
if (r.status === 401) {
location.href = '/login';
return;
}
const data = await r.json();
setStatus(data.status);
if (data.username) {
userChip.textContent = data.username;
}
connectWs();
loadTranscripts();
})();
+170
View File
@@ -0,0 +1,170 @@
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>tüit Transkriptor</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link href="https://fonts.googleapis.com/css2?family=Overpass:wght@300;400;600;700&display=swap" rel="stylesheet">
<style>
:root {
--red: #DA251C;
--yellow: #FFD802;
--bg: #111;
--surface: #1a1a1a;
--surface2: #232323;
--text: #e8e8e8;
--muted: #888;
--border: #2e2e2e;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
font-family: 'Overpass', system-ui, sans-serif;
background: var(--bg);
color: var(--text);
min-height: 100vh;
display: flex;
flex-direction: column;
}
header {
display: flex;
align-items: center;
gap: 12px;
padding: 16px 24px;
border-bottom: 1px solid var(--border);
}
.logo-dot { width: 12px; height: 12px; background: var(--red); border-radius: 50%; }
header h1 { font-size: 1.1rem; font-weight: 600; letter-spacing: 0.04em; }
header h1 span { color: var(--red); }
.header-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.status-badge {
font-size: 0.75rem;
padding: 4px 10px;
border-radius: 20px;
background: var(--surface2);
color: var(--muted);
text-transform: uppercase;
letter-spacing: 0.08em;
}
.status-badge.recording { background: var(--red); color: #fff; }
.status-badge.processing { background: var(--yellow); color: #111; }
.user-chip {
font-size: 0.75rem;
padding: 4px 10px;
border-radius: 20px;
background: var(--surface2);
color: var(--muted);
letter-spacing: 0.04em;
}
.logout-btn {
font-size: 0.75rem;
padding: 4px 10px;
border-radius: 20px;
background: none;
border: 1px solid var(--border);
color: var(--muted);
cursor: pointer;
font-family: inherit;
transition: border-color 0.15s, color 0.15s;
}
.logout-btn:hover { border-color: var(--red); color: var(--red); }
main {
flex: 1;
display: flex;
flex-direction: column;
gap: 20px;
padding: 24px;
max-width: 800px;
width: 100%;
margin: 0 auto;
}
.record-section { display: flex; flex-direction: column; align-items: center; gap: 16px; }
#record-btn {
width: 96px; height: 96px; border-radius: 50%;
background: var(--surface2); border: 3px solid var(--border);
cursor: pointer; transition: all 0.15s ease;
display: flex; align-items: center; justify-content: center;
outline: none;
}
#record-btn:hover { border-color: var(--red); }
#record-btn.recording { background: var(--red); border-color: var(--red); animation: pulse 1.4s infinite; }
#record-btn.processing { background: var(--yellow); border-color: var(--yellow); cursor: default; }
@keyframes pulse {
0%,100% { box-shadow: 0 0 0 0 rgba(218,37,28,0.4); }
50% { box-shadow: 0 0 0 16px rgba(218,37,28,0); }
}
.mic-icon { width: 36px; height: 36px; fill: var(--text); }
#record-btn.recording .mic-icon { fill: #fff; }
#record-btn.processing .mic-icon { fill: #111; }
#status-text { font-size: 0.85rem; color: var(--muted); }
.instructions-section { display: flex; flex-direction: column; gap: 8px; }
label { font-size: 0.8rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
textarea {
background: var(--surface); border: 1px solid var(--border);
color: var(--text); border-radius: 8px; padding: 12px;
font-family: inherit; font-size: 0.9rem; resize: vertical;
min-height: 80px; outline: none; transition: border-color 0.15s;
}
textarea:focus { border-color: var(--yellow); }
textarea::placeholder { color: var(--muted); }
.preview-section { display: flex; flex-direction: column; gap: 8px; }
#preview {
background: var(--surface); border: 1px solid var(--border);
border-radius: 8px; padding: 16px;
font-size: 0.85rem; line-height: 1.6; color: var(--muted);
min-height: 60px; white-space: pre-wrap; word-break: break-word;
}
#preview.has-content { color: var(--text); }
.transcripts-section { display: flex; flex-direction: column; gap: 8px; }
#transcript-list { display: flex; flex-direction: column; gap: 6px; }
.transcript-item {
background: var(--surface); border: 1px solid var(--border);
border-radius: 6px; padding: 10px 14px;
display: flex; align-items: center; justify-content: space-between;
font-size: 0.82rem; cursor: pointer; transition: border-color 0.1s;
}
.transcript-item:hover { border-color: var(--red); }
.transcript-item .meta { color: var(--muted); font-size: 0.75rem; }
</style>
</head>
<body>
<header>
<div class="logo-dot"></div>
<h1>tüit <span>Transkriptor</span></h1>
<div class="header-right">
<span class="status-badge" id="header-status">Bereit</span>
<span class="user-chip" id="user-chip"></span>
<button class="logout-btn" id="logout-btn">Abmelden</button>
</div>
</header>
<main>
<section class="record-section">
<button id="record-btn" title="Aufnahme starten / stoppen">
<svg class="mic-icon" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
<path d="M12 1a4 4 0 0 1 4 4v6a4 4 0 0 1-8 0V5a4 4 0 0 1 4-4zm0 2a2 2 0 0 0-2 2v6a2 2 0 0 0 4 0V5a2 2 0 0 0-2-2zM6.5 10.5A5.5 5.5 0 0 0 12 16a5.5 5.5 0 0 0 5.5-5.5h2A7.5 7.5 0 0 1 13 17.93V21h2v2H9v-2h2v-3.07A7.5 7.5 0 0 1 4.5 10.5h2z"/>
</svg>
</button>
<span id="status-text">Klicken zum Starten</span>
</section>
<section class="instructions-section">
<label for="instructions">Instruktionen für den Sekretär</label>
<textarea
id="instructions"
placeholder="z.B. &quot;Heb die wichtigsten Punkte hervor&quot; · &quot;Erstelle ein Ticket&quot; · &quot;Mach ein Angebot daraus&quot;"
></textarea>
</section>
<section class="preview-section">
<label>Vorschau</label>
<div id="preview">Noch keine Aufnahme verarbeitet.</div>
</section>
<section class="transcripts-section">
<label>Meine Transkripte</label>
<div id="transcript-list"></div>
</section>
</main>
<script src="/app.js"></script>
</body>
</html>