create very rough UI

This commit is contained in:
2026-06-03 00:31:35 +00:00
parent 2efe08b247
commit b379b7a5af
9 changed files with 1157 additions and 0 deletions
+28
View File
@@ -0,0 +1,28 @@
export async function login(username, password) {
const form = new FormData()
form.append('username', username)
form.append('password', password)
const res = await fetch('/api/login', { method: 'POST', body: form })
if (!res.ok) throw new Error(await res.text())
}
export async function logout() {
const res = await fetch('/api/logout', { method: 'POST' })
if (!res.ok) throw new Error(await res.text())
}
export async function getchannels() {
const res = await fetch('/api/channels')
if (!res.ok) throw new Error(await res.text())
return res.json()
}
export async function getmessages(channelid, { from, to } = {}) {
const params = new URLSearchParams()
if (from) params.set('from', from.toISOString())
if (to) params.set('to', to.toISOString())
const query = params.size ? `?${params}` : ''
const res = await fetch(`/api/channels/${channelid}/messages${query}`)
if (!res.ok) throw new Error(await res.text())
return res.json()
}
+13
View File
@@ -0,0 +1,13 @@
export async function requireAuth() {
const res = await fetch('/api/whoami')
if (res.status === 401) {
window.location.href = '/login.html'
}
}
export async function redirectIfAuthed() {
const res = await fetch('/api/whoami')
if (res.ok) {
window.location.href = '/'
}
}
+1
View File
@@ -0,0 +1 @@
// Alpine is initialized per-page inline in each HTML file