Skip to content

armgit / VERT

Public Imported from GitHub
0

The next-generation file converter. Open source, fully local* and free forever.

feat: vertd file size limit toast

JovannMC1b02dc0c79e6
diff --git a/messages/en.json b/messages/en.json
index d05d35b..12eabe3 100644
--- a/messages/en.json
+++ b/messages/en.json
@@ -211,12 +211,9 @@
"server": "what are you doing..? you're supposed to run the vertd server!",
"not_found": "Could not find the vertd instance to start video conversion. Are you sure the instance URL is set correctly?",
"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.",
- "file_too_large": {
- "text": "This file is <b>{fileSize}</b>, but the selected vertd server only supports files up to <b>{limit}</b>.\nTry using a smaller file, different format, or change your vertd server in Settings.",
- "button": "Change converter"
- },
+ "file_too_large": "The file '{filename}' is <b>{fileSize}</b>, but the selected vertd server only supports files up to <b>{limit}</b>.\nTry using a smaller file, different format, or change your vertd server in Settings.",
"failed_to_keep": "Failed to keep the video on the server: {error}",
- "retry": "Retrying video conversion for {filename} with different settings due to failure. This may take longer than usual.",
+ "retry": "Retrying video conversion for '{filename}' with different settings due to failure. This may take longer than usual.",
"generic": {
"title": "Video conversion error",
"view": "View error details",
diff --git a/src/lib/components/functional/FormatDropdown.svelte b/src/lib/components/functional/FormatDropdown.svelte
index 2b61f08..1c5767c 100644
--- a/src/lib/components/functional/FormatDropdown.svelte
+++ b/src/lib/components/functional/FormatDropdown.svelte
@@ -1,7 +1,12 @@
<script lang="ts">
import { duration, fade, transition } from "$lib/util/animation";
import { m } from "$lib/paraglide/messages";
- import { isMobile, files, dropdownStates, fileSettings } from "$lib/store/index.svelte";
+ import {
+ isMobile,
+ files,
+ dropdownStates,
+ fileSettings,
+ } from "$lib/store/index.svelte";
import type { Categories } from "$lib/types";
import clsx from "clsx";
import { ChevronDown, SearchIcon } from "@lucide/svelte";
@@ -64,11 +69,17 @@
const normalize = (str: string) => str.replace(/^\./, "").toLowerCase();
- const shouldExclude = (format: string): boolean =>
- !!(
+ const shouldExclude = (format: string): boolean => {
+ if (
categories["audio"]?.formats.includes(from ?? "") &&
format === ".gif"
- );
+ )
+ return true;
+
+ if (!file || file.unavailableConverters.length === 0) return false;
+
+ return !file.hasAvailableConverter(file.from, format);
+ };
const getFormats = (cat: string) => {
let formats = (categories[cat]?.formats ?? []).filter(
@@ -276,16 +287,10 @@
);
if (!allUnfilteredFormats.includes(selected)) {
- // check if formats available in filteredData, else fall back to all available formats, else keep previous selection
- if (filteredData.formats.length > 0) {
- selected = filteredData.formats[0];
- onselect?.(selected);
- } else if (allUnfilteredFormats.length > 0) {
+ if (allUnfilteredFormats.length > 0) {
selected = allUnfilteredFormats[0];
- onselect?.(allUnfilteredFormats[0]);
- } else {
- // no formats available, keeping previous selection
- // i feel like this is all very scuffed and we need a better search and filtering system
+ onselect?.(selected);
+ return;
}
}
});
@@ -632,7 +637,7 @@
<div class="border-t border-separator text-base p-2">
<button
class="w-full p-2 text-center rounded-lg bg-accent text-black"
- onclick={() => $fileSettings = file}
+ onclick={() => ($fileSettings = file)}
>
{m["convert.settings.settings"]()}
</button>
diff --git a/src/lib/components/functional/popups/SettingsModal.svelte b/src/lib/components/functional/popups/SettingsModal.svelte
index 8567532..f7359ab 100644
--- a/src/lib/components/functional/popups/SettingsModal.svelte
+++ b/src/lib/components/functional/popups/SettingsModal.svelte
@@ -45,9 +45,16 @@
]);
const getAvailableConverters = (vertFile: VertFile) => {
- return vertFile.isZip()
- ? vertFile.converters
- : vertFile.findConverters([vertFile.from, vertFile.to]);
+ const availableConverters = vertFile.converters.filter(
+ (converter) =>
+ !vertFile.unavailableConverters.includes(converter.name),
+ );
+ const supportedConverters = vertFile.findConverters(
+ [vertFile.from, vertFile.to],
+ vertFile.unavailableConverters,
+ );
+
+ return vertFile.isZip() ? availableConverters : supportedConverters;
};
const getValidConverter = (vertFile: VertFile, converterName?: string) => {
diff --git a/src/lib/components/visual/Toast.svelte b/src/lib/components/visual/Toast.svelte
index 5a066f8..b61cfad 100644
--- a/src/lib/components/visual/Toast.svelte
+++ b/src/lib/components/visual/Toast.svelte
@@ -13,6 +13,7 @@
import type { SvelteComponent } from "svelte";
import clsx from "clsx";
import type { Toast as ToastType } from "$lib/util/toast.svelte";
+ import { sanitize } from "$lib/store/index.svelte";
const props: {
toast: ToastType<unknown>;
@@ -58,7 +59,7 @@
</script>
<div
- class="flex flex-col max-w-[100%] md:max-w-md p-4 gap-2 bg-accent-{color} border-accent-{color}-alt border-l-4 rounded-lg shadow-md"
+ class="flex flex-col max-w-[100%] md:max-w-lg p-4 gap-2 bg-accent-{color} border-accent-{color}-alt border-l-4 rounded-lg shadow-md"
in:fly={{
duration: durations.enter,
easing: quintOut,
@@ -71,11 +72,10 @@
}}
>
<div class="flex flex-row items-center justify-between w-full gap-4">
- <div class="flex items-center gap-2">
+ <div class="flex items-center gap-4">
<Icon
class="w-6 h-6 text-black flex-shrink-0"
size="24"
- stroke="2"
fill="none"
/>
<p
@@ -83,7 +83,7 @@
"font-normal": !title,
})}
>
- {title || message}
+ {@html sanitize((title || message) as string)}
</p>
</div>
<button
diff --git a/src/lib/sections/settings/vertdSettings.svelte.ts b/src/lib/sections/settings/vertdSettings.svelte.ts
index e3c6a2a..dea9184 100644
--- a/src/lib/sections/settings/vertdSettings.svelte.ts
+++ b/src/lib/sections/settings/vertdSettings.svelte.ts
@@ -184,10 +184,7 @@ export function useVertdSizeLimit() {
const serverLimit = await getVertdLimit();
const finalLimit = serverLimit ?? Number.POSITIVE_INFINITY;
vertdSizeLimit.set(finalLimit);
- log(
- ["vertd"],
- `fetched vertd size limit: ${finalLimit} bytes`,
- );
+ log(["vertd"], `fetched vertd size limit: ${finalLimit} bytes`);
if (sessionStorageAvailable) {
try {
diff --git a/src/lib/types/file.svelte.ts b/src/lib/types/file.svelte.ts
index 28b56e1..70aee0a 100644
--- a/src/lib/types/file.svelte.ts
+++ b/src/lib/types/file.svelte.ts
@@ -35,6 +35,7 @@ export class VertFile {
public blobUrl = $state<string>();
public processing = $state(false);
public cancelled = $state(false);
+ public unavailableConverters = $state<string[]>([]);
public converters: Converter[] = [];
private fallbackToastId: number | null = null;
@@ -97,9 +98,14 @@ export class VertFile {
return converterInstance.getAvailableSettings(input);
}
- public findConverters(supportedFormats: string[] = [this.from]) {
+ public findConverters(
+ supportedFormats: string[] = [this.from],
+ unavailableConverters: string[] = [],
+ ) {
return this.converters
.filter((converter) => {
+ if (unavailableConverters.includes(converter.name))
+ return false;
if (
!converter
.formatStrings()
@@ -143,6 +149,28 @@ export class VertFile {
});
}
+ // returns true if there is at least one converter that can convert from `from` to `to`
+ public hasAvailableConverter(from: string, to: string): boolean {
+ return this.converters.some((converter) => {
+ if (this.unavailableConverters.includes(converter.name))
+ return false;
+
+ const fromInfo = converter.supportedFormats.find(
+ (info) => info.name === from,
+ );
+ const toInfo = converter.supportedFormats.find(
+ (info) => info.name === to,
+ );
+ return (
+ !!fromInfo &&
+ !!toInfo &&
+ fromInfo.fromSupported &&
+ toInfo.toSupported &&
+ (fromInfo.isNative || toInfo.isNative)
+ );
+ });
+ }
+
public isLarge(): boolean {
return this.file.size > MAX_ARRAY_BUFFER_SIZE;
}
diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte
index 361b495..14f24d0 100644
--- a/src/routes/+layout.svelte
+++ b/src/routes/+layout.svelte
@@ -3,10 +3,7 @@
import { goto, beforeNavigate, afterNavigate } from "$app/navigation";
import { PUB_PLAUSIBLE_URL, PUB_HOSTNAME } from "$env/static/public";
- import {
- DISABLE_ALL_EXTERNAL_REQUESTS,
- VERT_NAME,
- } from "$lib/util/consts";
+ import { DISABLE_ALL_EXTERNAL_REQUESTS, VERT_NAME } from "$lib/util/consts";
import * as Layout from "$lib/components/layout";
import * as Navbar from "$lib/components/layout/Navbar";
import { Settings } from "$lib/sections/settings/index.svelte";
diff --git a/src/routes/convert/+page.svelte b/src/routes/convert/+page.svelte
index d2fa65b..5a290a1 100644
--- a/src/routes/convert/+page.svelte
+++ b/src/routes/convert/+page.svelte
@@ -17,7 +17,6 @@
showGradient,
dropdownStates,
fileSettings,
- sanitize,
} from "$lib/store/index.svelte";
import { VertFile } from "$lib/types";
import {
@@ -38,10 +37,41 @@
import { MAX_ARRAY_BUFFER_SIZE } from "$lib/store/index.svelte";
import { GB } from "$lib/util/consts";
import { formatBytes } from "$lib/util/file";
- import { vertdSizeLimit } from "$lib/sections/settings/vertdSettings.svelte";
import SettingsModal from "$lib/components/functional/popups/SettingsModal.svelte";
+ import { ToastManager } from "$lib/util/toast.svelte";
+ import { vertdSizeLimit } from "$lib/sections/settings/vertdSettings.svelte";
let processedFileIds = $state(new Set<string>());
+ const vertdSizeWarningFileIds = new Set<string>();
+
+ $effect(() => {
+ const limit = $vertdSizeLimit;
+ for (const file of files.files) {
+ const exceedsLimit = file.size > limit;
+ const unavailable = file.unavailableConverters;
+ const shouldMarkUnavailable = exceedsLimit
+ ? !unavailable.includes("vertd")
+ : unavailable.includes("vertd");
+
+ if (shouldMarkUnavailable) {
+ file.unavailableConverters = exceedsLimit
+ ? [...unavailable, "vertd"]
+ : unavailable.filter((name) => name !== "vertd");
+ }
+ if (!exceedsLimit || vertdSizeWarningFileIds.has(file.id)) continue;
+
+ vertdSizeWarningFileIds.add(file.id);
+ ToastManager.add({
+ type: "warning",
+ message: m["convert.errors.vertd.file_too_large"]({
+ filename: file.name,
+ fileSize: formatBytes(file.size),
+ limit: formatBytes(limit),
+ }),
+ disappearing: false,
+ });
+ }
+ });
const getCurrentConverter = (file: VertFile) => {
const converterName = file.conversionSettings.converter;
@@ -270,8 +300,6 @@
(f) => f.name === file.from,
)}
{@const isLarge = file.isLarge()}
- {@const size = file.size}
- {@const limit = $vertdSizeLimit}
{#if formatInfo && !formatInfo.fromSupported}
<div
class="h-full flex flex-col text-center justify-center text-failure"
@@ -283,37 +311,6 @@
{m["convert.errors.format_output_only"]()}
</p>
</div>
- {:else if size > limit && currentConverter.name === "vertd"}
- <div class="h-full flex flex-col justify-between">
- <div
- class="flex flex-col text-center justify-center text-failure"
- >
- <p class="font-body font-bold">
- {m["convert.errors.cant_convert"]()}
- </p>
- <p class="font-normal whitespace-pre-line">
- {@html sanitize(m["convert.errors.vertd.file_too_large.text"]({
- fileSize: formatBytes(size),
- limit: formatBytes(limit),
- }))}
- </p>
- </div>
- <div class="flex p-2 justify-center gap-4">
- <FormatDropdown
- {categories}
- from={file.from}
- bind:selected={file.to}
- onselect={(option) => handleSelect(option, file)}
- {file}
- />
- <button
- class="w-full p-2 text-center rounded-lg bg-accent text-black"
- onclick={() => ($fileSettings = file)}
- >
- {m["convert.errors.vertd.file_too_large.button"]()}
- </button>
- </div>
- </div>
{:else if isLarge && !file.supportsStreaming()}
<div
class="h-full flex flex-col text-center justify-center text-failure"