aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/routes
diff options
context:
space:
mode:
authorMatt Strapp <matt@mattstrapp.net>2023-09-27 16:16:10 -0500
committerMatt Strapp <matt@mattstrapp.net>2023-09-27 16:16:10 -0500
commit13d465c1c45e649a702457d67476694aeb553704 (patch)
treed0d3ba8ac0ff9546482b8f5e7294399613e6cb20 /app/src/routes
parentWorkspaces! (diff)
downloadtrinkets-13d465c1c45e649a702457d67476694aeb553704.tar
trinkets-13d465c1c45e649a702457d67476694aeb553704.tar.gz
trinkets-13d465c1c45e649a702457d67476694aeb553704.tar.bz2
trinkets-13d465c1c45e649a702457d67476694aeb553704.tar.lz
trinkets-13d465c1c45e649a702457d67476694aeb553704.tar.xz
trinkets-13d465c1c45e649a702457d67476694aeb553704.tar.zst
trinkets-13d465c1c45e649a702457d67476694aeb553704.zip
Get rid of crc32, truncate instead
Signed-off-by: Matt Strapp <matt@mattstrapp.net>
Diffstat (limited to 'app/src/routes')
-rw-r--r--app/src/routes/crc32/+page.svelte55
-rw-r--r--app/src/routes/truncate/+page.svelte75
2 files changed, 75 insertions, 55 deletions
diff --git a/app/src/routes/crc32/+page.svelte b/app/src/routes/crc32/+page.svelte
deleted file mode 100644
index b88e52e..0000000
--- a/app/src/routes/crc32/+page.svelte
+++ /dev/null
@@ -1,55 +0,0 @@
-<script lang="ts">
- import { FileDropzone, ProgressBar } from '@skeletonlabs/skeleton';
- import { onMount } from 'svelte';
-
- let disableInput = false;
- let files: FileList;
- let form: HTMLFormElement;
- let worker: Worker;
-
- function onUpload() {
- disableInput = true;
- worker.postMessage(files[0]);
- form.reset();
- }
-
- onMount(async () => {
- worker = new Worker(new URL('$lib/ts/crc32.worker.ts', import.meta.url), { type: 'module' });
- worker.onmessage = (e: MessageEvent<number>) => {
- disableInput = false;
- console.log(e.data);
- };
- });
-</script>
-
-<svelte:head>
- <title>CRC32</title>
-</svelte:head>
-
-<div class="container h-full mx-auto flex justify-center items-center">
- <div class="space-y-10 text-center flex flex-col items-center">
- <form bind:this={form} on:submit|preventDefault={onUpload} method="POST" action="?/TODO">
- <FileDropzone
- name="checksumMe"
- bind:files
- on:change={() => form.requestSubmit()}
- required
- disabled={disableInput}
- >
- <svelte:fragment slot="lead">
- <h2 class="h2">Drop a file here to get its CRC32 checksum.</h2>
- </svelte:fragment>
- </FileDropzone>
- <br />
- <noscript>
- <button type="submit" class="btn variant-filled">
- After adding a file, click to submit! (Not yet implemented)
- </button>
- </noscript>
- {#if disableInput}
- <h3 class="h3">Calculating the checksum, this may take time!</h3> <br />
- <ProgressBar />
- {/if}
- </form>
- </div>
-</div>
diff --git a/app/src/routes/truncate/+page.svelte b/app/src/routes/truncate/+page.svelte
new file mode 100644
index 0000000..9e2545f
--- /dev/null
+++ b/app/src/routes/truncate/+page.svelte
@@ -0,0 +1,75 @@
+<script lang="ts">
+ 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';
+
+ let disableInput = false;
+ let files: FileList;
+ let form: HTMLFormElement;
+ let worker: Worker;
+ $: truncateTo = 1;
+ let originalName: string;
+
+ function onUpload() {
+ disableInput = true;
+ originalName = files[0].name;
+ worker.postMessage({
+ file: files[0],
+ size: truncateTo,
+ } as TruncateRequest);
+ form.reset();
+ truncateTo = 1;
+ }
+
+ onMount(async () => {
+ worker = new Worker(new URL('$lib/ts/truncate.worker.ts', import.meta.url), { type: 'module' });
+ worker.onmessage = (e: MessageEvent<TruncateResponse>) => {
+ disableInput = false;
+ saveFile(e.data.file, `trunc-${originalName}`);
+
+ };
+ });
+</script>
+
+<svelte:head>
+ <title>Truncate</title>
+</svelte:head>
+
+<div class="container h-full mx-auto flex justify-center items-center">
+ <div class="space-y-10 text-center flex flex-col items-center">
+ <form bind:this={form} on:submit|preventDefault={onUpload} method="POST" action="?/TODO">
+ <label class="label" for="truncateMe">
+ <FileDropzone
+ id="truncateMe"
+ name="truncateMe"
+ bind:files
+ on:change={() => form.requestSubmit()}
+ required
+ disabled={disableInput}
+ >
+ <svelte:fragment slot="lead">
+ <h2 class="h2">Drop a file here to truncate it.</h2>
+ </svelte:fragment>
+ </FileDropzone>
+ </label>
+ <br />
+ <label class="label">
+ <span>Truncate up to... (in bytes)</span>
+ <input class="input" type="number" name="truncateTo" bind:value={truncateTo} min="1" required />
+
+ </label>
+ <br />
+ <noscript>
+ <button type="submit" class="btn variant-filled"
+ >After adding a file, click to submit! (Not yet implemented)</button
+ >
+ </noscript>
+ {#if disableInput}
+ <h3 class="h3">Truncating the file, this may take time!</h3>
+ <br />
+ <ProgressBar />
+ {/if}
+ </form>
+ </div>
+</div>