2023-10-08 22:38:42 +00:00
|
|
|
<script>
|
2023-11-19 00:47:12 +00:00
|
|
|
import { onMount, tick } from 'svelte';
|
|
|
|
import { config, user } from '$lib/stores';
|
|
|
|
import { goto } from '$app/navigation';
|
|
|
|
import { WEBUI_API_BASE_URL } from '$lib/constants';
|
|
|
|
import toast, { Toaster } from 'svelte-french-toast';
|
2023-10-08 22:38:42 +00:00
|
|
|
|
|
|
|
import '../app.css';
|
|
|
|
import '../tailwind.css';
|
2023-12-14 22:24:56 +00:00
|
|
|
import 'tippy.js/dist/tippy.css';
|
2023-11-19 00:47:12 +00:00
|
|
|
let loaded = false;
|
|
|
|
|
|
|
|
onMount(async () => {
|
2023-12-26 06:14:06 +00:00
|
|
|
// Check Backend Status
|
|
|
|
const res = await fetch(`${WEBUI_API_BASE_URL}/`, {
|
2023-11-19 00:47:12 +00:00
|
|
|
method: 'GET',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.then(async (res) => {
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
return res.json();
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
console.log(error);
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
2023-12-26 06:14:06 +00:00
|
|
|
if (res) {
|
|
|
|
await config.set(res);
|
|
|
|
console.log(res);
|
2023-11-19 00:47:12 +00:00
|
|
|
|
2023-12-26 06:14:06 +00:00
|
|
|
if ($config) {
|
2023-11-19 00:47:12 +00:00
|
|
|
if (localStorage.token) {
|
2023-12-26 06:14:06 +00:00
|
|
|
// Get Session User Info
|
|
|
|
const sessionUser = await fetch(`${WEBUI_API_BASE_URL}/auths`, {
|
2023-11-19 00:47:12 +00:00
|
|
|
method: 'GET',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
Authorization: `Bearer ${localStorage.token}`
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.then(async (res) => {
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
return res.json();
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
console.log(error);
|
|
|
|
toast.error(error.detail);
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
2023-12-26 06:14:06 +00:00
|
|
|
if (sessionUser) {
|
|
|
|
await user.set(sessionUser);
|
2023-11-19 05:41:43 +00:00
|
|
|
} else {
|
|
|
|
localStorage.removeItem('token');
|
|
|
|
await goto('/auth');
|
|
|
|
}
|
2023-11-19 00:47:12 +00:00
|
|
|
} else {
|
2023-11-19 05:41:43 +00:00
|
|
|
await goto('/auth');
|
2023-11-19 00:47:12 +00:00
|
|
|
}
|
|
|
|
}
|
2023-12-26 06:14:06 +00:00
|
|
|
} else {
|
|
|
|
await goto(`/error`);
|
2023-11-19 00:47:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
await tick();
|
|
|
|
loaded = true;
|
|
|
|
});
|
2023-10-08 22:38:42 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<svelte:head>
|
|
|
|
<title>Ollama</title>
|
|
|
|
</svelte:head>
|
2023-11-19 00:47:12 +00:00
|
|
|
|
2023-12-26 06:14:06 +00:00
|
|
|
{#if loaded}
|
2023-11-19 00:47:12 +00:00
|
|
|
<slot />
|
|
|
|
{/if}
|
2023-12-26 06:14:06 +00:00
|
|
|
|
|
|
|
<Toaster />
|