web/version: convert to readable

This commit is contained in:
dumbmoron 2024-07-20 12:43:14 +00:00
parent 0e60ea9582
commit c3c7a6b7ba
No known key found for this signature in database
2 changed files with 17 additions and 15 deletions

View file

@ -1,3 +1,5 @@
import { readable } from "svelte/store";
type VersionResponse = {
commit: string;
branch: string;
@ -5,19 +7,19 @@ type VersionResponse = {
version: string;
}
const fetchVersion = async function () {
const response: VersionResponse | undefined = await fetch('/version.json')
.then(r => r.json())
.catch(() => {});
if (!response) return {
const unknownVersion = {
commit: "unknown",
branch: "unknown",
remote: "unknown",
version: "unknown"
};
export const version = readable<VersionResponse>(
unknownVersion,
(set) => {
fetch('/version.json')
.then(r => r.json())
.then(set)
.catch(() => {})
}
return response;
}
export const version = await fetchVersion();
)

View file

@ -32,7 +32,7 @@
<h3>version:</h3>
<div class="message-container subtext">
{JSON.stringify(version, null, 2)}
{JSON.stringify($version, null, 2)}
</div>
</div>
{/if}