npm run format

This commit is contained in:
Ilion Beyst 2021-12-31 11:38:06 +01:00
parent 74d0189d37
commit 8d3b8fd8aa
10 changed files with 207 additions and 210 deletions

View file

@ -1,20 +1,20 @@
module.exports = { module.exports = {
root: true, root: true,
parser: '@typescript-eslint/parser', parser: "@typescript-eslint/parser",
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'prettier'], extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended", "prettier"],
plugins: ['svelte3', '@typescript-eslint'], plugins: ["svelte3", "@typescript-eslint"],
ignorePatterns: ['*.cjs'], ignorePatterns: ["*.cjs"],
overrides: [{ files: ['*.svelte'], processor: 'svelte3/svelte3' }], overrides: [{ files: ["*.svelte"], processor: "svelte3/svelte3" }],
settings: { settings: {
'svelte3/typescript': () => require('typescript') "svelte3/typescript": () => require("typescript"),
}, },
parserOptions: { parserOptions: {
sourceType: 'module', sourceType: "module",
ecmaVersion: 2020 ecmaVersion: 2020,
}, },
env: { env: {
browser: true, browser: true,
es2017: true, es2017: true,
node: true node: true,
} },
}; };

View file

@ -1,7 +1,7 @@
export function set_session_token(token: string) { export function set_session_token(token: string) {
window.localStorage.setItem('session', token); window.localStorage.setItem("session", token);
} }
export function get_session_token(): string | null { export function get_session_token(): string | null {
return window.localStorage.getItem('session'); return window.localStorage.getItem("session");
} }

View file

@ -1,55 +1,55 @@
<script lang="ts" context="module"> <script lang="ts" context="module">
import { get_session_token } from '$lib/auth'; import { get_session_token } from "$lib/auth";
/** @type {import('@sveltejs/kit').Load} */ /** @type {import('@sveltejs/kit').Load} */
export async function load({ params, fetch, session, stuff }) { export async function load({ params, fetch, session, stuff }) {
const token = get_session_token(); const token = get_session_token();
const res = await fetch('/api/bots/my_bots', { const res = await fetch("/api/bots/my_bots", {
headers: { headers: {
'Content-Type': 'application/json', "Content-Type": "application/json",
Authorization: `Bearer ${token}` Authorization: `Bearer ${token}`,
} },
}); });
if (res.ok) { if (res.ok) {
return { return {
props: { props: {
bots: await res.json() bots: await res.json(),
} },
}; };
} }
return { return {
status: res.status, status: res.status,
error: new Error('Could not load bots') error: new Error("Could not load bots"),
}; };
} }
</script> </script>
<script lang="ts"> <script lang="ts">
import { goto } from '$app/navigation'; import { goto } from "$app/navigation";
export let bots: object[]; export let bots: object[];
let name: string | undefined; let name: string | undefined;
async function createBot() { async function createBot() {
const token = get_session_token(); const token = get_session_token();
const res = await fetch('/api/bots', { const res = await fetch("/api/bots", {
method: 'POST', method: "POST",
headers: { headers: {
'Content-Type': 'application/json', "Content-Type": "application/json",
Authorization: `Bearer ${token}` Authorization: `Bearer ${token}`,
}, },
body: JSON.stringify({ body: JSON.stringify({
name: name name: name,
}) }),
}); });
if (res.ok) { if (res.ok) {
let bot = await res.json(); let bot = await res.json();
goto(`/bots/${bot['id']}`); goto(`/bots/${bot["id"]}`);
} else { } else {
new Error('creation failed'); new Error("creation failed");
} }
} }
</script> </script>
@ -63,8 +63,8 @@
<ul> <ul>
{#each bots as bot} {#each bots as bot}
<li> <li>
<a target="_blank" href={`bots/${bot['id']}`}> <a target="_blank" href={`bots/${bot["id"]}`}>
{bot['name']} {bot["name"]}
</a> </a>
</li> </li>
{/each} {/each}

View file

@ -1,20 +1,20 @@
<script lang="ts"> <script lang="ts">
import { get_session_token, set_session_token } from '$lib/auth'; import { get_session_token, set_session_token } from "$lib/auth";
import { goto } from '$app/navigation'; import { goto } from "$app/navigation";
let username: string | undefined; let username: string | undefined;
let password: string | undefined; let password: string | undefined;
const onSubmit = () => { const onSubmit = () => {
fetch('/api/login', { fetch("/api/login", {
method: 'POST', method: "POST",
headers: { headers: {
'Content-Type': 'application/json' "Content-Type": "application/json",
}, },
body: JSON.stringify({ body: JSON.stringify({
username, username,
password password,
}) }),
}) })
.then((response) => { .then((response) => {
if (!response.ok) { if (!response.ok) {
@ -24,12 +24,12 @@
}) })
.then((token) => { .then((token) => {
set_session_token(token); set_session_token(token);
goto("/") goto("/");
}); });
}; };
function loggedIn(): boolean { function loggedIn(): boolean {
return get_session_token() != null return get_session_token() != null;
} }
</script> </script>

View file

@ -3,23 +3,23 @@
let password: string | undefined; let password: string | undefined;
const onSubmit = () => { const onSubmit = () => {
if (username === undefined || username.trim() === '') { if (username === undefined || username.trim() === "") {
return; return;
} }
if (password === undefined || password.trim() === '') { if (password === undefined || password.trim() === "") {
return; return;
} }
fetch('/api/register', { fetch("/api/register", {
method: 'POST', method: "POST",
headers: { headers: {
'Content-Type': 'application/json' "Content-Type": "application/json",
}, },
body: JSON.stringify({ body: JSON.stringify({
username, username,
password password,
}) }),
}) })
.then((resp) => resp.json()) .then((resp) => resp.json())
.then((data) => { .then((data) => {

View file

@ -1,9 +1,8 @@
import adapter from '@sveltejs/adapter-auto'; import adapter from "@sveltejs/adapter-auto";
import preprocess from 'svelte-preprocess'; import preprocess from "svelte-preprocess";
// import { svelte } from '@sveltejs/vite-plugin-svelte' // import { svelte } from '@sveltejs/vite-plugin-svelte'
import { viteCommonjs } from '@originjs/vite-plugin-commonjs' import { viteCommonjs } from "@originjs/vite-plugin-commonjs";
import wasmPack from 'vite-plugin-wasm-pack'; import wasmPack from "vite-plugin-wasm-pack";
/** @type {import('@sveltejs/kit').Config} */ /** @type {import('@sveltejs/kit').Config} */
const config = { const config = {
@ -15,7 +14,7 @@ const config = {
adapter: adapter(), adapter: adapter(),
// hydrate the <div id="svelte"> element in src/app.html // hydrate the <div id="svelte"> element in src/app.html
target: '#svelte', target: "#svelte",
ssr: false, ssr: false,
vite: { vite: {
plugins: [ plugins: [
@ -37,13 +36,11 @@ const config = {
}, },
fs: { fs: {
// Allow serving files from one level up to the project root // Allow serving files from one level up to the project root
allow: ['..'] allow: [".."],
} },
},
}, },
}
}, },
}; };
export default config; export default config;