Skip to content

Commit

Permalink
Merge pull request #318 from hearchco/as/feat/version
Browse files Browse the repository at this point in the history
feat: versions
  • Loading branch information
aleksasiriski authored Jun 20, 2024
2 parents cd77b65 + 24e8fb1 commit 146ae69
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 5 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
PUBLIC_UI_VERSION=dev
PUBLIC_URI=http://localhost:5173
# use local frontend with local backend
API_URI=http://localhost:3030 # server reachable
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/dockercicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ jobs:
permissions:
contents: read
packages: write
env:
PUBLIC_UI_VERSION: ${{ github.ref }}

steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/testingci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ jobs:
runs-on: ubuntu-latest
permissions:
contents: read
env:
PUBLIC_UI_VERSION: ${{ github.sha }}

steps:
- uses: actions/checkout@v4
Expand Down
16 changes: 15 additions & 1 deletion src/lib/components/footer/main.svelte
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
<script>
/**
* @typedef {object} Props
* @property {string} uiVersion
* @property {string} apiVersion
*/
/** @type {Props} */
let { uiVersion, apiVersion } = $props();
</script>

<footer class="h-[10lvh] w-full border-t-2 border-neutral-100 dark:border-neutral-700">
<div class="h-full flex place-content-center items-center">
<div class="h-full flex flex-col place-content-center items-center">
<a
class="text-hearchco-primary dark:text-hearchco-secondary font-bold hover:underline"
href="https://github.com/hearchco"
>
Source code
</a>
<p class="text-sm text-neutral-600 dark:text-neutral-300 font-light">
UI ver: {uiVersion} | Agent ver: {apiVersion.replace(/;$/, '')}
</p>
</div>
</footer>
37 changes: 37 additions & 0 deletions src/lib/functions/api/fetchversion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { error } from '@sveltejs/kit';
import { createApiUrl } from '$lib/functions/api/createurl.js';

/**
* @param {typeof fetch} [fetcher]
* @returns {Promise<string>}
*/
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;
}
11 changes: 11 additions & 0 deletions src/routes/+layout.js
Original file line number Diff line number Diff line change
@@ -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
};
}
6 changes: 5 additions & 1 deletion src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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);
</script>

<Preconnect />
Expand All @@ -15,4 +19,4 @@
<slot />
</main>

<Footer />
<Footer {uiVersion} {apiVersion} />
1 change: 0 additions & 1 deletion src/routes/search/+page.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ export async function load({ url, fetch }) {

return {
browser: browser,
apiVersion: resp.version,
query: queryWithoutCategory,
currentPage: currentPage,
maxPages: maxPages,
Expand Down
2 changes: 0 additions & 2 deletions src/routes/search/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
let { data } = $props();
const javascript = $derived(data.browser);
const query = $derived(data.query);
const title = $derived(
query === ''
Expand All @@ -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);
Expand Down

0 comments on commit 146ae69

Please sign in to comment.