diff options
author | Ilion Beyst <ilion.beyst@gmail.com> | 2021-12-31 11:38:06 +0100 |
---|---|---|
committer | Ilion Beyst <ilion.beyst@gmail.com> | 2021-12-31 11:38:06 +0100 |
commit | 8d3b8fd8aa9603f5377f1b37963190ac2c01e9dd (patch) | |
tree | 7f4867f47702eedbb94e9723597f301e36aa0ea8 /web/pw-server/src | |
parent | 74d0189d37087188de72a70aadb0e3a22cad7917 (diff) | |
download | planetwars.dev-8d3b8fd8aa9603f5377f1b37963190ac2c01e9dd.tar.xz planetwars.dev-8d3b8fd8aa9603f5377f1b37963190ac2c01e9dd.zip |
npm run format
Diffstat (limited to 'web/pw-server/src')
-rw-r--r-- | web/pw-server/src/app.html | 20 | ||||
-rw-r--r-- | web/pw-server/src/lib/auth.ts | 6 | ||||
-rw-r--r-- | web/pw-server/src/routes/bots/[bot_id].svelte | 4 | ||||
-rw-r--r-- | web/pw-server/src/routes/bots/index.svelte | 108 | ||||
-rw-r--r-- | web/pw-server/src/routes/login.svelte | 56 | ||||
-rw-r--r-- | web/pw-server/src/routes/register.svelte | 54 |
6 files changed, 124 insertions, 124 deletions
diff --git a/web/pw-server/src/app.html b/web/pw-server/src/app.html index 9c8080f..32f9591 100644 --- a/web/pw-server/src/app.html +++ b/web/pw-server/src/app.html @@ -1,13 +1,13 @@ <!DOCTYPE html> <html lang="en"> - <head> - <meta charset="utf-8" /> - <meta name="description" content="" /> - <link rel="icon" href="/favicon.ico" /> - <meta name="viewport" content="width=device-width, initial-scale=1" /> - %svelte.head% - </head> - <body> - <div id="svelte">%svelte.body%</div> - </body> + <head> + <meta charset="utf-8" /> + <meta name="description" content="" /> + <link rel="icon" href="/favicon.ico" /> + <meta name="viewport" content="width=device-width, initial-scale=1" /> + %svelte.head% + </head> + <body> + <div id="svelte">%svelte.body%</div> + </body> </html> diff --git a/web/pw-server/src/lib/auth.ts b/web/pw-server/src/lib/auth.ts index 436ec66..3f77c58 100644 --- a/web/pw-server/src/lib/auth.ts +++ b/web/pw-server/src/lib/auth.ts @@ -1,7 +1,7 @@ export function set_session_token(token: string) { - window.localStorage.setItem('session', token); + window.localStorage.setItem("session", token); } export function get_session_token(): string | null { - return window.localStorage.getItem('session'); -}
\ No newline at end of file + return window.localStorage.getItem("session"); +} diff --git a/web/pw-server/src/routes/bots/[bot_id].svelte b/web/pw-server/src/routes/bots/[bot_id].svelte index 2556d73..955f1c6 100644 --- a/web/pw-server/src/routes/bots/[bot_id].svelte +++ b/web/pw-server/src/routes/bots/[bot_id].svelte @@ -1,6 +1,6 @@ <script lang="ts" context="module"> import { get_session_token } from "$lib/auth"; -import { mount_component } from "svelte/internal"; + import { mount_component } from "svelte/internal"; export async function load({ page }) { const token = get_session_token(); @@ -30,7 +30,7 @@ import { mount_component } from "svelte/internal"; <script lang="ts"> import dayjs from "dayjs"; - + export let bot: object; export let bundles: object[]; diff --git a/web/pw-server/src/routes/bots/index.svelte b/web/pw-server/src/routes/bots/index.svelte index 775652b..9186271 100644 --- a/web/pw-server/src/routes/bots/index.svelte +++ b/web/pw-server/src/routes/bots/index.svelte @@ -1,71 +1,71 @@ <script lang="ts" context="module"> - import { get_session_token } from '$lib/auth'; + import { get_session_token } from "$lib/auth"; - /** @type {import('@sveltejs/kit').Load} */ - export async function load({ params, fetch, session, stuff }) { - const token = get_session_token(); - const res = await fetch('/api/bots/my_bots', { - headers: { - 'Content-Type': 'application/json', - Authorization: `Bearer ${token}` - } - }); + /** @type {import('@sveltejs/kit').Load} */ + export async function load({ params, fetch, session, stuff }) { + const token = get_session_token(); + const res = await fetch("/api/bots/my_bots", { + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${token}`, + }, + }); - if (res.ok) { - return { - props: { - bots: await res.json() - } - }; - } + if (res.ok) { + return { + props: { + bots: await res.json(), + }, + }; + } - return { - status: res.status, - error: new Error('Could not load bots') - }; - } + return { + status: res.status, + error: new Error("Could not load bots"), + }; + } </script> <script lang="ts"> - import { goto } from '$app/navigation'; + import { goto } from "$app/navigation"; - export let bots: object[]; - let name: string | undefined; + export let bots: object[]; + let name: string | undefined; - async function createBot() { - const token = get_session_token(); - const res = await fetch('/api/bots', { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - Authorization: `Bearer ${token}` - }, - body: JSON.stringify({ - name: name - }) - }); + async function createBot() { + const token = get_session_token(); + const res = await fetch("/api/bots", { + method: "POST", + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${token}`, + }, + body: JSON.stringify({ + name: name, + }), + }); - if (res.ok) { - let bot = await res.json(); - goto(`/bots/${bot['id']}`); - } else { - new Error('creation failed'); - } - } + if (res.ok) { + let bot = await res.json(); + goto(`/bots/${bot["id"]}`); + } else { + new Error("creation failed"); + } + } </script> <form on:submit|preventDefault={createBot}> - <label for="name">Name</label> - <input name="name" bind:value={name}/> - <button type="submit">Create</button> + <label for="name">Name</label> + <input name="name" bind:value={name} /> + <button type="submit">Create</button> </form> <ul> - {#each bots as bot} - <li> - <a target="_blank" href={`bots/${bot['id']}`}> - {bot['name']} - </a> - </li> - {/each} + {#each bots as bot} + <li> + <a target="_blank" href={`bots/${bot["id"]}`}> + {bot["name"]} + </a> + </li> + {/each} </ul> diff --git a/web/pw-server/src/routes/login.svelte b/web/pw-server/src/routes/login.svelte index 197238e..09b1834 100644 --- a/web/pw-server/src/routes/login.svelte +++ b/web/pw-server/src/routes/login.svelte @@ -1,46 +1,46 @@ <script lang="ts"> - import { get_session_token, set_session_token } from '$lib/auth'; - import { goto } from '$app/navigation'; + import { get_session_token, set_session_token } from "$lib/auth"; + import { goto } from "$app/navigation"; - let username: string | undefined; - let password: string | undefined; + let username: string | undefined; + let password: string | undefined; - const onSubmit = () => { - fetch('/api/login', { - method: 'POST', - headers: { - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ - username, - password - }) - }) - .then((response) => { + const onSubmit = () => { + fetch("/api/login", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + username, + password, + }), + }) + .then((response) => { if (!response.ok) { throw Error(response.statusText); } return response.text(); }) - .then((token) => { - set_session_token(token); - goto("/") - }); - }; + .then((token) => { + set_session_token(token); + goto("/"); + }); + }; function loggedIn(): boolean { - return get_session_token() != null + return get_session_token() != null; } </script> {#if loggedIn()} - you are logged in + you are logged in {/if} <form on:submit|preventDefault={onSubmit}> - <label for="username">Username</label> - <input name="username" bind:value={username} /> - <label for="password">Password</label> - <input type="password" name="password" bind:value={password} /> - <button type="submit">Log in</button> + <label for="username">Username</label> + <input name="username" bind:value={username} /> + <label for="password">Password</label> + <input type="password" name="password" bind:value={password} /> + <button type="submit">Log in</button> </form> diff --git a/web/pw-server/src/routes/register.svelte b/web/pw-server/src/routes/register.svelte index a21cf65..6344399 100644 --- a/web/pw-server/src/routes/register.svelte +++ b/web/pw-server/src/routes/register.svelte @@ -1,38 +1,38 @@ <script lang="ts"> - let username: string | undefined; - let password: string | undefined; + let username: string | undefined; + let password: string | undefined; - const onSubmit = () => { - if (username === undefined || username.trim() === '') { - return; - } + const onSubmit = () => { + if (username === undefined || username.trim() === "") { + return; + } - if (password === undefined || password.trim() === '') { + if (password === undefined || password.trim() === "") { return; } - fetch('/api/register', { - method: 'POST', - headers: { - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ - username, - password - }) - }) - .then((resp) => resp.json()) - .then((data) => { - console.log(data); - }); - }; + fetch("/api/register", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + username, + password, + }), + }) + .then((resp) => resp.json()) + .then((data) => { + console.log(data); + }); + }; </script> <h1>Register</h1> <form on:submit|preventDefault={onSubmit}> - <label for="username">Username</label> - <input name="username" bind:value={username} /> - <label for="password">Password</label> - <input type="password" name="password" bind:value={password} /> - <button type="submit">Register</button> + <label for="username">Username</label> + <input name="username" bind:value={username} /> + <label for="password">Password</label> + <input type="password" name="password" bind:value={password} /> + <button type="submit">Register</button> </form> |