Skip to content

Commit

Permalink
add more error & loading hint for dashboard loglist
Browse files Browse the repository at this point in the history
  • Loading branch information
zyxkad committed Jun 7, 2024
1 parent f87833e commit 919d0b7
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 15 deletions.
5 changes: 4 additions & 1 deletion api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,7 @@ func (cr *Cluster) apiV0LogFiles(rw http.ResponseWriter, req *http.Request) {
}

func (cr *Cluster) apiV0LogFile(rw http.ResponseWriter, req *http.Request) {
if checkRequestMethodOrRejectWithJson(rw, req, http.MethodGet) {
if checkRequestMethodOrRejectWithJson(rw, req, http.MethodGet, http.MethodHead) {
return
}
query := req.URL.Query()
Expand Down Expand Up @@ -1084,6 +1084,9 @@ func (cr *Cluster) apiV0LogFile(rw http.ResponseWriter, req *http.Request) {

func (cr *Cluster) apiV0LogFileEncrypted(rw http.ResponseWriter, req *http.Request, r io.Reader, useGzip bool) {
rw.WriteHeader(http.StatusOK)
if req.Method == http.MethodHead {
return
}
if useGzip {
pr, pw := io.Pipe()
defer pr.Close()
Expand Down
6 changes: 5 additions & 1 deletion dashboard/src/assets/lang/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@
},
"settings": {
"login": {
"first": "Please login first before enable this feature"
"auth": "Require authuation",
"first": "You have to login before use this feature"
},
"notify": {
"cant.enable": "Cannot enable notification",
Expand All @@ -93,6 +94,9 @@
"webpush": {
"cant.enable": "Cannot enable Web Push",
"denied": "Web Push is denied by the browser"
},
"filelist": {
"cant.fetch": "Cannot fetch filelist"
}
}
},
Expand Down
6 changes: 5 additions & 1 deletion dashboard/src/assets/lang/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@
},
"settings": {
"login": {
"first": "启用此功能前请先登录"
"auth": "需要授权",
"first": "使用此功能前请先登录"
},
"notify": {
"cant.enable": "无法启用通知",
Expand All @@ -93,6 +94,9 @@
"webpush": {
"cant.enable": "无法启用推送",
"denied": "推送已被浏览器拒绝"
},
"filelist": {
"cant.fetch": "无法获取文件列表"
}
}
},
Expand Down
21 changes: 19 additions & 2 deletions dashboard/src/components/FileContentCard.vue
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
<script setup lang="ts">
import Button from 'primevue/button'
import ProgressSpinner from 'primevue/progressspinner'
import type { FileInfo } from '@/api/v0'
defineProps<{
info: FileInfo
content: string
content: string | null
}>()
</script>
<template>
<div>
<slot :info="info" :content="content" />
<pre class="code-box"><code>{{ content }}</code></pre>
<pre v-if="content" class="code-box"><code>{{ content }}</code></pre>
<div v-else class="loading-box">
<div class="flex-row-center">
<ProgressSpinner
style="width: 2em; height: 2em; margin: 0 0.5em 0 0"
strokeWidth="5"
fill="var(--surface-ground)"
animationDuration="1s"
/>
<i>Loading...</i>
</div>
</div>
</div>
</template>
<style scoped>
Expand All @@ -22,4 +34,9 @@ defineProps<{
background: var(--surface-c);
overflow: auto;
}
.loading-box {
height: 62vh;
padding: 1rem;
}
</style>
54 changes: 45 additions & 9 deletions dashboard/src/views/LogListView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,61 @@ const token = inject('token') as Ref<string | null>
const logList = ref<FileInfo[] | null>(null)
async function refreshFileList(): Promise<void> {
if (!token.value) {
toast.add({
severity: 'warn',
summary: tr('message.settings.login.auth'),
detail: tr('message.settings.login.first'),
})
return
}
logList.value = await getLogFiles(token.value)
try {
logList.value = await getLogFiles(token.value)
} catch (e) {
toast.add({
severity: 'error',
summary: tr('message.settings.filelist.cant.fetch'),
detail: String(e),
})
}
}
const showInfo = ref<FileInfo | null>(null)
const fileContent = ref<string | null>(null)
async function openFile(file: FileInfo): Promise<void> {
if (!token.value) {
toast.add({
severity: 'error',
summary: tr('message.settings.login.auth'),
detail: tr('message.settings.login.first'),
life: 10000,
})
return
}
if (showInfo.value) {
toast.add({
severity: 'error',
summary: 'Another file is opening',
life: 5000,
})
return
}
const buf = await getLogFile(token.value, file.name, true)
showInfo.value = file
fileContent.value = null
var buf: ArrayBuffer
try {
buf = await getLogFile(token.value, file.name, true)
} catch (e) {
toast.add({
severity: 'error',
summary: tr('message.settings.filelist.cant.fetch'),
detail: String(e),
})
return
}
if (showInfo.value.name !== file.name) {
return
}
fileContent.value = new TextDecoder().decode(new Uint8Array(buf))
}
Expand Down Expand Up @@ -59,17 +100,12 @@ onMounted(() => {
</FileListCard>
<Dialog
:visible="!!showInfo"
@update:visible="(show) => !show && (showInfo = null)"
@update:visible="(show) => !show && ((showInfo = null), (fileContent = null))"
modal
:header="(showInfo && showInfo.name) || undefined"
:style="{ width: 'var(--dialog-width)' }"
>
<FileContentCard
v-if="showInfo && fileContent"
:info="showInfo"
:content="fileContent"
v-slot="{ info }"
>
<FileContentCard v-if="showInfo" :info="showInfo" :content="fileContent" v-slot="{ info }">
<div class="flex-row-center tool-box">
<Button
icon="pi pi-download"
Expand Down
3 changes: 2 additions & 1 deletion dashboard/src/views/SettingsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ async function onEnableNotify(): Promise<void> {
if (!token.value) {
toast.add({
severity: 'error',
summary: tr('message.settings.login.first'),
summary: tr('message.settings.login.auth'),
detail: tr('message.settings.login.first'),
life: 5000,
})
return
Expand Down

0 comments on commit 919d0b7

Please sign in to comment.