+
Source code
+
+ UI ver: {uiVersion} | Agent ver: {apiVersion.replace(/;$/, '')}
+
diff --git a/src/lib/functions/api/fetchversion.js b/src/lib/functions/api/fetchversion.js
new file mode 100644
index 00000000..a809b8ea
--- /dev/null
+++ b/src/lib/functions/api/fetchversion.js
@@ -0,0 +1,37 @@
+import { error } from '@sveltejs/kit';
+import { createApiUrl } from '$lib/functions/api/createurl.js';
+
+/**
+ * @param {typeof fetch} [fetcher]
+ * @returns {Promise
}
+ */
+export async function fetchVersion(fetcher = fetch) {
+ /** @type {URL} */
+ let apiUrl;
+ try {
+ apiUrl = createApiUrl('versionz');
+ } catch (/** @type {any} */ err) {
+ // Internal Server Error
+ throw error(500, `Failed to create API URL: ${err.message}`);
+ }
+
+ /** @type {Response} */
+ let response;
+ try {
+ response = await fetcher(apiUrl, {
+ method: 'GET', // POST doesn't cache on CDN
+ headers: {
+ Accept: 'text/plain',
+ 'Accept-Encoding': 'gzip, deflate, br'
+ }
+ });
+ } catch (/** @type {any} */ err) {
+ // Bad Gateway
+ throw error(502, `Failed to fetch version: ${err.message}`);
+ }
+
+ /** @type {string} */
+ const version = await response.text();
+
+ return version;
+}
diff --git a/src/routes/+layout.js b/src/routes/+layout.js
new file mode 100644
index 00000000..431aeaec
--- /dev/null
+++ b/src/routes/+layout.js
@@ -0,0 +1,11 @@
+import { PUBLIC_UI_VERSION } from '$env/static/public';
+import { fetchVersion } from '$lib/functions/api/fetchversion';
+
+/** @type {import('./$types').LayoutLoad} */
+export async function load({ fetch }) {
+ const apiVersion = await fetchVersion(fetch);
+ return {
+ uiVersion: PUBLIC_UI_VERSION ?? 'dev',
+ apiVersion: apiVersion
+ };
+}
diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte
index ae311a17..256c46dc 100644
--- a/src/routes/+layout.svelte
+++ b/src/routes/+layout.svelte
@@ -3,6 +3,10 @@
import Preconnect from '$lib/components/preconnect/main.svelte';
import ThemeToggle from '$lib/components/themetoggle/main.svelte';
import Footer from '$lib/components/footer/main.svelte';
+
+ let { data } = $props();
+ const uiVersion = $derived(data.uiVersion);
+ const apiVersion = $derived(data.apiVersion);
@@ -15,4 +19,4 @@
-
+
diff --git a/src/routes/search/+page.js b/src/routes/search/+page.js
index ab16d396..1aa44d69 100644
--- a/src/routes/search/+page.js
+++ b/src/routes/search/+page.js
@@ -77,7 +77,6 @@ export async function load({ url, fetch }) {
return {
browser: browser,
- apiVersion: resp.version,
query: queryWithoutCategory,
currentPage: currentPage,
maxPages: maxPages,
diff --git a/src/routes/search/+page.svelte b/src/routes/search/+page.svelte
index 9921b24d..97ce6de9 100644
--- a/src/routes/search/+page.svelte
+++ b/src/routes/search/+page.svelte
@@ -9,7 +9,6 @@
let { data } = $props();
const javascript = $derived(data.browser);
-
const query = $derived(data.query);
const title = $derived(
query === ''
@@ -18,7 +17,6 @@
? `${query} | Hearchco Search`
: `${query.slice(0, 15)}... | Hearchco Search`
);
-
const currentPage = $derived(data.currentPage);
// const maxPages = $derived(data.maxPages);
const category = $derived(data.category);