@@ -9,13 +9,16 @@ import {
9
9
LogoutOutlined ,
10
10
SettingOutlined ,
11
11
DatabaseOutlined ,
12
+ GithubOutlined ,
12
13
} from "@ant-design/icons" ;
13
14
import { message } from "antd" ;
14
15
import DatabaseBackup from "./DatabaseBackup" ;
16
+ import { APP_VERSION } from "@/lib/version" ;
15
17
16
18
export default function Header ( ) {
17
19
const [ apiKey , setApiKey ] = useState ( "加载中..." ) ;
18
20
const [ isBackupModalOpen , setIsBackupModalOpen ] = useState ( false ) ;
21
+ const [ isCheckingUpdate , setIsCheckingUpdate ] = useState ( false ) ;
19
22
20
23
useEffect ( ( ) => {
21
24
const token = document . cookie
@@ -51,6 +54,75 @@ export default function Header() {
51
54
window . location . href = "/token" ;
52
55
} ;
53
56
57
+ const checkUpdate = async ( ) => {
58
+ setIsCheckingUpdate ( true ) ;
59
+ try {
60
+ const response = await fetch (
61
+ "https://api.github.com/repos/variantconst/openwebui-monitor/releases/latest"
62
+ ) ;
63
+ const data = await response . json ( ) ;
64
+ const latestVersion = data . tag_name ;
65
+
66
+ if ( ! latestVersion ) {
67
+ throw new Error ( "获取版本号失败" ) ;
68
+ }
69
+
70
+ const currentVer = APP_VERSION . replace ( / ^ v / , "" ) ;
71
+ const latestVer = latestVersion . replace ( / ^ v / , "" ) ;
72
+
73
+ if ( currentVer === latestVer ) {
74
+ message . success ( `当前已是最新版本 v${ APP_VERSION } ` ) ;
75
+ } else {
76
+ Modal . confirm ( {
77
+ icon : null ,
78
+ title : (
79
+ < div className = "flex items-center gap-3 mb-4" >
80
+ < div className = "flex items-center justify-center w-10 h-10 rounded-full bg-blue-50" >
81
+ < GithubOutlined className = "text-lg text-blue-500" />
82
+ </ div >
83
+ < div className = "flex flex-col" >
84
+ < div className = "text-lg font-medium text-gray-800" >
85
+ 发现新版本
86
+ </ div >
87
+ </ div >
88
+ </ div >
89
+ ) ,
90
+ content : (
91
+ < div className = "flex flex-col gap-4 py-2" >
92
+ < div className = "flex justify-between items-center" >
93
+ < span className = "text-gray-500" > 当前版本</ span >
94
+ < span className = "font-mono text-gray-800" > v{ APP_VERSION } </ span >
95
+ </ div >
96
+ < div className = "flex justify-between items-center" >
97
+ < span className = "text-gray-500" > 最新版本</ span >
98
+ < span className = "font-mono text-blue-600" > { latestVersion } </ span >
99
+ </ div >
100
+ </ div >
101
+ ) ,
102
+ centered : true ,
103
+ width : 400 ,
104
+ okText : "前往更新" ,
105
+ cancelText : "暂不更新" ,
106
+ className : "update-modal" ,
107
+ okButtonProps : {
108
+ className : "bg-blue-500 hover:bg-blue-600" ,
109
+ } ,
110
+ onOk : ( ) => {
111
+ window . open (
112
+ "https://github.com/VariantConst/OpenWebUI-Monitor/releases/latest" ,
113
+ "_blank"
114
+ ) ;
115
+ } ,
116
+ } ) ;
117
+ }
118
+ } catch ( error ) {
119
+ message . error ( "检查更新失败" ) ;
120
+ console . error ( "检查更新失败:" , error ) ;
121
+ } finally {
122
+ setIsCheckingUpdate ( false ) ;
123
+ }
124
+ } ;
125
+
54
126
const items : MenuProps [ "items" ] = [
55
127
{
56
128
key : "1" ,
@@ -78,6 +150,18 @@ export default function Header() {
78
150
} ,
79
151
{
80
152
key : "3" ,
153
+ label : (
154
+ < div
155
+ className = "flex items-center gap-2 px-2 py-1.5 text-gray-600 hover:text-gray-900"
156
+ onClick = { checkUpdate }
157
+ >
158
+ < GithubOutlined className = "text-base" spin = { isCheckingUpdate } />
159
+ < span > 检查更新</ span >
160
+ </ div >
161
+ ) ,
162
+ } ,
163
+ {
164
+ key : "4" ,
81
165
label : (
82
166
< div
83
167
className = "flex items-center gap-2 px-2 py-1.5 text-gray-600 hover:text-red-500"
0 commit comments