forked from halo-dev/halo
-
Notifications
You must be signed in to change notification settings - Fork 38
/
Actuator.vue
265 lines (247 loc) · 8.08 KB
/
Actuator.vue
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
<script lang="ts" setup>
import {
IconTerminalBoxLine,
IconClipboardLine,
VAlert,
VPageHeader,
VCard,
VButton,
Toast,
VDescription,
VDescriptionItem,
} from "@halo-dev/components";
import { computed, onMounted, ref } from "vue";
import type { Info, GlobalInfo, Startup } from "./types";
import axios from "axios";
import { formatDatetime } from "@/utils/date";
import { useClipboard } from "@vueuse/core";
import { useI18n } from "vue-i18n";
const { t } = useI18n();
const info = ref<Info>();
const globalInfo = ref<GlobalInfo>();
const startup = ref<Startup>();
const handleFetchActuatorInfo = async () => {
const { data } = await axios.get(
`${import.meta.env.VITE_API_URL}/actuator/info`,
{
withCredentials: true,
}
);
info.value = data;
};
const handleFetchActuatorGlobalInfo = async () => {
const { data } = await axios.get(
`${import.meta.env.VITE_API_URL}/actuator/globalinfo`,
{
withCredentials: true,
}
);
globalInfo.value = data;
};
const handleFetchActuatorStartup = async () => {
const { data } = await axios.get(
`${import.meta.env.VITE_API_URL}/actuator/startup`,
{
withCredentials: true,
}
);
startup.value = data;
};
const isExternalUrlValid = computed(() => {
if (!globalInfo.value?.useAbsolutePermalink) {
return true;
}
if (!globalInfo.value?.externalUrl) {
return true;
}
const url = new URL(globalInfo.value.externalUrl);
const { host: currentHost, protocol: currentProtocol } = window.location;
return url.host === currentHost && url.protocol === currentProtocol;
});
onMounted(() => {
handleFetchActuatorInfo();
handleFetchActuatorGlobalInfo();
handleFetchActuatorStartup();
});
// copy system information to clipboard
const { copy, isSupported } = useClipboard({ legacy: true });
const handleCopy = () => {
if (!isSupported.value) {
Toast.warning(t("core.actuator.actions.copy.toast_browser_not_supported"));
return;
}
const text = `
- ${t("core.actuator.copy_results.external_url", {
external_url: globalInfo.value?.externalUrl,
})}
- ${t("core.actuator.copy_results.start_time", {
start_time: formatDatetime(startup.value?.timeline.startTime),
})}
- ${t("core.actuator.fields.version", { version: info.value?.build?.version })}
- ${t("core.actuator.copy_results.build_time", {
build_time: formatDatetime(info.value?.build?.time),
})}
- Git Commit:${info.value?.git?.commit.id}
- Java:${info.value?.java.runtime.name} / ${info.value?.java.runtime.version}
- ${t("core.actuator.copy_results.database", {
database: [info.value?.database.name, info.value?.database.version].join(
" / "
),
})}
- ${t("core.actuator.copy_results.os", {
os: [info.value?.os.name, info.value?.os.version].join(" / "),
})}
`;
copy(text);
Toast.success(t("core.common.toast.copy_success"));
};
const handleDownloadLogfile = () => {
axios
.get(`${import.meta.env.VITE_API_URL}/actuator/logfile`)
.then((response) => {
const blob = new Blob([response.data]);
const downloadElement = document.createElement("a");
const href = window.URL.createObjectURL(blob);
downloadElement.href = href;
downloadElement.download = `halo-log-${formatDatetime(new Date())}.log`;
document.body.appendChild(downloadElement);
downloadElement.click();
document.body.removeChild(downloadElement);
window.URL.revokeObjectURL(href);
Toast.success(t("core.common.toast.download_success"));
})
.catch((e) => {
Toast.error(t("core.common.toast.download_failed"));
console.log("Failed to download log file.", e);
});
};
</script>
<template>
<VPageHeader :title="$t('core.actuator.title')">
<template #icon>
<IconTerminalBoxLine class="mr-2 self-center" />
</template>
<template #actions>
<VButton size="sm" @click="handleCopy">
<template #icon>
<IconClipboardLine class="h-full w-full" />
</template>
{{ $t("core.common.buttons.copy") }}
</VButton>
</template>
</VPageHeader>
<div class="m-0 flex flex-col gap-4 md:m-4">
<VCard :body-class="['!p-0']">
<div class="bg-white">
<div
class="flex items-center justify-between bg-white px-4 py-4 sm:px-6"
>
<div>
<h3 class="text-lg font-medium leading-6 text-gray-900">
{{ $t("core.actuator.header.titles.general") }}
</h3>
</div>
</div>
<div class="border-t border-gray-200">
<VDescription>
<VDescriptionItem :label="$t('core.actuator.fields.external_url')">
<span v-if="globalInfo?.externalUrl">
{{ globalInfo?.externalUrl }}
</span>
<span v-else>
{{ $t("core.actuator.fields_values.external_url.not_setup") }}
</span>
<VAlert
v-if="!isExternalUrlValid"
class="mt-3"
type="warning"
:title="$t('core.common.text.warning')"
:closable="false"
>
<template #description>
{{ $t("core.actuator.alert.external_url_invalid") }}
</template>
</VAlert>
</VDescriptionItem>
<VDescriptionItem
:label="$t('core.actuator.fields.start_time')"
:content="formatDatetime(startup?.timeline.startTime)"
/>
<VDescriptionItem
:label="$t('core.actuator.fields.timezone')"
:content="globalInfo?.timeZone"
/>
<VDescriptionItem
:label="$t('core.actuator.fields.locale')"
:content="globalInfo?.locale"
/>
</VDescription>
</div>
</div>
</VCard>
<VCard v-if="info" :body-class="['!p-0']">
<div class="bg-white">
<div
class="flex items-center justify-between bg-white px-4 py-4 sm:px-6"
>
<div>
<h3 class="text-lg font-medium leading-6 text-gray-900">
{{ $t("core.actuator.header.titles.environment") }}
</h3>
</div>
</div>
<div class="border-t border-gray-200">
<VDescription>
<VDescriptionItem
v-if="info.build"
:label="$t('core.actuator.fields.version')"
>
<a
:href="`https://github.com/halo-dev/halo/releases/tag/v${info.build.version}`"
class="hover:text-gray-600"
target="_blank"
>
{{ info.build.version }}
</a>
</VDescriptionItem>
<VDescriptionItem
v-if="info.build"
:label="$t('core.actuator.fields.build_time')"
:content="formatDatetime(info.build.time)"
/>
<VDescriptionItem v-if="info.git" label="Git Commit">
<a
:href="`https://github.com/halo-dev/halo/commit/${info.git.commit.id}`"
class="hover:text-gray-600"
target="_blank"
>
{{ info.git.commit.id }}
</a>
</VDescriptionItem>
<VDescriptionItem
label="Java"
:content="
[info.java.runtime.name, info.java.runtime.version].join(' / ')
"
/>
<VDescriptionItem
:label="$t('core.actuator.fields.database')"
:content="[info.database.name, info.database.version].join(' / ')"
/>
<VDescriptionItem :label="$t('core.actuator.fields.os')">
{{ info.os.name }} {{ info.os.version }} / {{ info.os.arch }}
</VDescriptionItem>
<VDescriptionItem
:label="$t('core.actuator.fields.log')"
vertical-center
>
<VButton size="sm" @click="handleDownloadLogfile()">
{{ $t("core.common.buttons.download") }}
</VButton>
</VDescriptionItem>
</VDescription>
</div>
</div>
</VCard>
</div>
</template>