feat(ota): show short hash

This commit is contained in:
Jacky 2025-05-03 08:13:58 +08:00
parent 1c282a57ad
commit 3fe4d859df
No known key found for this signature in database
GPG key ID: 215C21B10DF38B4D
6 changed files with 34 additions and 18 deletions

View file

@ -7,6 +7,14 @@ export interface RuntimeInfo {
ex_path: string ex_path: string
body: string body: string
published_at: string published_at: string
cur_version: Info
}
interface Info {
version: string
build_id: number
total_build: number
short_hash: string
} }
const upgrade = { const upgrade = {

View file

@ -32,12 +32,13 @@ export function handleApiError(err: CosyError, dedupe: MessageDedupe) {
if (!errors[err.scope]) { if (!errors[err.scope]) {
try { try {
// Dynamic import error files // Dynamic import error files
import(/* @vite-ignore */ `@/constants/errors/${err.scope}.ts`) import(`@/constants/errors/${err.scope}.ts`)
.then(error => { .then(error => {
registerError(err.scope!, error.default) registerError(err.scope!, error.default)
displayErrorMessage(err, dedupe) displayErrorMessage(err, dedupe)
}) })
.catch(() => { .catch(err => {
console.error(err)
dedupe.error($gettext(err?.message ?? 'Server error')) dedupe.error($gettext(err?.message ?? 'Server error'))
}) })
} }

View file

@ -1 +1 @@
{"version":"2.0.0-rc.6","build_id":1,"total_build":417} {"version":"2.0.0-rc.6","build_id":2,"total_build":418}

View file

@ -137,6 +137,15 @@ async function performUpgrade() {
}, 2000) }, 2000)
} }
} }
const performUpgradeBtnText = computed(() => {
if (channel.value === 'dev')
return $gettext('Install')
else if (isLatestVer.value)
return $gettext('Reinstall')
else
return $gettext('Upgrade')
})
</script> </script>
<template> <template>
@ -162,7 +171,7 @@ async function performUpgrade() {
</AModal> </AModal>
<div class="upgrade-container"> <div class="upgrade-container">
<p>{{ $gettext('You can check Nginx UI upgrade at this page.') }}</p> <p>{{ $gettext('You can check Nginx UI upgrade at this page.') }}</p>
<h3>{{ $gettext('Current Version') }}: v{{ version.version }}</h3> <h3>{{ $gettext('Current Version') }}: v{{ version.version }} <span class="short-hash">({{ data?.cur_version?.short_hash }})</span></h3>
<template v-if="getReleaseError"> <template v-if="getReleaseError">
<AAlert <AAlert
type="error" type="error"
@ -200,7 +209,7 @@ async function performUpgrade() {
</AFormItem> </AFormItem>
<template v-if="!loading"> <template v-if="!loading">
<AAlert <AAlert
v-if="isLatestVer" v-if="isLatestVer && channel !== 'dev'"
type="success" type="success"
:message="$gettext('You are using the latest version')" :message="$gettext('You are using the latest version')"
banner banner
@ -226,7 +235,7 @@ async function performUpgrade() {
ghost ghost
@click="performUpgrade" @click="performUpgrade"
> >
{{ isLatestVer ? $gettext('Reinstall') : $gettext('Upgrade') }} {{ performUpgradeBtnText }}
</AButton> </AButton>
</ASpace> </ASpace>
</div> </div>

View file

@ -9,15 +9,10 @@ import (
) )
type RuntimeInfo struct { type RuntimeInfo struct {
OS string `json:"os"` OS string `json:"os"`
Arch string `json:"arch"` Arch string `json:"arch"`
ExPath string `json:"ex_path"` ExPath string `json:"ex_path"`
} CurVersion *Info `json:"cur_version"`
type CurVersion struct {
Version string `json:"version"`
BuildID int `json:"build_id"`
TotalBuild int `json:"total_build"`
} }
func GetRuntimeInfo() (r RuntimeInfo, err error) { func GetRuntimeInfo() (r RuntimeInfo, err error) {
@ -33,9 +28,10 @@ func GetRuntimeInfo() (r RuntimeInfo, err error) {
} }
r = RuntimeInfo{ r = RuntimeInfo{
OS: runtime.GOOS, OS: runtime.GOOS,
Arch: runtime.GOARCH, Arch: runtime.GOARCH,
ExPath: realPath, ExPath: realPath,
CurVersion: GetVersionInfo(),
} }
return return

View file

@ -11,6 +11,7 @@ type Info struct {
Version string `json:"version"` Version string `json:"version"`
BuildId int `json:"build_id"` BuildId int `json:"build_id"`
TotalBuild int `json:"total_build"` TotalBuild int `json:"total_build"`
ShortHash string `json:"short_hash"`
} }
var versionInfo *Info var versionInfo *Info
@ -21,6 +22,7 @@ func GetVersionInfo() *Info {
Version: Version, Version: Version,
BuildId: BuildId, BuildId: BuildId,
TotalBuild: TotalBuild, TotalBuild: TotalBuild,
ShortHash: GetShortHash(),
} }
} }
return versionInfo return versionInfo