T-011: Login-Flow in der App (AudibleClient-Trait, Auth- Erkennung über ~/.audible, Terminal-Login, Minimale Bibliothek; spec-Abweichung: kein Kopieren nach ~/.config, app nutzt audible-cli-pfad)

This commit is contained in:
2026-11-06 19:25:00 +01:00
parent cf7378d0f4
commit d7e7d554a8
11 changed files with 540 additions and 370 deletions

View File

@ -1,89 +1,126 @@
<script>
import svelteLogo from './assets/svelte.svg'
import viteLogo from './assets/vite.svg'
import heroImg from './assets/hero.png'
import Counter from './lib/Counter.svelte'
<script lang="ts">
import { authStatus, startLogin, getLibrary, type Book } from './lib/audible'
type View = 'loading' | 'login' | 'library'
let view = $state<View>('loading')
let error = $state('')
let info = $state('')
let books = $state<Book[]>([])
let starting = $state(false)
let checking = $state(false)
let pollTimer = $state<ReturnType<typeof setInterval> | null>(null)
function clearPoll() {
if (pollTimer !== null) {
clearInterval(pollTimer)
pollTimer = null
}
}
async function loadLibrary(): Promise<void> {
checking = true
error = ''
try {
books = await getLibrary()
view = 'library'
} catch (e) {
error = String(e)
} finally {
checking = false
}
}
async function checkAuth(): Promise<void> {
checking = true
error = ''
try {
const s = await authStatus()
if (s.logged_in) {
clearPoll()
await loadLibrary()
} else if (view === 'library') {
view = 'login'
}
} catch (e) {
error = String(e)
} finally {
checking = false
}
}
async function doLogin(): Promise<void> {
starting = true
error = ''
info = ''
try {
await startLogin()
info = 'Anmeldung läuft im Terminal. Danach hier „Jetzt prüfen“ oder kurz warten.'
clearPoll()
pollTimer = setInterval(checkAuth, 3000)
} catch (e) {
error = String(e)
} finally {
starting = false
}
}
// Beim Start prüfen: angemeldet → Bibliothek; sonst Login-Screen.
$effect(() => {
checkAuth()
return clearPoll
})
</script>
<section id="center">
<div class="hero">
<img src={heroImg} class="base" width="170" height="179" alt="" />
<img src={svelteLogo} class="framework" alt="Svelte logo" />
<img src={viteLogo} class="vite" alt="Vite logo" />
</div>
<div>
<h1>Get started</h1>
<p>Edit <code>src/App.svelte</code> and save to test <code>HMR</code></p>
</div>
<Counter />
</section>
{#if view === 'loading'}
<main class="center">
<h1>Hörwerk</h1>
<p class="muted">Prüfe Anmeldung…</p>
</main>
{:else if view === 'login'}
<main class="center">
<h1>Hörwerk</h1>
<p class="muted">
Melden dich mit deinem Audible-Konto an. Die Anmeldung läuft über
<code>audible-cli</code> im Terminal. Nur dein eigenes, gekauftes Konto —
keine Daten gehen über die App hinaus.
</p>
<button class="primary" onclick={() => doLogin()} disabled={starting}>
{starting ? 'Starte…' : 'Anmeldung starten'}
</button>
<button class="ghost" onclick={() => checkAuth()} disabled={checking}>
{checking ? 'Prüfe…' : 'Jetzt prüfen'}
</button>
{#if info}<p class="info">{info}</p>{/if}
{#if error}<p class="error">{error}</p>{/if}
</main>
{:else if view === 'library'}
<main>
<header class="bar">
<h1>Hörwerk</h1>
<span class="muted">{books.length} Titel</span>
<button class="ghost" onclick={() => checkAuth()} disabled={checking}>Aushang prüfen</button>
</header>
<div class="ticks"></div>
<section id="next-steps">
<div id="docs">
<svg class="icon" role="presentation" aria-hidden="true">
<use href="/icons.svg#documentation-icon"></use>
</svg>
<h2>Documentation</h2>
<p>Your questions, answered</p>
<ul>
<li>
<a href="https://vite.dev/" target="_blank" rel="noreferrer">
<img class="logo" src={viteLogo} alt="" />
Explore Vite
</a>
</li>
<li>
<a href="https://svelte.dev/" target="_blank" rel="noreferrer">
<img class="button-icon" src={svelteLogo} alt="" />
Learn more
</a>
</li>
</ul>
</div>
<div id="social">
<svg class="icon" role="presentation" aria-hidden="true">
<use href="/icons.svg#social-icon"></use>
</svg>
<h2>Connect with us</h2>
<p>Join the Vite community</p>
<ul>
<li>
<a href="https://github.com/vitejs/vite" target="_blank" rel="noreferrer">
<svg class="button-icon" role="presentation" aria-hidden="true">
<use href="/icons.svg#github-icon"></use>
</svg>
GitHub
</a>
</li>
<li>
<a href="https://chat.vite.dev/" target="_blank" rel="noreferrer">
<svg class="button-icon" role="presentation" aria-hidden="true">
<use href="/icons.svg#discord-icon"></use>
</svg>
Discord
</a>
</li>
<li>
<a href="https://x.com/vite_js" target="_blank" rel="noreferrer">
<svg class="button-icon" role="presentation" aria-hidden="true">
<use href="/icons.svg#x-icon"></use>
</svg>
X.com
</a>
</li>
<li>
<a href="https://bsky.app/profile/vite.dev" target="_blank" rel="noreferrer">
<svg class="button-icon" role="presentation" aria-hidden="true">
<use href="/icons.svg#bluesky-icon"></use>
</svg>
Bluesky
</a>
</li>
</ul>
</div>
</section>
<div class="ticks"></div>
<section id="spacer"></section>
{#if error}
<p class="error">{error}</p>
{:else}
<table>
<thead>
<tr><th>Titel</th><th>Autor</th><th>Sprecher</th><th class="num">Min</th></tr>
</thead>
<tbody>
{#each books as b (b.asin)}
<tr>
<td>{b.title}</td>
<td>{b.authors}</td>
<td>{b.narrators}</td>
<td class="num">{b.runtime_length_min}</td>
</tr>
{/each}
</tbody>
</table>
<p class="muted footnote">Bibliotheksansicht minimal (T-012: Cover, Suche, Sortierung, Status).</p>
{/if}
</main>
{/if}