Skip to content

armgit / VERT

Public Imported from GitHub
0

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

feat: allow toggling file type detection

JovannMC9a4efbf7c8c0
diff --git a/messages/en.json b/messages/en.json
index 348a5c8..6e8ddc0 100644
--- a/messages/en.json
+++ b/messages/en.json
@@ -318,6 +318,12 @@
"description": "This will determine the name of the file on download, <b>not including the file extension.</b> You can put the following templates in the format, which will be replaced with the relevant information: <b>%name%</b> for the original file name, <b>%extension%</b> for the original file extension, <b>%datetime%</b> for the full ISO 8601 timestamp, <b>%date%</b> for the date, <b>%time%</b> for the time, and <b>%unix%</b> for the unix timestamp.",
"placeholder": "VERT_%name%"
},
+ "file_type_detection": {
+ "label": "File type detection",
+ "description": "Detect the actual format of a file from its contents instead of trusting the file extension. This helps with files that were renamed incorrectly, but may change the format of files you named on purpose.",
+ "enable": "Enable",
+ "disable": "Disable"
+ },
"default_format": {
"label": "Default conversion format",
"enable": "Enable",
diff --git a/src/lib/sections/settings/Conversion.svelte b/src/lib/sections/settings/Conversion.svelte
index 55e58f7..b5a64d2 100644
--- a/src/lib/sections/settings/Conversion.svelte
+++ b/src/lib/sections/settings/Conversion.svelte
@@ -48,6 +48,41 @@
type="text"
/>
</div>
+ <div class="flex flex-col gap-4">
+ <div class="flex flex-col gap-2">
+ <p class="text-base font-bold">
+ {m["settings.conversion.file_type_detection.label"]()}
+ </p>
+ <p class="text-sm font-normal text-muted">
+ {m["settings.conversion.file_type_detection.description"]()}
+ </p>
+ </div>
+ <div class="flex w-full gap-3">
+ <button
+ onclick={() => (settings.fileTypeDetection = true)}
+ class={clsx(
+ "btn flex flex-1 items-center justify-center rounded-lg p-4 text-black dynadark:text-white",
+ !$effects && "!scale-100",
+ settings.fileTypeDetection && "selected",
+ )}
+ >
+ <PlayIcon size="24" class="mr-2 inline-block" />
+ {m["settings.conversion.file_type_detection.enable"]()}
+ </button>
+
+ <button
+ onclick={() => (settings.fileTypeDetection = false)}
+ class={clsx(
+ "btn flex flex-1 items-center justify-center rounded-lg p-4 text-black dynadark:text-white",
+ !$effects && "!scale-100",
+ !settings.fileTypeDetection && "selected",
+ )}
+ >
+ <PauseIcon size="24" class="mr-2 inline-block" />
+ {m["settings.conversion.file_type_detection.disable"]()}
+ </button>
+ </div>
+ </div>
<div class="flex flex-col gap-4">
<button
onclick={() => (showAdvanced = !showAdvanced)}
diff --git a/src/lib/sections/settings/index.svelte.ts b/src/lib/sections/settings/index.svelte.ts
index 1551569..d41d293 100644
--- a/src/lib/sections/settings/index.svelte.ts
+++ b/src/lib/sections/settings/index.svelte.ts
@@ -22,6 +22,7 @@ export interface ISettings {
defaultFormat: DefaultFormats;
useDefaultFormat: boolean;
metadata: boolean;
+ fileTypeDetection: boolean; // detect the real format from file contents
plausible: boolean;
vertdURL: string;
vertdSpeed: ConversionSpeed; // videos (vertd)
@@ -44,6 +45,7 @@ export class Settings {
},
useDefaultFormat: false,
metadata: true,
+ fileTypeDetection: true,
plausible: true,
vertdURL: PUB_VERTD_URL,
vertdSpeed: "slow",
diff --git a/src/lib/types/file.svelte.ts b/src/lib/types/file.svelte.ts
index a9d0535..515fbfb 100644
--- a/src/lib/types/file.svelte.ts
+++ b/src/lib/types/file.svelte.ts
@@ -5,6 +5,7 @@ import { byNative, categories, converters } from "#lib/converters";
import type { Converter } from "#lib/converters/converter.svelte";
import { formatDuration } from "#lib/converters/converter.svelte";
import { m } from "#lib/paraglide/messages";
+import { Settings } from "#lib/sections/settings/index.svelte";
import { addDialog } from "#lib/store/DialogProvider";
import { MAX_ARRAY_BUFFER_SIZE } from "#lib/store/index.svelte";
import { conversionConcurrency } from "#lib/util/consts";
@@ -330,6 +331,8 @@ export class VertFile {
}
private async detectFileType() {
+ if (!Settings.instance.settings.fileTypeDetection) return;
+
try {
this.fileType = await fileTypeFromBuffer(
await this.file.slice(0, FILE_TYPE_HEADER_SIZE).arrayBuffer(),
@@ -403,7 +406,7 @@ export class VertFile {
this.converters = converters.filter((converter) =>
converter.formatStrings().includes(this.from),
);
-
+
// reset target format if previous format wasn't compatible (that was rewritten from this function)
if (!this.hasAvailableConverter(this.from, this.to))
this.to = this.defaultTargetFormat();