The next-generation file converter. Open source, fully local* and free forever.
feat: vertd warning toast to modal, device/timeout mediabunny warnings, image settings updates
JovannMC83a77f30e9a5
diff --git a/messages/en.json b/messages/en.jsonindex 7e4bc3d..9bc390a 100644--- a/messages/en.json+++ b/messages/en.json@@ -67,10 +67,17 @@"large_file_warning": "Due to browser / device limitations, video to audio conversion is disabled for '{filename}' as it is larger than {limit}GB. We recommend using Firefox or Safari for files of this size since they have less limitations.","external_warning": {"title": "External server warning",- "text": "Converting {filename} with its current settings is not supported locally and requires server-side processing. Do you want to continue?",+ "text": "Converting '{filename}' with its current settings is not supported locally and requires server-side processing. Do you want to continue?","yes": "Convert on server","no": "Cancel conversion",- "dont_show_again": "Convert & don't show again"+ "dont_show_again": "Don't show again"+ },+ "slow_conversion": {+ "title": "Conversion may take a while",+ "device_body": "Your device may be slow at converting '{filename}' locally. You can continue to try local conversion, but you might have better luck switching to on-server conversion.",+ "timeout_body": "Converting '{filename}' is taking longer than expected. You can continue waiting, or try on-server conversion instead.",+ "continue": "Continue locally",+ "switch": "Continue on server"},"panel": {"convert_all": "Convert all",@@ -302,14 +309,15 @@}},"vertd": {- "title": "Server video conversion",+ "title": "Video conversion server","status": "status:","loading": "loading...","available": "available, size limit {sizeLimit}, commit id {commitId}","unavailable": "unavailable (is the url right?)","description": {- "main": "When possible, VERT converts videos locally in your browser, however some conversions may require the use of the <code>vertd</code> project, a server wrapper for FFmpeg. This allows you to convert videos through the convenience of VERT's web interface, while still being able to harness the power of your GPU to do it as quickly as possible.",- "info": "We host a public instance for your convenience, but it is quite easy to host your own on your PC or server if you know what you are doing. You can download the server binaries [vertd_link]here[/vertd_link] - the process of setting this up will become easier in the future, so stay tuned!"+ "main": "VERT converts videos securely by doing it locally in your browser; however some specific conversions may require connecting to, and using a <code>vertd</code> server. <code>vertd</code> allows you to convert videos using the server's GPU, and without the conversion limits of your browser, whilst still allowing you the convenience of VERT's web interface.",+ "info": "We host a public server for vertd for your convenience, but it is quite easy to host your own on your PC or server if you know what you are doing.",+ "more": "[vertd_link]Learn more[/vertd_link]"},"instance": {"label": "Instance",diff --git a/src/lib/components/functional/FancyInput.svelte b/src/lib/components/functional/FancyInput.svelteindex 7e416c0..ffdcf5c 100644--- a/src/lib/components/functional/FancyInput.svelte+++ b/src/lib/components/functional/FancyInput.svelte@@ -29,7 +29,7 @@}: Props = $props();</script>-<div class="relative flex w-full {className}">+<div class="relative flex {className}">{#if type === "checkbox"}<input{...rest}diff --git a/src/lib/components/functional/FormatDropdown.svelte b/src/lib/components/functional/FormatDropdown.svelteindex a42e12d..f1639cf 100644--- a/src/lib/components/functional/FormatDropdown.svelte+++ b/src/lib/components/functional/FormatDropdown.svelte@@ -660,7 +660,6 @@><FancyInputtype="checkbox"- class="!w-fit"bind:checked={imageSequence}/><label for="extract-sequence" class="text-sm">@@ -689,7 +688,6 @@><FancyInputtype="checkbox"- class="!w-fit"bind:checked={imageSequenceTransparency}disabled={!imageSequence}/>diff --git a/src/lib/components/functional/popups/ServerUploadWarning.svelte b/src/lib/components/functional/popups/ServerUploadWarning.svelteindex a16978c..7f2219e 100644--- a/src/lib/components/functional/popups/ServerUploadWarning.svelte+++ b/src/lib/components/functional/popups/ServerUploadWarning.svelte@@ -1,47 +1,39 @@<script lang="ts" module>+ import type { DialogProps } from "$lib/store/DialogProvider";+export interface ServerUploadWarningProps {filename: string;- onProceed: () => void;- onCancel: () => void;- onDontShowAgain: () => void;+ onDontShowAgainChange: (value: boolean) => void;}++ export type Props = DialogProps<ServerUploadWarningProps>;</script><script lang="ts">import { m } from "$lib/paraglide/messages";- import type { ToastProps } from "$lib/util/toast.svelte";-- const toast: ToastProps<ServerUploadWarningProps> = $props();+ import FancyInput from "../FancyInput.svelte";- export const title = m["convert.external_warning.title"]();+ let { additional }: Props = $props();+ let dontShowAgain = $state(true);</script><div class="flex flex-col gap-4"><p class="text-black">{m["convert.external_warning.text"]({- filename: toast.additional.filename,+ filename: additional.filename,})}</p>- <div class="flex flex-col gap-2">- <button- onclick={toast.additional.onDontShowAgain}- class="btn rounded-lg h-fit py-2 w-full bg-accent-blue text-black"- >- {m["convert.external_warning.dont_show_again"]()}- </button>- <div class="flex gap-4">- <button- onclick={toast.additional.onCancel}- class="btn rounded-lg h-fit py-2 w-full"- >- {m["convert.external_warning.no"]()}- </button>- <button- onclick={toast.additional.onProceed}- class="btn rounded-lg h-fit py-2 w-full bg-accent-red-alt text-white"- >- {m["convert.external_warning.yes"]()}- </button>- </div>+ <div class="flex items-center gap-2 text-black">+ <FancyInput+ type="checkbox"+ checked={dontShowAgain}+ onchange={(event: Event) => {+ const checked = (event.currentTarget as HTMLInputElement)+ .checked;+ dontShowAgain = checked;+ additional.onDontShowAgainChange(checked);+ }}+ />+ <span>{m["convert.external_warning.dont_show_again"]()}</span></div></div>diff --git a/src/lib/components/functional/popups/SettingsModal.svelte b/src/lib/components/functional/popups/SettingsModal.svelteindex d49eecb..4ca5f07 100644--- a/src/lib/components/functional/popups/SettingsModal.svelte+++ b/src/lib/components/functional/popups/SettingsModal.svelte@@ -86,12 +86,20 @@let activeTab = $state("Converter");let availableCategories = $state<SettingCategories>({});- const settingTabs = $derived.by((): SettingCategories => ({- ...(targetFile && getAvailableConverters(targetFile).length > 1- ? { Converter: [] }- : {}),- ...availableCategories,- }));+ const settingTabs = $derived.by((): SettingCategories => {+ const categories = Object.fromEntries(+ Object.entries(availableCategories).filter(+ ([, settings]) => settings.length > 0,+ ),+ );++ return {+ ...(targetFile && getAvailableConverters(targetFile).length > 1+ ? { Converter: [] }+ : {}),+ ...categories,+ };+ });const getTabLabel = (tab: string) => {const key = tab.toLowerCase();@@ -305,10 +313,15 @@{:else if availableCategories[activeTab]?.length}<div class="grid grid-cols-2 gap-4">{#each availableCategories[activeTab] as setting (setting.key)}+ {@const fullWidth = setting.forceFullWidth || setting.type === "boolean"}<div- class={setting.forceFullWidth- ? "col-span-2 min-w-0"- : "flex min-w-0 flex-col gap-2"}+ class={clsx(+ "flex min-w-0 gap-2",+ fullWidth && "col-span-2",+ setting.type === "boolean"+ ? "flex-row justify-between"+ : "flex-col",+ )}><p class="text-sm font-bold">{setting.label}</p>{#if setting.description}diff --git a/src/lib/components/functional/popups/SlowConversionToast.svelte b/src/lib/components/functional/popups/SlowConversionToast.sveltenew file mode 100644index 0000000..2e8e98e--- /dev/null+++ b/src/lib/components/functional/popups/SlowConversionToast.svelte@@ -0,0 +1,34 @@+<script lang="ts">+ import { m } from "$lib/paraglide/messages";++ type Additional = {+ filename: string;+ converter: string;+ reason: "device" | "timeout";+ onSwitch: () => void | Promise<void>;+ onContinue: () => void;+ };++ let { additional }: { additional: Additional } = $props();++ export const title = m["convert.slow_conversion.title"]();+</script>++<div class="flex flex-col gap-4">+ <p class="text-black">+ {additional.reason === "device"+ ? m["convert.slow_conversion.device_body"]({ filename: additional.filename })+ : m["convert.slow_conversion.timeout_body"]({ filename: additional.filename })}+ </p>+ <div class="flex gap-4">+ <button class="btn rounded-lg h-fit py-2 w-full" onclick={additional.onContinue}>+ {m["convert.slow_conversion.continue"]()}+ </button>+ <button+ class="btn rounded-lg h-fit py-2 w-full bg-accent-blue text-black"+ onclick={() => additional.onSwitch()}+ >+ {m["convert.slow_conversion.switch"]({ converter: additional.converter })}+ </button>+ </div>+</div>diff --git a/src/lib/components/layout/Dialogs.svelte b/src/lib/components/layout/Dialogs.svelteindex c902203..65955eb 100644--- a/src/lib/components/layout/Dialogs.svelte+++ b/src/lib/components/layout/Dialogs.svelte@@ -26,7 +26,7 @@easing: quintOut,}}>- {#each dialogList as dialog, i}+ {#each dialogList as dialog, i (dialog.id)}{#if i === 0}<Dialog {...dialog} />{/if}diff --git a/src/lib/components/visual/Toast.svelte b/src/lib/components/visual/Toast.svelteindex b61cfad..ed0586c 100644--- a/src/lib/components/visual/Toast.svelte+++ b/src/lib/components/visual/Toast.svelte@@ -83,7 +83,11 @@"font-normal": !title,})}>- {@html sanitize((title || message) as string)}+ {#if title && typeof title === "string"}+ {@html sanitize(title)}+ {:else if message && typeof message === "string"}+ {@html sanitize(message)}+ {/if}</p></div><buttondiff --git a/src/lib/converters/magick/magick-settings.ts b/src/lib/converters/magick/magick-settings.tsnew file mode 100644index 0000000..c4b810c--- /dev/null+++ b/src/lib/converters/magick/magick-settings.ts@@ -0,0 +1,73 @@+export const formatsWithoutTransparency = new Set([+ "jpg",+ "jpeg",+ "jfif",+ "jpe",+ "pjpeg",+ "gif87",+ "cin",+ "fax",+ "fit",+ "fits",+ "fts",+ "g3",+ "g4",+ "hrz",+ "jps",+ "mono",+ "otb",+ "pcd",+ "pcds",+ "pgx",+ "rgf",+ "six",+ "sixel",+ "wbmp",+ "xbm",+]);++export const formatsWithoutMetadataRemoval = new Set([+ // Raw pixel/sample formats+ "a",+ "b",+ "bgr",+ "bgra",+ "bgro",+ "cmyk",+ "cmyka",+ "gray",+ "graya",+ "rgb",+ "rgba",+ "rgbo",+ "uyvy",+ "ycbcr",+ "ycbcra",+ "yuv",++ // Simple/raw image representations+ "farbfeld",+ "ff",+ "fl32",+ "mono",+ "otb",+ "pgx",+ "rgf",++ // Terminal / display representations+ "hrz",+ "six",+ "sixel",++ // Simple bitmap formats+ "ubrl",+ "ubrl6",+ "wbmp",+ "xbm",++ // Texture / lookup / raw data formats+ "dxt1",+ "dxt5",+ "map",+ "pal",+]);diff --git a/src/lib/converters/magick/magick.svelte.ts b/src/lib/converters/magick/magick.svelte.tsindex fb5448e..a9fdcfd 100644--- a/src/lib/converters/magick/magick.svelte.ts+++ b/src/lib/converters/magick/magick.svelte.ts@@ -5,6 +5,10 @@ import { VertFile, type WorkerMessage } from "$lib/types";import MagickWorker from "$lib/workers/magick?worker&url";import { Converter, FormatInfo } from "../converter.svelte";import { imageFormats } from "./magick-automated";+import {+ formatsWithoutMetadataRemoval,+ formatsWithoutTransparency,+} from "./magick-settings";import { Settings } from "$lib/sections/settings/index.svelte";import magickWasm from "@imagemagick/magick-wasm/magick.wasm?url";import { ToastManager } from "$lib/util/toast.svelte";@@ -130,32 +134,14 @@ export class MagickConverter extends Converter {const global = Settings.instance.settings;const settings: SettingDefinition[] = [];- let supportsMetadata = true;- let supportsTransparency = true;+ const outputFormat = input.to.replace(/^\./, "").toLowerCase();+ const supportsMetadata =+ !formatsWithoutMetadataRemoval.has(outputFormat);+ const supportsTransparency =+ !formatsWithoutTransparency.has(outputFormat);const toIcon = input.to === ".ico";- // TODO: surely there's a better way to do this lol- switch (input.from) {- case ".jpg":- case ".jpeg":- case ".jfif":- supportsTransparency = false;- break;- }-- switch (input.to) {- case ".ico":- supportsMetadata = false;- break;-- case ".jpg":- case ".jpeg":- case ".jfif":- supportsTransparency = false;- break;- }-const quality: SettingDefinition = {key: "quality",label: m["convert.settings.image.quality.label"](),@@ -231,8 +217,15 @@ export class MagickConverter extends Converter {// resize, crop, rotate - prob want a uireturn {- Image: settings.filter((setting) => setting.key !== "metadata"),- General: [metadata],+ // put all boolean types (checkboxes) at end+ Image: settings+ .filter((setting) => setting.key !== "metadata")+ .sort(+ (a, b) =>+ Number(a.type === "boolean") -+ Number(b.type === "boolean"),+ ),+ General: supportsMetadata ? [metadata] : [],};}diff --git a/src/lib/converters/mediabunny/mediabunny.svelte.ts b/src/lib/converters/mediabunny/mediabunny.svelte.tsindex b3c6b24..c998dfb 100644--- a/src/lib/converters/mediabunny/mediabunny.svelte.ts+++ b/src/lib/converters/mediabunny/mediabunny.svelte.ts@@ -32,8 +32,10 @@ import type {SettingCategories,ConversionSettings,} from "$lib/types/conversion-settings";+import { isMobile } from "$lib/store/index.svelte";import { ToastManager } from "$lib/util/toast.svelte";import { browser } from "$app/environment";+import { get } from "svelte/store";// codec compatibility stuff, based on mediabunny's docs// https://mediabunny.dev/guide/supported-formats-and-codecs#compatibility-table@@ -434,6 +436,26 @@ export class MediabunnyConverter extends Converter {this.activeConversions.set(file.id, conversion);+ const mobile = get(isMobile);+ const deviceMemory = (navigator as Navigator & { deviceMemory?: number })+ .deviceMemory;+ const hardwareConcurrency = navigator.hardwareConcurrency || 3; // if we can't detect it, just fall back to something that will definitely warn+ const likelySlowDevice =+ (mobile && hardwareConcurrency <= 4) ||+ hardwareConcurrency <= 4 ||+ (deviceMemory !== undefined && deviceMemory <= 4);+ if (likelySlowDevice) void file.slowConversionOffer("device");+ this.log(`hardwareConcurrency: ${hardwareConcurrency}`)+ this.log(`deviceMemory: ${deviceMemory}`)+ this.log(`mobile: ${mobile}`)++ const slowConversionTimer: ReturnType<typeof setTimeout> = setTimeout(+ () => {+ void file.slowConversionOffer("timeout");+ },+ 60 * 1000,+ );+this.log(`videoConfig: ${JSON.stringify(videoConfig)}`);this.log(`audioConfig: ${JSON.stringify(audioConfig)}`);@@ -484,6 +506,7 @@ export class MediabunnyConverter extends Converter {}throw err;} finally {+ if (slowConversionTimer) clearTimeout(slowConversionTimer);this.activeConversions.delete(file.id);}diff --git a/src/lib/sections/settings/Vertd.svelte b/src/lib/sections/settings/Vertd.svelteindex c00bb11..8167314 100644--- a/src/lib/sections/settings/Vertd.svelte+++ b/src/lib/sections/settings/Vertd.svelte@@ -91,11 +91,14 @@<p class="text-sm text-muted font-normal">{@html sanitize(m["settings.vertd.description.main"]())}</p>+ <p class="text-sm text-muted font-normal">+ {@html sanitize(m["settings.vertd.description.info"]())}+ </p><p class="text-sm text-muted font-normal">{@html sanitize(link("vertd_link",- m["settings.vertd.description.info"](),+ m["settings.vertd.description.more"](),GITHUB_URL_VERTD,),)}diff --git a/src/lib/types/file.svelte.ts b/src/lib/types/file.svelte.tsindex 6863709..85ad2e1 100644--- a/src/lib/types/file.svelte.ts+++ b/src/lib/types/file.svelte.ts@@ -2,9 +2,11 @@ import { byNative, converters } from "$lib/converters";import type { Converter } from "$lib/converters/converter.svelte";import { m } from "$lib/paraglide/messages";import { ToastManager } from "$lib/util/toast.svelte";+import { addDialog } from "$lib/store/DialogProvider";import type { Component } from "svelte";import { MAX_ARRAY_BUFFER_SIZE } from "$lib/store/index.svelte";import FallbackToast from "$lib/components/functional/popups/FallbackToast.svelte";+import SlowConversionToast from "$lib/components/functional/popups/SlowConversionToast.svelte";import ServerUploadWarning from "$lib/components/functional/popups/ServerUploadWarning.svelte";import type {ConversionSettings,@@ -18,6 +20,78 @@ import { fileTypeFromBuffer } from "file-type";const LARGE_FILE = 2 * 1024 * 1024 * 1024; // 2GB+type ServerWarningRequest = {+ filename: string;+ resolve: (shouldProceed: boolean) => void;+};++const serverWarningQueue: ServerWarningRequest[] = [];+let serverWarningActive = false;++const processServerWarningQueue = () => {+ if (serverWarningActive) return;++ if (localStorage.getItem("acceptedExternalWarning") === "true") {+ while (serverWarningQueue.length)+ serverWarningQueue.shift()?.resolve(true);+ return;+ }++ const request = serverWarningQueue.shift();+ if (!request) return;++ serverWarningActive = true;+ let resolved = false;++ const finish = (shouldProceed: boolean, dontShowAgain = false) => {+ if (resolved) return;+ resolved = true;+ serverWarningActive = false;++ if (dontShowAgain) {+ localStorage.setItem("acceptedExternalWarning", "true");+ log(+ ["file", "warning"],+ `external upload warning preference saved: ${localStorage.getItem("acceptedExternalWarning")}`,+ );+ }+ request.resolve(shouldProceed);++ if (dontShowAgain) {+ while (serverWarningQueue.length)+ serverWarningQueue.shift()?.resolve(true);+ }++ queueMicrotask(processServerWarningQueue);+ };++ let dontShowAgain = false;+ const additional = {+ filename: request.filename,+ onDontShowAgainChange: (value: boolean) => {+ dontShowAgain = value;+ },+ };++ addDialog(+ m["convert.external_warning.title"](),+ // eslint-disable-next-line @typescript-eslint/no-explicit-any+ ServerUploadWarning as any,+ [+ {+ text: m["convert.external_warning.no"](),+ action: () => finish(false),+ },+ {+ text: m["convert.external_warning.yes"](),+ action: () => finish(true, dontShowAgain),+ },+ ],+ "warning",+ additional,+ );+};+export type UnavailableReasons = "vertd-size-limit" | "other-reason"; // find more stuff to addexport class VertFile {@@ -44,9 +118,9 @@ export class VertFile {public converters: Converter[] = [];private fallbackToastId: number | null = null;+ private slowConversionToastId: number | null = null;private attemptedConverters = new Set<string>();private retryingFallback = false;- private vertdWarningToastId: number | null = null;private postDownload: (() => Promise<void>) | null = null;private activeConverterName: string | null = null;@@ -373,6 +447,10 @@ export class VertFile {ToastManager.remove(this.fallbackToastId);this.fallbackToastId = null;}+ if (this.slowConversionToastId !== null) {+ ToastManager.remove(this.slowConversionToastId);+ this.slowConversionToastId = null;+ }} catch (err) {if (!this.cancelled) this.toastErr(err);@@ -445,41 +523,11 @@ export class VertFile {private async confirmServerWarning(converter: Converter): Promise<boolean> {if (converter.name !== "vertd") return true;if (localStorage.getItem("acceptedExternalWarning") === "true")- return true;+ return Promise.resolve(true);return new Promise((resolve) => {- let resolved = false;-- const finish = (shouldProceed: boolean) => {- if (resolved) return;- resolved = true;- if (this.vertdWarningToastId !== null)- ToastManager.remove(this.vertdWarningToastId);- this.vertdWarningToastId = null;- resolve(shouldProceed);- };-- if (this.vertdWarningToastId !== null)- ToastManager.remove(this.vertdWarningToastId);-- this.vertdWarningToastId = ToastManager.add({- type: "warning",- disappearing: false,- message: ServerUploadWarning,- additional: {- filename: this.file.name,- onProceed: () => {- finish(true);- },- onCancel: () => {- finish(false);- },- onDontShowAgain: () => {- localStorage.setItem("acceptedExternalWarning", "true");- finish(true);- },- },- });+ serverWarningQueue.push({ filename: this.file.name, resolve });+ processServerWarningQueue();});}@@ -577,6 +625,52 @@ export class VertFile {return new VertFile(resultFile, ".zip");}+ public slowConversionOffer(reason: "device" | "timeout") {+ if (+ !this.processing ||+ this.activeConverterName !== "mediabunny" ||+ this.slowConversionToastId !== null+ )+ return;++ const serverConverter = this.findConverters([this.from, this.to]).find(+ (converter) => converter.name === "vertd",+ );+ if (!serverConverter) return;++ const removeToast = () => {+ if (this.slowConversionToastId !== null)+ ToastManager.remove(this.slowConversionToastId);+ this.slowConversionToastId = null;+ };++ this.slowConversionToastId = ToastManager.add({+ type: "warning",+ disappearing: false,+ message: SlowConversionToast,+ additional: {+ filename: this.file.name,+ converter: serverConverter.name,+ reason,+ onContinue: removeToast,+ onSwitch: async () => {+ removeToast();+ await this.cancel();+ this.conversionSettings = {+ ...this.conversionSettings,+ converter: serverConverter.name,+ };+ this.retryingFallback = true;+ try {+ await this.convert();+ } finally {+ this.retryingFallback = false;+ }+ },+ },+ });+ }+public async cancel() {if (!this.processing) return;const selectedConverter = this.conversionSettings.converter;