ver优化

This commit is contained in:
gotoeasy 2023-10-24 15:32:52 +08:00
parent 8f2722479a
commit 0e577a90f6
7 changed files with 51 additions and 19 deletions

View File

@ -3,6 +3,7 @@ package onstart
import (
"fmt"
"glc/conf"
"glc/ver"
"os"
"os/exec"
"os/user"
@ -43,7 +44,7 @@ func init() {
}
// 查看版本
if version {
fmt.Printf("%s\n", VERSION)
fmt.Printf("%s\n", "glogcenter "+ver.VERSION)
os.Exit(0)
}

View File

@ -42,6 +42,7 @@ func Run() {
gweb.RegisterController(method.POST, contextPath+"/v1/store/delete", controller.StorageDeleteController) // 删除日志仓
gweb.RegisterController(method.POST, contextPath+"/v1/user/enableLogin", controller.IsEnableLoginController) // 查询是否开启用户密码登录功能
gweb.RegisterController(method.POST, contextPath+"/v1/user/login", controller.LoginController) // Login
gweb.RegisterController(method.POST, contextPath+"/v1/version/info", controller.VersionController) // 查询版本信息
// 集群操作接口
gweb.RegisterController(method.POST, contextPath+"/sys/cluster/info", controller.ClusterGetClusterInfoController) // 获取集群信息

View File

@ -1,3 +0,0 @@
package onstart
const VERSION = "glogcenter 0.12.0"

3
glc/ver/version.go Normal file
View File

@ -0,0 +1,3 @@
package ver
const VERSION = "v0.12.0"

View File

@ -1,16 +1,24 @@
package controller
import (
"encoding/json"
"fmt"
"glc/com"
"glc/conf"
"glc/gweb"
"glc/ldb/status"
"glc/ldb/sysmnt"
"glc/ver"
"github.com/gotoeasy/glang/cmn"
)
// 查询版本信息
func VersionController(req *gweb.HttpRequest) *gweb.HttpResult {
rs := cmn.OfMap("version", ver.VERSION, "latest", getLatestVersion()) // version当前版本号latest最新版本号
return gweb.Result(rs)
}
// 查询日志仓名称列表
func StorageNamesController(req *gweb.HttpRequest) *gweb.HttpResult {
if conf.IsEnableLogin() && req.GetFormParameter("token") != GetSessionid() {
@ -63,3 +71,20 @@ func StorageDeleteController(req *gweb.HttpRequest) *gweb.HttpResult {
}
return gweb.Ok()
}
// 尝试查询最新版本号(注:这里不能保证服务一定可用),查不到返回空串
func getLatestVersion() string {
// {"version":"v0.12.0"}
bts, err := cmn.HttpGetJson("https://glc.gotoeasy.top/glogcenter/current/version.json?v=" + ver.VERSION) // 取最新版本号
if err != nil {
return ""
}
var data struct {
Version string `json:"version,omitempty"`
}
if err := json.Unmarshal(bts, &data); err != nil {
return ""
}
return data.Version
}

View File

@ -8,9 +8,6 @@ VITE_PRD_DROP_DEBUGGER = true
# 开发模式下是否要启用MOCK
VITE_DEV_MOCK = false
# Logo提示
VITE_GLC_INFO = "v0.12.0"
# --------------------------------------------------------
# 【例1】
# 配置 VITE_DEV_DOMAIN_URL = "http://127.0.0.1:8080"

View File

@ -22,10 +22,8 @@
import { gxUtil, useThemeStore, useTokenStore } from '~/pkgs';
import { userLogout } from '~/api';
const { VITE_GLC_INFO } = import.meta.env;
const router = useRouter();
const verInfo = ref(VITE_GLC_INFO);
const verInfo = ref('');
const tokenStore = useTokenStore();
const themeStore = useThemeStore();
const headerHeight = computed(() => `${themeStore.headerHeight}px`);
@ -79,15 +77,25 @@ const clickLogo = () => {
};
function checkVersion() {
!window.$checkVersionDone && (window.$checkVersionDone = 1) && fetch(`https://glc.gotoeasy.top/glogcenter/current/version.json?v=${VITE_GLC_INFO}`)
.then(response => response.text())
.then(data => {
const rs = JSON.parse(data)
if (rs.version && VITE_GLC_INFO < rs.version) {
verInfo.value = `当前版本 ${VITE_GLC_INFO} ,有新版本 ${rs.version} 可更新`
}
})
.catch(e => console.log(e));
if (!window.$checkVersionDone) {
window.$checkVersionDone = true;
fetch('/v1/version/info', { method: 'POST' })
.then(response => response.json())
.then(data1 => { //
verInfo.value = data1.version
fetch(`https://glc.gotoeasy.top/glogcenter/current/version.json?v=${data1.version}`)
.then(response => response.json())
.then(data2 => { // tip
if (data2.version && data1.version < data2.version) {
verInfo.value = `当前版本 ${data1.version} ,有新版本 ${data2.version} 可更新`
}
})
.catch(e => console.log(e));
})
.catch(e => console.log(e));
}
}
</script>