Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions src/plugins/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ export function setupAppVersionNotification() {

const buildTime = await getHtmlBuildTime();

// If build time hasn't changed, no update is needed
if (buildTime === BUILD_TIME) {
// If failed to get build time or build time hasn't changed, no update is needed.
if (!buildTime || buildTime === BUILD_TIME) {
return;
}

Expand Down Expand Up @@ -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 res = await fetch(`${baseUrl}index.html?time=${Date.now()}`);
try {
const res = await fetch(`${baseUrl}index.html?time=${Date.now()}`);

const html = await res.text();

const match = html.match(/<meta name="buildTime" content="(.*)">/);

const buildTime = match?.[1] || '';
if (!res.ok) {
console.error('getHtmlBuildTime error:', res.status, res.statusText);
return null;
}

return buildTime;
const html = await res.text();
const match = html.match(/<meta name="buildTime" content="(.*)">/);
return match?.[1] || null;
} catch (error) {
console.error('getHtmlBuildTime error:', error);
return null;
}
}