-
Notifications
You must be signed in to change notification settings - Fork 295
Expand file tree
/
Copy pathsystem.js
More file actions
84 lines (77 loc) · 1.83 KB
/
system.js
File metadata and controls
84 lines (77 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import { defineStore } from 'pinia'
import { ref } from 'vue'
import { systemApi } from '../api/system'
import { spiderApi } from '../api/spider'
export const useSystemStore = defineStore('system', () => {
const health = ref({ status: 'unknown' })
const logs = ref([])
const routes = ref([])
const sources = ref({ js: [], catvod: [] })
const loading = ref(false)
const error = ref(null)
const checkHealth = async () => {
try {
health.value = await systemApi.getHealth()
} catch (e) {
health.value = { status: 'error', message: e.message }
}
}
const fetchLogs = async (lines = 100) => {
loading.value = true
error.value = null
try {
logs.value = await systemApi.getLogs(lines)
} catch (e) {
error.value = e.message
console.error('Failed to fetch logs:', e)
} finally {
loading.value = false
}
}
const fetchRoutes = async () => {
try {
routes.value = await systemApi.getRoutes()
} catch (e) {
error.value = e.message
console.error('Failed to fetch routes:', e)
}
}
const fetchSources = async () => {
loading.value = true
error.value = null
try {
sources.value = await spiderApi.listSources()
} catch (e) {
error.value = e.message
console.error('Failed to fetch sources:', e)
} finally {
loading.value = false
}
}
const restartService = async () => {
loading.value = true
error.value = null
try {
await systemApi.restartService()
} catch (e) {
error.value = e.message
console.error('Failed to restart service:', e)
throw e
} finally {
loading.value = false
}
}
return {
health,
logs,
routes,
sources,
loading,
error,
checkHealth,
fetchLogs,
fetchRoutes,
fetchSources,
restartService
}
})