Skip to content

armgit / VERT

Public Imported from GitHub
0

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

fix: better formatdropdown logic i think

JovannMC9bd518705c1c
diff --git a/messages/en.json b/messages/en.json
index 12eabe3..66c81f7 100644
--- a/messages/en.json
+++ b/messages/en.json
@@ -64,7 +64,7 @@
"fps": "FPS",
"transparency": "Transparency"
},
- "large_file_warning": "Due to browser / device limitations, video to audio conversion is disabled for this file as it is larger than {limit}GB. We recommend using Firefox or Safari for files of this size since they have less limitations.",
+ "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?",
diff --git a/src/lib/components/functional/ConversionPanel.svelte b/src/lib/components/functional/ConversionPanel.svelte
index d92b6ad..7e61826 100644
--- a/src/lib/components/functional/ConversionPanel.svelte
+++ b/src/lib/components/functional/ConversionPanel.svelte
@@ -13,6 +13,23 @@
const progress = $derived(files.files.filter((f) => f.result).length);
const manyFiles = $derived(files.files.length > 50);
const compactActions = $derived(manyFiles && !$isMobile);
+ const canSetAll = $derived.by(() => {
+ const [firstFile, ...otherFiles] = files.files;
+ if (!firstFile?.converters.length) return false;
+
+ const converterNames = new Set(
+ firstFile.converters.map((converter) => converter.name),
+ );
+ if (otherFiles.some((file) => !file.converters.length)) return false;
+
+ return otherFiles.every((file) => {
+ const names = new Set(
+ file.converters.map((converter) => converter.name),
+ );
+ return names.size === converterNames.size &&
+ [...converterNames].every((name) => names.has(name));
+ });
+ });
</script>
<Panel class="flex flex-col gap-4">
@@ -99,10 +116,9 @@
{m["convert.panel.set_all_to"]()}
</p>
<div class="w-[122px]">
- <!-- check if all files have the same converters -->
- <!-- video and audio together still have this dropdown disabled because audio has just ffmpeg (video has vertd & ffmpeg), even tho it can convert between video and audio -->
- {#if files.files.length > 0 && files.files.every((f) => f.converters.length) && files.files.every((f) => JSON.stringify(f.converters) === JSON.stringify(files.files[0].converters))}
+ {#if canSetAll}
<FormatDropdown
+ allowEmpty
onselect={(r) =>
files.files.forEach((f) => {
f.to = r;
diff --git a/src/lib/components/functional/FormatDropdown.svelte b/src/lib/components/functional/FormatDropdown.svelte
index 96bbbfc..c7b3169 100644
--- a/src/lib/components/functional/FormatDropdown.svelte
+++ b/src/lib/components/functional/FormatDropdown.svelte
@@ -24,6 +24,7 @@
disabled?: boolean;
dropdownSize?: "default" | "large" | "small";
file?: VertFile;
+ allowEmpty?: boolean;
};
let {
@@ -34,6 +35,7 @@
disabled,
dropdownSize = "default",
file,
+ allowEmpty = false,
}: Props = $props();
let open = $state(false);
@@ -287,6 +289,8 @@
getFormats(cat),
);
+ if (allowEmpty && !selected) return;
+
if (!allUnfilteredFormats.includes(selected)) {
if (allUnfilteredFormats.length > 0) {
selected = allUnfilteredFormats[0];
diff --git a/src/lib/store/index.svelte.ts b/src/lib/store/index.svelte.ts
index ae3b3cc..a886551 100644
--- a/src/lib/store/index.svelte.ts
+++ b/src/lib/store/index.svelte.ts
@@ -1,5 +1,10 @@
import { browser } from "$app/environment";
-import { byNative, converterCategories, converters } from "$lib/converters";
+import {
+ byNative,
+ categories,
+ converterCategories,
+ converters,
+} from "$lib/converters";
import type { Converter } from "$lib/converters/converter.svelte";
import { error, log } from "$lib/util/logger";
import { VertFile } from "$lib/types";
@@ -344,7 +349,12 @@ class Files {
this.files.push(new VertFile(file, format));
return;
}
- const to = converter.formatStrings().find((f) => f !== format);
+ const category = Object.keys(categories).find((name) =>
+ categories[name].formats.includes(format),
+ );
+ const to = category
+ ? categories[category].formats.find((f) => f !== format)
+ : converter.formatStrings().find((f) => f !== format);
if (!to) {
log(["files"], `no output format found for ${file.name}`);
return;
@@ -361,6 +371,7 @@ class Files {
ToastManager.add({
type: "warning",
message: m["convert.large_file_warning"]({
+ filename: file.name,
limit: (MAX_ARRAY_BUFFER_SIZE / GB).toFixed(2),
}),
durations: {