@@ -38,17 +38,35 @@ const SYSTEM_REQ = [
3838
3939export function DownloadCta ( ) {
4040 const [ latest , setLatest ] = useState < LatestInfo | null > ( null ) ;
41+ const [ loading , setLoading ] = useState ( true ) ;
4142
4243 useEffect ( ( ) => {
4344 const controller = new AbortController ( ) ;
44- fetch ( `${ DOWNLOAD_BASE } /latest.json` , { signal : controller . signal , cache : "no-store" } )
45- . then ( ( res ) => ( res . ok ? res . json ( ) : Promise . reject ( new Error ( `HTTP ${ res . status } ` ) ) ) )
46- . then ( ( data : LatestInfo ) => {
47- if ( data ?. version && data ?. fileName ) setLatest ( data ) ;
45+ // WEB-L1: 5s 超时 + 单次重试——原实现无超时控制,CDN 域名解析挂起时
46+ // (DNS 可达 30s+)下载按钮一直显示兑底值,用户无法区分"加载中"与"源站故障"
47+ const fetchWithTimeout = ( ctrl : AbortController , timeoutMs = 5000 ) => {
48+ const timer = setTimeout ( ( ) => ctrl . abort ( ) , timeoutMs ) ;
49+ const promise = fetch ( `${ DOWNLOAD_BASE } /latest.json` , { signal : ctrl . signal , cache : "no-store" } )
50+ . then ( ( res ) => ( res . ok ? res . json ( ) : Promise . reject ( new Error ( `HTTP ${ res . status } ` ) ) ) )
51+ . then ( ( data : LatestInfo ) => {
52+ if ( data ?. version && data ?. fileName ) setLatest ( data ) ;
53+ } ) ;
54+ promise . finally ( ( ) => clearTimeout ( timer ) ) ;
55+ return promise ;
56+ } ;
57+
58+ fetchWithTimeout ( controller )
59+ . catch ( ( ) => {
60+ // 源站不可达:单次重试后再放弃(回退 GitHub,不打扰用户)
61+ if ( controller . signal . aborted ) {
62+ // 超时中止:新建 controller 重试一次
63+ return fetchWithTimeout ( new AbortController ( ) ) ;
64+ }
4865 } )
4966 . catch ( ( ) => {
50- /* 服务器源不可达:保持 GitHub 回退,不打扰用户 */
51- } ) ;
67+ /* 重试仍失败:保持 GitHub 回退 */
68+ } )
69+ . finally ( ( ) => setLoading ( false ) ) ;
5270 return ( ) => controller . abort ( ) ;
5371 } , [ ] ) ;
5472
@@ -78,7 +96,9 @@ export function DownloadCta() {
7896 </ span >
7997 < div className = "text-left" >
8098 < h2 className = "font-serif text-xl font-bold text-kb-text" > 熵减 Entropydecrease</ h2 >
81- < p className = "text-xs text-kb-text3" > v{ version } 正式版 · { date } </ p >
99+ < p className = "text-xs text-kb-text3" >
100+ { loading ? "正在获取最新版本信息…" : `v${ version } 正式版 · ${ date } ` }
101+ </ p >
82102 </ div >
83103 </ div >
84104
0 commit comments