1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-01-31 14:08:06 +08:00

fix: 增加工具箱获取超时时间 (#3328)

This commit is contained in:
ssongliu 2023-12-14 16:38:22 +08:00 committed by GitHub
parent f91831a5ea
commit 55c71df906
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 26 additions and 21 deletions

View File

@ -14,7 +14,7 @@ import (
// @Description 获取设备基础信息 // @Description 获取设备基础信息
// @Success 200 {object} dto.DeviceBaseInfo // @Success 200 {object} dto.DeviceBaseInfo
// @Security ApiKeyAuth // @Security ApiKeyAuth
// @Router /toolbox/device/base [get] // @Router /toolbox/device/base [post]
func (b *BaseApi) LoadDeviceBaseInfo(c *gin.Context) { func (b *BaseApi) LoadDeviceBaseInfo(c *gin.Context) {
data, err := deviceService.LoadBaseInfo() data, err := deviceService.LoadBaseInfo()
if err != nil { if err != nil {

View File

@ -55,10 +55,15 @@ func (u *DeviceService) LoadBaseInfo() (dto.DeviceBaseInfo, error) {
baseInfo.Hosts = loadHosts() baseInfo.Hosts = loadHosts()
baseInfo.Hostname = loadHostname() baseInfo.Hostname = loadHostname()
baseInfo.User = loadUser() baseInfo.User = loadUser()
ntp, _ := settingRepo.Get(settingRepo.WithByKey("NtpSite")) ntp, err := settingRepo.Get(settingRepo.WithByKey("NtpSite"))
baseInfo.Ntp = ntp.Value 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.SwapMemoryTotal = swapInfo.Total
baseInfo.SwapMemoryAvailable = swapInfo.Free baseInfo.SwapMemoryAvailable = swapInfo.Free
baseInfo.SwapMemoryUsed = swapInfo.Used baseInfo.SwapMemoryUsed = swapInfo.Used
@ -375,7 +380,7 @@ func loadUser() string {
func loadSwap() []dto.SwapHelper { func loadSwap() []dto.SwapHelper {
var data []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 { if err != nil {
return data return data
} }

View File

@ -16,7 +16,7 @@ func (s *ToolboxRouter) InitToolboxRouter(Router *gin.RouterGroup) {
Use(middleware.PasswordExpired()) Use(middleware.PasswordExpired())
baseApi := v1.ApiGroupApp.BaseApi baseApi := v1.ApiGroupApp.BaseApi
{ {
toolboxRouter.GET("/device/base", baseApi.LoadDeviceBaseInfo) toolboxRouter.POST("/device/base", baseApi.LoadDeviceBaseInfo)
toolboxRouter.GET("/device/zone/options", baseApi.LoadTimeOption) toolboxRouter.GET("/device/zone/options", baseApi.LoadTimeOption)
toolboxRouter.POST("/device/update/conf", baseApi.UpdateDeviceConf) toolboxRouter.POST("/device/update/conf", baseApi.UpdateDeviceConf)
toolboxRouter.POST("/device/update/host", baseApi.UpdateDeviceHost) toolboxRouter.POST("/device/update/host", baseApi.UpdateDeviceHost)

View File

@ -10102,7 +10102,7 @@ const docTemplate = `{
} }
}, },
"/toolbox/device/base": { "/toolbox/device/base": {
"get": { "post": {
"security": [ "security": [
{ {
"ApiKeyAuth": [] "ApiKeyAuth": []

View File

@ -10095,7 +10095,7 @@
} }
}, },
"/toolbox/device/base": { "/toolbox/device/base": {
"get": { "post": {
"security": [ "security": [
{ {
"ApiKeyAuth": [] "ApiKeyAuth": []

View File

@ -11190,7 +11190,7 @@ paths:
formatZH: 清理系统垃圾文件 formatZH: 清理系统垃圾文件
paramKeys: [] paramKeys: []
/toolbox/device/base: /toolbox/device/base:
get: post:
description: 获取设备基础信息 description: 获取设备基础信息
responses: responses:
"200": "200":

View File

@ -6,16 +6,16 @@ import { TimeoutEnum } from '@/enums/http-enum';
// device // device
export const getDeviceBase = () => { 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 = () => { export const loadTimeZoneOptions = () => {
return http.get<Array<string>>(`/toolbox/device/zone/options`); return http.get<Array<string>>(`/toolbox/device/zone/options`);
}; };
export const updateDevice = (key: string, value: string) => { 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>) => { 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) => { export const updateDevicePasswd = (user: string, passwd: string) => {
return http.post(`/toolbox/device/update/passwd`, { user: user, passwd: Base64.encode(passwd) }); return http.post(`/toolbox/device/update/passwd`, { user: user, passwd: Base64.encode(passwd) });

View File

@ -69,7 +69,7 @@
{{ $t('home.free') }}: {{ formatNumber(currentInfo.swapMemoryAvailable / 1024 / 1024) }} MB {{ $t('home.free') }}: {{ formatNumber(currentInfo.swapMemoryAvailable / 1024 / 1024) }} MB
</el-tag> </el-tag>
<el-tag class="tagClass"> <el-tag class="tagClass">
{{ $t('home.percent') }}: {{ formatNumber(currentInfo.swapMemoryUsedPercent * 100) }}% {{ $t('home.percent') }}: {{ formatNumber(currentInfo.swapMemoryUsedPercent) }}%
</el-tag> </el-tag>
</div> </div>
<template #reference> <template #reference>

View File

@ -5,7 +5,7 @@
<DrawerHeader header="DNS" :back="handleClose" /> <DrawerHeader header="DNS" :back="handleClose" />
</template> </template>
<el-row type="flex" justify="center"> <el-row type="flex" justify="center" v-loading="loading">
<el-col :span="22"> <el-col :span="22">
<el-alert <el-alert
:title="$t('toolbox.device.dnsAlert')" :title="$t('toolbox.device.dnsAlert')"
@ -24,7 +24,6 @@
label-position="top" label-position="top"
@submit.prevent @submit.prevent
:model="form" :model="form"
v-loading="loading"
> >
<el-form-item label="DNS" prop="dns"> <el-form-item label="DNS" prop="dns">
<el-input <el-input

View File

@ -5,7 +5,7 @@
<DrawerHeader :header="$t('toolbox.device.hostname')" :back="handleClose" /> <DrawerHeader :header="$t('toolbox.device.hostname')" :back="handleClose" />
</template> </template>
<el-row type="flex" justify="center"> <el-row type="flex" justify="center" v-loading="loading">
<el-col :span="22"> <el-col :span="22">
<el-alert <el-alert
:title="$t('toolbox.device.hostnameHelper')" :title="$t('toolbox.device.hostnameHelper')"
@ -13,7 +13,7 @@
:closable="false" :closable="false"
type="warning" 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 <el-form-item
:label="$t('toolbox.device.hostname')" :label="$t('toolbox.device.hostname')"
prop="hostname" prop="hostname"
@ -76,6 +76,7 @@ const onSaveHostame = async (formEl: FormInstance | undefined) => {
type: 'info', type: 'info',
}, },
).then(async () => { ).then(async () => {
loading.value = true;
await updateDevice('Hostname', form.hostname) await updateDevice('Hostname', form.hostname)
.then(async () => { .then(async () => {
MsgSuccess(i18n.global.t('commons.msg.operationSuccess')); MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));

View File

@ -5,7 +5,7 @@
<DrawerHeader header="Hosts" :back="handleClose" /> <DrawerHeader header="Hosts" :back="handleClose" />
</template> </template>
<el-row type="flex" justify="center"> <el-row type="flex" justify="center" v-loading="loading">
<el-col :span="22"> <el-col :span="22">
<el-radio-group v-model="confShowType" @change="changeMode"> <el-radio-group v-model="confShowType" @change="changeMode">
<el-radio-button label="base">{{ $t('database.baseConf') }}</el-radio-button> <el-radio-button label="base">{{ $t('database.baseConf') }}</el-radio-button>

View File

@ -1,11 +1,11 @@
<template> <template>
<div v-loading="loading"> <div>
<el-drawer v-model="passwordVisible" :destroy-on-close="true" :close-on-click-modal="false" size="30%"> <el-drawer v-model="passwordVisible" :destroy-on-close="true" :close-on-click-modal="false" size="30%">
<template #header> <template #header>
<DrawerHeader :header="$t('setting.changePassword')" :back="handleClose" /> <DrawerHeader :header="$t('setting.changePassword')" :back="handleClose" />
</template> </template>
<el-row type="flex" justify="center"> <el-row type="flex" justify="center" v-loading="loading">
<el-col :span="22"> <el-col :span="22">
<el-form ref="formRef" label-position="top" :model="form" :rules="passRules"> <el-form ref="formRef" label-position="top" :model="form" :rules="passRules">
<el-alert <el-alert

View File

@ -1,5 +1,5 @@
<template> <template>
<div v-loading="loading"> <div>
<el-drawer v-model="drawerVisible" :destroy-on-close="true" :close-on-click-modal="false" size="50%"> <el-drawer v-model="drawerVisible" :destroy-on-close="true" :close-on-click-modal="false" size="50%">
<template #header> <template #header>
<DrawerHeader header="Swap" :back="handleClose" /> <DrawerHeader header="Swap" :back="handleClose" />