mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-18 00:34:28 +08:00
add refresh browser cache when client version not match server version
This commit is contained in:
@@ -5,6 +5,9 @@ import type { ApiResponse } from '@/core/api.ts';
|
||||
import type {
|
||||
ApplicationCloudSetting
|
||||
} from '@/core/setting.ts';
|
||||
import type {
|
||||
VersionInfo
|
||||
} from '@/core/version.ts';
|
||||
import {
|
||||
TransactionType
|
||||
} from '@/core/transaction.ts';
|
||||
@@ -599,6 +602,9 @@ export default {
|
||||
deleteUserCustomExchangeRate: (req: UserCustomExchangeRateDeleteRequest): ApiResponsePromise<boolean> => {
|
||||
return axios.post<ApiResponse<boolean>>('v1/exchange_rates/user_custom/delete.json', req);
|
||||
},
|
||||
getServerVersion: (): ApiResponsePromise<VersionInfo> => {
|
||||
return axios.get<ApiResponse<VersionInfo>>('v1/systems/version.json');
|
||||
},
|
||||
generateQrCodeUrl: (qrCodeName: string): string => {
|
||||
return `${getBasePath()}${BASE_QRCODE_PATH}/${qrCodeName}.png`;
|
||||
},
|
||||
|
||||
@@ -135,3 +135,39 @@ export function startDownloadFile(fileName: string, fileData: Blob): void {
|
||||
|
||||
dataLink.click();
|
||||
}
|
||||
|
||||
export function clearBrowserCaches(): Promise<void> {
|
||||
if (!window.caches) {
|
||||
logger.error('caches API is not supported in this browser');
|
||||
return Promise.reject();
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
window.caches.keys().then(cacheNames => {
|
||||
const promises = [];
|
||||
|
||||
for (let i = 0; i < cacheNames.length; i++) {
|
||||
const cacheName = cacheNames[i];
|
||||
promises.push(window.caches.delete(cacheName).then(success => {
|
||||
if (success) {
|
||||
logger.info(`cache "${cacheName}" cleared successfully`);
|
||||
return Promise.resolve(cacheName);
|
||||
} else {
|
||||
logger.warn(`failed to clear cache "${cacheName}"`);
|
||||
return Promise.reject(cacheName);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
Promise.all(promises).then(() => {
|
||||
logger.info("all caches cleared successfully");
|
||||
resolve();
|
||||
}).catch(() => {
|
||||
resolve();
|
||||
});
|
||||
}).catch(error => {
|
||||
logger.warn("failed to clear cache", error);
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
+27
-9
@@ -1,13 +1,17 @@
|
||||
import type { VersionInfo } from '@/core/version.ts';
|
||||
|
||||
import { getBasePath } from './web.ts';
|
||||
|
||||
export function isProduction(): boolean {
|
||||
return __EZBOOKKEEPING_IS_PRODUCTION__;
|
||||
}
|
||||
const clientVersionHolder: VersionInfo = {
|
||||
version: __EZBOOKKEEPING_VERSION__,
|
||||
commitHash: __EZBOOKKEEPING_BUILD_COMMIT_HASH__,
|
||||
buildTime: __EZBOOKKEEPING_BUILD_UNIX_TIME__
|
||||
};
|
||||
|
||||
export function getVersion(): string {
|
||||
const isRelease = !getBuildTime();
|
||||
const commitHash = __EZBOOKKEEPING_BUILD_COMMIT_HASH__;
|
||||
let version = __EZBOOKKEEPING_VERSION__;
|
||||
export function formatDisplayVersion(versionInfo: VersionInfo): string {
|
||||
const isRelease = !versionInfo.buildTime;
|
||||
const commitHash = versionInfo.commitHash;
|
||||
let version = versionInfo.version;
|
||||
|
||||
if (version && (!isRelease || !isProduction())) {
|
||||
version += '-dev';
|
||||
@@ -15,6 +19,8 @@ export function getVersion(): string {
|
||||
|
||||
if (!version) {
|
||||
version = 'unknown';
|
||||
} else {
|
||||
version = 'v' + version;
|
||||
}
|
||||
|
||||
if (commitHash) {
|
||||
@@ -24,8 +30,20 @@ export function getVersion(): string {
|
||||
return version;
|
||||
}
|
||||
|
||||
export function getBuildTime(): string {
|
||||
return __EZBOOKKEEPING_BUILD_UNIX_TIME__;
|
||||
export function isProduction(): boolean {
|
||||
return __EZBOOKKEEPING_IS_PRODUCTION__;
|
||||
}
|
||||
|
||||
export function getClientVersionInfo(): VersionInfo {
|
||||
return clientVersionHolder;
|
||||
}
|
||||
|
||||
export function getClientDisplayVersion(): string {
|
||||
return formatDisplayVersion(clientVersionHolder);
|
||||
}
|
||||
|
||||
export function getClientBuildTime(): string {
|
||||
return clientVersionHolder.buildTime || '';
|
||||
}
|
||||
|
||||
export function getMobileVersionPath(): string {
|
||||
|
||||
Reference in New Issue
Block a user