aboutsummaryrefslogtreecommitdiffstats
path: root/app/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--app/src/lib/ts/download.ts59
-rw-r--r--app/src/lib/ts/truncate.worker.ts11
-rw-r--r--app/src/lib/types/truncate-worker.ts6
-rw-r--r--app/src/routes/+layout.svelte1
-rw-r--r--app/src/routes/truncate/+page.svelte15
5 files changed, 49 insertions, 43 deletions
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<TruncateRequest>) => {
- 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 @@
</script>
<svelte:head>
+ <!-- eslint-disable-next-line svelte/no-at-html-tags VitePWA can probably be trusted -->
{@html webManifestLink}
</svelte:head>
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 @@
<script lang="ts">
- import saveFile from '$lib/ts/download';
+ import saveFile from '$lib/ts/download';
import type { TruncateRequest, TruncateResponse } from '$lib/types/truncate-worker';
import { FileDropzone, ProgressBar } from '@skeletonlabs/skeleton';
import { onMount } from 'svelte';
@@ -16,7 +16,7 @@
originalName = files[0].name;
worker.postMessage({
file: files[0],
- size: truncateTo,
+ size: truncateTo
} as TruncateRequest);
form.reset();
truncateTo = 1;
@@ -27,7 +27,6 @@
worker.onmessage = (e: MessageEvent<TruncateResponse>) => {
disableInput = false;
saveFile(e.data.file, `trunc-${originalName}`);
-
};
});
</script>
@@ -56,8 +55,14 @@
<br />
<label class="label">
<span>Truncate up to... (in bytes)</span>
- <input class="input" type="number" name="truncateTo" bind:value={truncateTo} min="1" required />
-
+ <input
+ class="input"
+ type="number"
+ name="truncateTo"
+ bind:value={truncateTo}
+ min="1"
+ required
+ />
</label>
<br />
<noscript>