From 34a1a5df64ca8b2e6736c24046fd6b3b5274a5a0 Mon Sep 17 00:00:00 2001 From: Maya Date: Sun, 22 Mar 2026 23:01:34 +0300 Subject: [PATCH] feat: toast if file is too large for vertd --- messages/en.json | 3 +- .../functional/FormatDropdown.svelte | 2 +- src/lib/converters/mediabunny.svelte.ts | 1 - src/lib/converters/vertd.svelte.ts | 74 ++++++++++++++++++- src/lib/sections/settings/Privacy.svelte | 36 +++++---- src/lib/types/file.svelte.ts | 4 - src/lib/util/file.ts | 16 ++++ src/routes/about/+page.svelte | 16 ++-- 8 files changed, 121 insertions(+), 31 deletions(-) diff --git a/messages/en.json b/messages/en.json index 3cc258d..7836a4b 100644 --- a/messages/en.json +++ b/messages/en.json @@ -174,6 +174,7 @@ "vertd_details_error_message": "Error message: [view_link]View error logs[/view_link]", "vertd_details_close": "Close", "vertd_ratelimit": "Your video, '{filename}', has failed to convert a few times. To prevent server overload, further conversion attempts for this file have been temporarily blocked. Please try again later.", + "vertd_file_too_large": "This file is too big for the specified vertd server ({fileSize}/{limit}). Please choose a smaller file or use another converter/server.", "vertd_retry": "Retrying video conversion for {filename} with different settings due to failure. This may take longer than usual.", "unsupported_format": "Only image, video, audio, and document files are supported", "format_output_only": "This format can currently only be used as output (converted to), not as input.", @@ -382,7 +383,7 @@ }, "local_storage": { "title": "Local Storage", - "description": "We use your browser's local storage to save your settings, and your browser's session storage to temporarily store the GitHub contributors list for the \"About\" section to reduce repeated GitHub API requests. No personal data is stored or transmitted.

The WebAssembly or browser versions of the conversion tools we use (Mediabunny, FFmpeg, ImageMagick, Pandoc) are also stored locally on your browser when you first visit the website, so you don't need to redownload them each visit. No personal data is stored or transmitted. You may view or delete this data at any time in the \"Privacy & data\" section in [settings_link]settings[/settings_link]." + "description": "We use your browser's local storage to save your settings. We also use your browser's session storage to temporarily store the specified vertd server's file size limit (if applicable) to reduce repeated API requests and the GitHub contributors list for the \"About\" section to do the same. No personal data is stored or transmitted.

The WebAssembly or browser versions of the conversion tools we use (Mediabunny, FFmpeg, ImageMagick, Pandoc) are also stored locally on your browser when you first visit the website, so you don't need to redownload them each visit. No personal data is stored or transmitted. You may view or delete this data at any time in the \"Privacy & data\" section in [settings_link]settings[/settings_link]." }, "contact": { "title": "Contact", diff --git a/src/lib/components/functional/FormatDropdown.svelte b/src/lib/components/functional/FormatDropdown.svelte index 633b41e..900cc11 100644 --- a/src/lib/components/functional/FormatDropdown.svelte +++ b/src/lib/components/functional/FormatDropdown.svelte @@ -475,7 +475,7 @@ {/if} - + {#if file?.name.toLowerCase().endsWith(".zip")}
@@ -270,7 +277,6 @@ {m["settings.privacy.clear_all_data"]()}
- diff --git a/src/lib/types/file.svelte.ts b/src/lib/types/file.svelte.ts index fe61439..0783287 100644 --- a/src/lib/types/file.svelte.ts +++ b/src/lib/types/file.svelte.ts @@ -196,8 +196,6 @@ export class VertFile { ["file", "convert"], `no compatible converter found for ${this.from} to ${this.to}`, ); - // TODO: handle zip converter fallback explicitly if needed - // TODO: provide a clearer error path for unsupported from/to pairs } } else { log( @@ -250,8 +248,6 @@ export class VertFile { (c) => !this.attemptedConverters.has(c.name), ); - // TODO: clean up languages file, then migrate all languages to new structure - // TODO: should figure out a cleaner way to do this if (!this.cancelled && nextConverter) { if (this.fallbackToastId !== null) diff --git a/src/lib/util/file.ts b/src/lib/util/file.ts index bb9dd6f..4f36d64 100644 --- a/src/lib/util/file.ts +++ b/src/lib/util/file.ts @@ -74,3 +74,19 @@ export function formatFilename(format: string, file: File | string) { .replace(/%name%/g, baseName) .replace(/%extension%/g, originalExtension); } + +export const formatBytes = (bytes: number): string => { + if (!Number.isFinite(bytes) || bytes <= 0) return "0 B"; + if (bytes < 1024) return `${bytes} B`; + + const units = ["KB", "MB", "GB", "TB"]; + let value = bytes; + let unitIndex = -1; + + while (value >= 1024 && unitIndex < units.length - 1) { + value /= 1024; + unitIndex++; + } + + return `${value.toFixed(value >= 100 ? 0 : value >= 10 ? 1 : 2)} ${units[unitIndex]}`; +}; \ No newline at end of file diff --git a/src/routes/about/+page.svelte b/src/routes/about/+page.svelte index 9500254..3c03043 100644 --- a/src/routes/about/+page.svelte +++ b/src/routes/about/+page.svelte @@ -9,7 +9,10 @@ import avatarRealmy from "$lib/assets/avatars/realmy.jpg"; import avatarAzurejelly from "$lib/assets/avatars/azurejelly.jpg"; import { PUB_DONATION_URL, PUB_STRIPE_KEY } from "$env/static/public"; - import { DISABLE_ALL_EXTERNAL_REQUESTS, GITHUB_API_URL } from "$lib/util/consts"; + import { + DISABLE_ALL_EXTERNAL_REQUESTS, + GITHUB_API_URL, + } from "$lib/util/consts"; import { m } from "$lib/paraglide/messages"; import { ToastManager } from "$lib/util/toast.svelte"; // import { dev } from "$app/environment"; @@ -69,9 +72,11 @@ let ghContribs: Contributor[] = []; onMount(async () => { - if (DISABLE_ALL_EXTERNAL_REQUESTS) { + if ( + DISABLE_ALL_EXTERNAL_REQUESTS || + typeof sessionStorage === "undefined" + ) return; - } // Check if the data is already in sessionStorage const cachedContribs = sessionStorage.getItem("ghContribs"); @@ -130,9 +135,8 @@ } }); - const donationsEnabled = PUB_STRIPE_KEY - && PUB_DONATION_URL - && !DISABLE_ALL_EXTERNAL_REQUESTS; + const donationsEnabled = + PUB_STRIPE_KEY && PUB_DONATION_URL && !DISABLE_ALL_EXTERNAL_REQUESTS;