StaffLDB-Minify #1
@ -1,14 +1,39 @@
|
||||
<script lang="ts">
|
||||
|
||||
const fetchUrl = "https://testing.owlboard.info";
|
||||
import { uuid } from "$lib/stores/uuid";
|
||||
import { getApiUrl } from "$lib/scripts/upstream";
|
||||
import type { ApiResponse, StaffLdb } from "@owlboard/ts-types";
|
||||
|
||||
export let station: string
|
||||
export let title: string | undefined = "Loading..."
|
||||
|
||||
const fetchUrl = getApiUrl();
|
||||
|
||||
async function fetchStaffLdb(station: string) {
|
||||
const url = `${fetchUrl}/api/v2/live/station/${station}/staff`
|
||||
const res = await fetch(url)
|
||||
const options = {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
uuid: $uuid,
|
||||
},
|
||||
}
|
||||
const res = await fetch(url, options)
|
||||
let jsonData: ApiResponse<StaffLdb>
|
||||
if (res.status === 200) {
|
||||
return await res.json()
|
||||
jsonData = await res.json()
|
||||
title = jsonData.data?.locationName
|
||||
} else if (res.status === 401) {
|
||||
console.log(`Request Status: ${res.status}`)
|
||||
title = "Unauthorised"
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
{#await fetchStaffLdb(station)}
|
||||
Loading
|
||||
{:then data}
|
||||
Loaded {JSON.stringify(data)}
|
||||
{:catch}
|
||||
Error Loading
|
||||
{/await}
|
||||
|
9
src/lib/scripts/upstream.ts
Normal file
9
src/lib/scripts/upstream.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import { dev } from "$app/environment";
|
||||
|
||||
export function getApiUrl() {
|
||||
if (dev) {
|
||||
console.info("DEVMODE active, using testing URL")
|
||||
return "https://testing.owlboard.info"
|
||||
}
|
||||
return "https://owlboard.info"
|
||||
}
|
Loading…
Reference in New Issue
Block a user