diff --git a/frontend/src/lib/types/application-configuration.ts b/frontend/src/lib/types/application-configuration.ts index ec4edd6..af5e59e 100644 --- a/frontend/src/lib/types/application-configuration.ts +++ b/frontend/src/lib/types/application-configuration.ts @@ -16,3 +16,9 @@ export type AppConfigRawResponse = { type: string; value: string; }[]; + +export type AppVersionInformation = { + isUpToDate: boolean; + newestVersion: string; + currentVersion: string; +}; \ No newline at end of file diff --git a/frontend/src/routes/settings/+layout.server.ts b/frontend/src/routes/settings/+layout.server.ts new file mode 100644 index 0000000..2203fdc --- /dev/null +++ b/frontend/src/routes/settings/+layout.server.ts @@ -0,0 +1,24 @@ +import AppConfigService from '$lib/services/app-config-service'; +import type { AppVersionInformation } from '$lib/types/application-configuration'; +import type { LayoutServerLoad } from './$types'; + +let versionInformation: AppVersionInformation; +let versionInformationLastUpdated: number; + +export const load: LayoutServerLoad = async () => { + const appConfigService = new AppConfigService(); + + // Cache the version information for 3 hours + const cacheExpired = + versionInformationLastUpdated && + Date.now() - versionInformationLastUpdated > 1000 * 60 * 60 * 3; + + if (!versionInformation || cacheExpired) { + versionInformation = await appConfigService.getVersionInformation(); + versionInformationLastUpdated = Date.now(); + } + + return { + versionInformation + }; +}; diff --git a/frontend/src/routes/settings/+layout.ts b/frontend/src/routes/settings/+layout.ts deleted file mode 100644 index 0cd6c6d..0000000 --- a/frontend/src/routes/settings/+layout.ts +++ /dev/null @@ -1,11 +0,0 @@ -import AppConfigService from '$lib/services/app-config-service'; -import type { LayoutLoad } from './$types'; - -export const load: LayoutLoad = async () => { - const appConfigService = new AppConfigService(); - - const versionInformation = await appConfigService.getVersionInformation(); - return { - versionInformation - }; -};