feat: v0.2.0 branding, healthz version, SSE dashboard live
Centralize APP_VERSION 0.2.0; /health and /healthz return version; startup log line; UI title Security Alert Center v.0.2.0; SSE /api/v1/stream/events for live dashboard counters.
This commit is contained in:
@@ -54,17 +54,20 @@
|
||||
</table>
|
||||
<div class="filters" style="margin-top: 1rem">
|
||||
<button type="button" class="secondary" @click="load">Обновить</button>
|
||||
<span v-if="live" class="live-badge">live</span>
|
||||
</div>
|
||||
</template>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from "vue";
|
||||
import { apiFetch, type DashboardSummary } from "../api";
|
||||
import { onMounted, onUnmounted, ref } from "vue";
|
||||
import { apiFetch, getToken, type DashboardSummary } from "../api";
|
||||
|
||||
const data = ref<DashboardSummary | null>(null);
|
||||
const loading = ref(false);
|
||||
const error = ref("");
|
||||
const live = ref(false);
|
||||
let eventSource: EventSource | null = null;
|
||||
|
||||
function formatDt(iso: string) {
|
||||
return new Date(iso).toLocaleString("ru-RU");
|
||||
@@ -82,5 +85,44 @@ async function load() {
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => load());
|
||||
function connectLive() {
|
||||
const token = getToken();
|
||||
if (!token) return;
|
||||
eventSource?.close();
|
||||
const url = `/api/v1/stream/events?token=${encodeURIComponent(token)}`;
|
||||
eventSource = new EventSource(url);
|
||||
eventSource.onopen = () => {
|
||||
live.value = true;
|
||||
};
|
||||
eventSource.onmessage = (ev) => {
|
||||
try {
|
||||
const msg = JSON.parse(ev.data) as {
|
||||
type?: string;
|
||||
events_last_24h?: number;
|
||||
problems_open?: number;
|
||||
};
|
||||
if (msg.type !== "dashboard" || !data.value) return;
|
||||
if (typeof msg.events_last_24h === "number") {
|
||||
data.value.events_last_24h = msg.events_last_24h;
|
||||
}
|
||||
if (typeof msg.problems_open === "number") {
|
||||
data.value.problems_open = msg.problems_open;
|
||||
}
|
||||
} catch {
|
||||
/* ignore malformed SSE */
|
||||
}
|
||||
};
|
||||
eventSource.onerror = () => {
|
||||
live.value = false;
|
||||
};
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
load().then(() => connectLive());
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
eventSource?.close();
|
||||
eventSource = null;
|
||||
});
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user