Skip to content

Commit

Permalink
fix: 增加工具箱获取超时时间 (#3328)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssongliu authored Dec 14, 2023
1 parent f91831a commit 55c71df
Show file tree
Hide file tree
Showing 13 changed files with 26 additions and 21 deletions.
2 changes: 1 addition & 1 deletion backend/app/api/v1/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
// @Description 获取设备基础信息
// @Success 200 {object} dto.DeviceBaseInfo
// @Security ApiKeyAuth
// @Router /toolbox/device/base [get]
// @Router /toolbox/device/base [post]
func (b *BaseApi) LoadDeviceBaseInfo(c *gin.Context) {
data, err := deviceService.LoadBaseInfo()
if err != nil {
Expand Down
13 changes: 9 additions & 4 deletions backend/app/service/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,15 @@ func (u *DeviceService) LoadBaseInfo() (dto.DeviceBaseInfo, error) {
baseInfo.Hosts = loadHosts()
baseInfo.Hostname = loadHostname()
baseInfo.User = loadUser()
ntp, _ := settingRepo.Get(settingRepo.WithByKey("NtpSite"))
baseInfo.Ntp = ntp.Value
ntp, err := settingRepo.Get(settingRepo.WithByKey("NtpSite"))
if err == nil {
baseInfo.Ntp = ntp.Value
}

swapInfo, _ := mem.SwapMemory()
swapInfo, err := mem.SwapMemory()
if err != nil {
return baseInfo, err
}
baseInfo.SwapMemoryTotal = swapInfo.Total
baseInfo.SwapMemoryAvailable = swapInfo.Free
baseInfo.SwapMemoryUsed = swapInfo.Used
Expand Down Expand Up @@ -375,7 +380,7 @@ func loadUser() string {

func loadSwap() []dto.SwapHelper {
var data []dto.SwapHelper
std, err := cmd.Execf("%s swapon --show --summary", cmd.SudoHandleCmd())
std, err := cmd.Execf("%s swapon --summary", cmd.SudoHandleCmd())
if err != nil {
return data
}
Expand Down
2 changes: 1 addition & 1 deletion backend/router/ro_toolbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func (s *ToolboxRouter) InitToolboxRouter(Router *gin.RouterGroup) {
Use(middleware.PasswordExpired())
baseApi := v1.ApiGroupApp.BaseApi
{
toolboxRouter.GET("/device/base", baseApi.LoadDeviceBaseInfo)
toolboxRouter.POST("/device/base", baseApi.LoadDeviceBaseInfo)
toolboxRouter.GET("/device/zone/options", baseApi.LoadTimeOption)
toolboxRouter.POST("/device/update/conf", baseApi.UpdateDeviceConf)
toolboxRouter.POST("/device/update/host", baseApi.UpdateDeviceHost)
Expand Down
2 changes: 1 addition & 1 deletion cmd/server/docs/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cmd/server/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -10095,7 +10095,7 @@
}
},
"/toolbox/device/base": {
"get": {
"post": {
"security": [
{
"ApiKeyAuth": []
Expand Down
2 changes: 1 addition & 1 deletion cmd/server/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11190,7 +11190,7 @@ paths:
formatZH: 清理系统垃圾文件
paramKeys: []
/toolbox/device/base:
get:
post:
description: 获取设备基础信息
responses:
"200":
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/api/modules/toolbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ import { TimeoutEnum } from '@/enums/http-enum';

// device
export const getDeviceBase = () => {
return http.get<Toolbox.DeviceBaseInfo>(`/toolbox/device/base`);
return http.post<Toolbox.DeviceBaseInfo>(`/toolbox/device/base`, {}, TimeoutEnum.T_60S);
};
export const loadTimeZoneOptions = () => {
return http.get<Array<string>>(`/toolbox/device/zone/options`);
};
export const updateDevice = (key: string, value: string) => {
return http.post(`/toolbox/device/update/conf`, { key: key, value: value });
return http.post(`/toolbox/device/update/conf`, { key: key, value: value }, TimeoutEnum.T_60S);
};
export const updateDeviceHost = (param: Array<Toolbox.TimeZoneOptions>) => {
return http.post(`/toolbox/device/update/host`, param);
return http.post(`/toolbox/device/update/host`, param, TimeoutEnum.T_60S);
};
export const updateDevicePasswd = (user: string, passwd: string) => {
return http.post(`/toolbox/device/update/passwd`, { user: user, passwd: Base64.encode(passwd) });
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/views/home/status/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
{{ $t('home.free') }}: {{ formatNumber(currentInfo.swapMemoryAvailable / 1024 / 1024) }} MB
</el-tag>
<el-tag class="tagClass">
{{ $t('home.percent') }}: {{ formatNumber(currentInfo.swapMemoryUsedPercent * 100) }}%
{{ $t('home.percent') }}: {{ formatNumber(currentInfo.swapMemoryUsedPercent) }}%
</el-tag>
</div>
<template #reference>
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/views/toolbox/device/dns/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<DrawerHeader header="DNS" :back="handleClose" />
</template>

<el-row type="flex" justify="center">
<el-row type="flex" justify="center" v-loading="loading">
<el-col :span="22">
<el-alert
:title="$t('toolbox.device.dnsAlert')"
Expand All @@ -24,7 +24,6 @@
label-position="top"
@submit.prevent
:model="form"
v-loading="loading"
>
<el-form-item label="DNS" prop="dns">
<el-input
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/views/toolbox/device/hostname/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
<DrawerHeader :header="$t('toolbox.device.hostname')" :back="handleClose" />
</template>

<el-row type="flex" justify="center">
<el-row type="flex" justify="center" v-loading="loading">
<el-col :span="22">
<el-alert
:title="$t('toolbox.device.hostnameHelper')"
class="common-prompt"
:closable="false"
type="warning"
/>
<el-form ref="formRef" label-position="top" :model="form" @submit.prevent v-loading="loading">
<el-form ref="formRef" label-position="top" :model="form" @submit.prevent>
<el-form-item
:label="$t('toolbox.device.hostname')"
prop="hostname"
Expand Down Expand Up @@ -76,6 +76,7 @@ const onSaveHostame = async (formEl: FormInstance | undefined) => {
type: 'info',
},
).then(async () => {
loading.value = true;
await updateDevice('Hostname', form.hostname)
.then(async () => {
MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/views/toolbox/device/hosts/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<DrawerHeader header="Hosts" :back="handleClose" />
</template>

<el-row type="flex" justify="center">
<el-row type="flex" justify="center" v-loading="loading">
<el-col :span="22">
<el-radio-group v-model="confShowType" @change="changeMode">
<el-radio-button label="base">{{ $t('database.baseConf') }}</el-radio-button>
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/views/toolbox/device/passwd/index.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<template>
<div v-loading="loading">
<div>
<el-drawer v-model="passwordVisible" :destroy-on-close="true" :close-on-click-modal="false" size="30%">
<template #header>
<DrawerHeader :header="$t('setting.changePassword')" :back="handleClose" />
</template>

<el-row type="flex" justify="center">
<el-row type="flex" justify="center" v-loading="loading">
<el-col :span="22">
<el-form ref="formRef" label-position="top" :model="form" :rules="passRules">
<el-alert
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/views/toolbox/device/swap/index.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div v-loading="loading">
<div>
<el-drawer v-model="drawerVisible" :destroy-on-close="true" :close-on-click-modal="false" size="50%">
<template #header>
<DrawerHeader header="Swap" :back="handleClose" />
Expand Down

0 comments on commit 55c71df

Please sign in to comment.