diff --git a/Webserver/src/lib/client/color.ts b/Webserver/src/lib/client/color.ts index b5cf9d9..441c2ae 100644 --- a/Webserver/src/lib/client/color.ts +++ b/Webserver/src/lib/client/color.ts @@ -18,10 +18,10 @@ export function hexToRgb(hex: string): Color | null { const result = /^([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); return result ? { - r: parseInt(result[1], 16), - g: parseInt(result[2], 16), - b: parseInt(result[3], 16) - } + r: parseInt(result[1], 16), + g: parseInt(result[2], 16), + b: parseInt(result[3], 16) + } : null; } @@ -36,7 +36,5 @@ export function getLuminance(rgb: Color): number { // Convert an rgb color object to a hex color string export function rgbToHex(color: Color): string { - return [color.r, color.g, color.b] - .map((e) => e.toString(16).padStart(2, '0')) - .join(''); + return [color.r, color.g, color.b].map((e) => e.toString(16).padStart(2, '0')).join(''); } diff --git a/Webserver/src/lib/client/httpRequests.ts b/Webserver/src/lib/client/httpRequests.ts index e7a8ea5..e59d0ad 100644 --- a/Webserver/src/lib/client/httpRequests.ts +++ b/Webserver/src/lib/client/httpRequests.ts @@ -1,23 +1,22 @@ -import type { APIResponse } from '$lib/interfaces'; - -export async function redirectAPI({ form, fdata }: { form?: HTMLFormElement; fdata?: FormData }) { - if (!fdata && form) fdata = new FormData(form); - else if (!fdata) throw new Error('No formdata provided!'); - - // Get endpoint, prefer form, then formdata or empty - const endpoint = (form?.dataset.endpoint ?? fdata.get('endpoint')) ?? ''; - // Append endpoint to formdata - if (!fdata?.has('endpoint')) - fdata.append('endpoint', endpoint); - - // Send request to be redirected to given endpoint - const response = await fetch('/api/redirect', { - method: 'POST', - body: fdata - }); - - // Await respose from webserver - const mdata = (await response.json()) as APIResponse; - // Basic error handling - if (!mdata.success) alert(`Error while processing '${endpoint}'!`); -} +import type { APIResponse } from '$lib/interfaces'; + +export async function redirectAPI({ form, fdata }: { form?: HTMLFormElement; fdata?: FormData }) { + if (!fdata && form) fdata = new FormData(form); + else if (!fdata) throw new Error('No formdata provided!'); + + // Get endpoint, prefer form, then formdata or empty + const endpoint = form?.dataset.endpoint ?? fdata.get('endpoint') ?? ''; + // Append endpoint to formdata + if (!fdata?.has('endpoint')) fdata.append('endpoint', endpoint); + + // Send request to be redirected to given endpoint + const response = await fetch('/api/redirect', { + method: 'POST', + body: fdata + }); + + // Await respose from webserver + const mdata = (await response.json()) as APIResponse; + // Basic error handling + if (!mdata.success) alert(`Error while processing '${endpoint}'!`); +} diff --git a/Webserver/src/lib/client/matrix.ts b/Webserver/src/lib/client/matrix.ts index 36aef55..66fbb72 100644 --- a/Webserver/src/lib/client/matrix.ts +++ b/Webserver/src/lib/client/matrix.ts @@ -46,9 +46,6 @@ export function createGridArray(matrix: Matrix): MatrixCell[][] { const { factor } = scale; return Array.from({ length: height / factor }, (_, y) => - Array.from( - { length: width / factor }, - (_, x) => ({ x, y, color: '000000' }) as MatrixCell - ) + Array.from({ length: width / factor }, (_, x) => ({ x, y, color: '000000' }) as MatrixCell) ) as MatrixCell[][]; } diff --git a/Webserver/src/lib/server/buildAPIStr.ts b/Webserver/src/lib/server/buildAPIStr.ts index 603c400..5460fc2 100644 --- a/Webserver/src/lib/server/buildAPIStr.ts +++ b/Webserver/src/lib/server/buildAPIStr.ts @@ -2,4 +2,4 @@ import { API_SERVER_IP, API_SERVER_PORT } from '$env/static/private'; export function buildAPIStr(endpoint: string) { return `http://${API_SERVER_IP ?? 'localhost'}:${API_SERVER_PORT ?? '8080'}/${endpoint}`; -} \ No newline at end of file +} diff --git a/Webserver/src/routes/+page.svelte b/Webserver/src/routes/+page.svelte index 87cebf6..a0c61e2 100644 --- a/Webserver/src/routes/+page.svelte +++ b/Webserver/src/routes/+page.svelte @@ -1,10 +1,10 @@ -
Fetching subreddit data . . .
-{uploadData.elapsed} seconds elapsed.
- {/await} - {:else} - {#await fileAsDataURL(submitData)} -Loading image data . . .
-{uploadData.elapsed} seconds elapsed.
- {:then dataUrl} - {#await sendImage(dataUrl)} -Sending image . . .
-{uploadData.elapsed} seconds elapsed.
- {:then} - {#await placeImage(submitData)} -Placing image . . .
-{uploadData.elapsed} seconds elapsed.
- {:then} - {#await updateMatrix(submitData)} -Updating matrix . . .
-{uploadData.elapsed} seconds elapsed.
- {:then} -Done!
-{uploadData.elapsed} seconds elapsed.
- {/await} - {/await} - {/await} - {/await} - {/if} -{/if} + + +Fetching subreddit data . . .
+{uploadData.elapsed} seconds elapsed.
+ {/await} + {:else} + {#await fileAsDataURL(submitData)} +Loading image data . . .
+{uploadData.elapsed} seconds elapsed.
+ {:then dataUrl} + {#await sendImage(dataUrl)} +Sending image . . .
+{uploadData.elapsed} seconds elapsed.
+ {:then} + {#await placeImage(submitData)} +Placing image . . .
+{uploadData.elapsed} seconds elapsed.
+ {:then} + {#await updateMatrix(submitData)} +Updating matrix . . .
+{uploadData.elapsed} seconds elapsed.
+ {:then} +Done!
+{uploadData.elapsed} seconds elapsed.
+ {/await} + {/await} + {/await} + {/await} + {/if} +{/if} diff --git a/Webserver/tsconfig.json b/Webserver/tsconfig.json index 1797076..a588d37 100644 --- a/Webserver/tsconfig.json +++ b/Webserver/tsconfig.json @@ -10,11 +10,13 @@ "sourceMap": true, "strict": true, "moduleResolution": "bundler", - "plugins": [{ - "name": "typescript-svelte-plugin", - "assumeIsSvelteProject": false, - "enabled": true - }] + "plugins": [ + { + "name": "typescript-svelte-plugin", + "assumeIsSvelteProject": false, + "enabled": true + } + ] } // Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias // diff --git a/Webserver/vite.config.ts b/Webserver/vite.config.ts index f78a266..fea8786 100644 --- a/Webserver/vite.config.ts +++ b/Webserver/vite.config.ts @@ -6,5 +6,5 @@ export default defineConfig({ test: { include: ['src/**/*.{test,spec}.{js,ts}'], exclude: ['src/playwright'] - }, + } });