ui: align js with api

This commit is contained in:
2026-06-03 01:30:38 +00:00
parent 007e61bca1
commit b29520c5af
4 changed files with 77 additions and 22 deletions
+5 -7
View File
@@ -36,6 +36,7 @@
</div>
<script type="module">
import Alpine from 'alpinejs'
import { requireAuth } from '/src/auth.js'
import { logout, getchannels, getmessages } from '/src/api.js'
window.app = () => ({
@@ -45,12 +46,9 @@
selectedChannel: null,
messages: [],
async init() {
const res = await fetch('/api/whoami')
if (res.status === 401) {
window.location.href = '/login.html'
return
}
this.username = await res.text()
const username = await requireAuth()
if (!username) return
this.username = username
try {
this.channels = await getchannels()
} catch (e) {
@@ -62,7 +60,7 @@
this.messages = []
this.error = ''
try {
const from = new Date(Date.now() - 24 * 60 * 60 * 1000)
const from = new Date(Date.now() - 96 * 60 * 60 * 1000)
const to = new Date(Date.now())
this.messages = await getmessages(ch.ID, { from, to })
} catch (e) {