optimize(hooks): update detection function to cover the exceptions that occur when the request fails.
This commit is contained in:
parent
75455b006c
commit
222187d3b0
@ -25,8 +25,8 @@ export function setupAppVersionNotification() {
|
|||||||
|
|
||||||
const buildTime = await getHtmlBuildTime();
|
const buildTime = await getHtmlBuildTime();
|
||||||
|
|
||||||
// If build time hasn't changed, no update is needed
|
// If failed to get build time or build time hasn't changed, no update is needed.
|
||||||
if (buildTime === BUILD_TIME) {
|
if (!buildTime || buildTime === BUILD_TIME) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,16 +88,22 @@ export function setupAppVersionNotification() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getHtmlBuildTime() {
|
async function getHtmlBuildTime(): Promise<string | null> {
|
||||||
const baseUrl = import.meta.env.VITE_BASE_URL || '/';
|
const baseUrl = import.meta.env.VITE_BASE_URL || '/';
|
||||||
|
|
||||||
|
try {
|
||||||
const res = await fetch(`${baseUrl}index.html?time=${Date.now()}`);
|
const res = await fetch(`${baseUrl}index.html?time=${Date.now()}`);
|
||||||
|
|
||||||
|
if (!res.ok) {
|
||||||
|
console.error('getHtmlBuildTime error:', res.status, res.statusText);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
const html = await res.text();
|
const html = await res.text();
|
||||||
|
|
||||||
const match = html.match(/<meta name="buildTime" content="(.*)">/);
|
const match = html.match(/<meta name="buildTime" content="(.*)">/);
|
||||||
|
return match?.[1] || null;
|
||||||
const buildTime = match?.[1] || '';
|
} catch (error) {
|
||||||
|
console.error('getHtmlBuildTime error:', error);
|
||||||
return buildTime;
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user