From ef30f835d04038a1cbec06fbe35a70037e926cd6 Mon Sep 17 00:00:00 2001 From: Matt Strapp Date: Thu, 28 Sep 2023 08:42:25 -0500 Subject: Lint Signed-off-by: Matt Strapp --- app/.eslintignore | 1 + app/.prettierignore | 1 + app/src/lib/ts/download.ts | 59 ++++++++++++++++++------------------ app/src/lib/ts/truncate.worker.ts | 11 +++---- app/src/lib/types/truncate-worker.ts | 6 ++-- app/src/routes/+layout.svelte | 1 + app/src/routes/truncate/+page.svelte | 15 ++++++--- 7 files changed, 51 insertions(+), 43 deletions(-) diff --git a/app/.eslintignore b/app/.eslintignore index 3897265..fd8e5e1 100644 --- a/app/.eslintignore +++ b/app/.eslintignore @@ -6,6 +6,7 @@ node_modules .env .env.* !.env.example +/dev-dist # Ignore files for PNPM, NPM and YARN pnpm-lock.yaml diff --git a/app/.prettierignore b/app/.prettierignore index 3897265..fd8e5e1 100644 --- a/app/.prettierignore +++ b/app/.prettierignore @@ -6,6 +6,7 @@ node_modules .env .env.* !.env.example +/dev-dist # Ignore files for PNPM, NPM and YARN pnpm-lock.yaml diff --git a/app/src/lib/ts/download.ts b/app/src/lib/ts/download.ts index a6167d7..16712fb 100644 --- a/app/src/lib/ts/download.ts +++ b/app/src/lib/ts/download.ts @@ -1,33 +1,34 @@ // Yoinked from https://web.dev/patterns/files/save-a-file/ for the polyfill export default async function saveFile(blob: ArrayBuffer, suggestedName: string | undefined) { - const supportsFSAccess = 'showSaveFilePicker' in window && - (() => { - try { - return window.self === window.top; - } catch { - return false; - } - })(); + const supportsFSAccess = + 'showSaveFilePicker' in window && + (() => { + try { + return window.self === window.top; + } catch { + return false; + } + })(); - if (supportsFSAccess) { - try { - const handle = await window.showSaveFilePicker({ - suggestedName: suggestedName, - }) - const writable = await handle.createWritable(); - await writable.write(blob); - await writable.close(); - } catch (err: unknown) { - // TypeScript - if ((err as Error)?.name !== 'AbortError') { - console.error(err); - } - } - } else { - const anchor = document.createElement('a'); - anchor.download = suggestedName ?? 'truncated'; - anchor.href = URL.createObjectURL(new Blob([blob])); - anchor.click(); - } -} \ No newline at end of file + if (supportsFSAccess) { + try { + const handle = await window.showSaveFilePicker({ + suggestedName: suggestedName + }); + const writable = await handle.createWritable(); + await writable.write(blob); + await writable.close(); + } catch (err: unknown) { + // TypeScript + if ((err as Error)?.name !== 'AbortError') { + console.error(err); + } + } + } else { + const anchor = document.createElement('a'); + anchor.download = suggestedName ?? 'truncated'; + anchor.href = URL.createObjectURL(new Blob([blob])); + anchor.click(); + } +} diff --git a/app/src/lib/ts/truncate.worker.ts b/app/src/lib/ts/truncate.worker.ts index 52eebb7..ad00011 100644 --- a/app/src/lib/ts/truncate.worker.ts +++ b/app/src/lib/ts/truncate.worker.ts @@ -1,10 +1,9 @@ import type { TruncateRequest, TruncateResponse } from '../types/truncate-worker'; - onmessage = async (message: MessageEvent) => { - const file = message.data.file; - const buffer = await file.arrayBuffer(); - const truncated = buffer.slice(0, message.data.size); + const file = message.data.file; + const buffer = await file.arrayBuffer(); + const truncated = buffer.slice(0, message.data.size); - postMessage({ file: truncated } as TruncateResponse); -} \ No newline at end of file + postMessage({ file: truncated } as TruncateResponse); +}; diff --git a/app/src/lib/types/truncate-worker.ts b/app/src/lib/types/truncate-worker.ts index 9b1872f..7052d17 100644 --- a/app/src/lib/types/truncate-worker.ts +++ b/app/src/lib/types/truncate-worker.ts @@ -1,8 +1,8 @@ export type TruncateRequest = { - file: File, - size: number, + file: File; + size: number; }; export type TruncateResponse = { - file: ArrayBuffer, + file: ArrayBuffer; }; diff --git a/app/src/routes/+layout.svelte b/app/src/routes/+layout.svelte index a0dd68a..6ad0d22 100644 --- a/app/src/routes/+layout.svelte +++ b/app/src/routes/+layout.svelte @@ -42,6 +42,7 @@ + {@html webManifestLink} diff --git a/app/src/routes/truncate/+page.svelte b/app/src/routes/truncate/+page.svelte index 9e2545f..1b37f56 100644 --- a/app/src/routes/truncate/+page.svelte +++ b/app/src/routes/truncate/+page.svelte @@ -1,5 +1,5 @@ @@ -56,8 +55,14 @@