The next-generation file converter. Open source, fully local* and free forever.
feat: conversion time logging, show file id in ui
JovannMCc3564acff85c
diff --git a/messages/en.json b/messages/en.jsonindex 9df7d73..65196c1 100644--- a/messages/en.json+++ b/messages/en.json@@ -111,6 +111,7 @@},"description": "Editing conversion settings for:","all_files": "all files",+ "file_id": "File ID: {id}","cancel": "Cancel","apply": "Apply","none": "No settings available for this format.",diff --git a/src/lib/components/functional/popups/SettingsModal.svelte b/src/lib/components/functional/popups/SettingsModal.svelteindex 24d0e73..36b624e 100644--- a/src/lib/components/functional/popups/SettingsModal.svelte+++ b/src/lib/components/functional/popups/SettingsModal.svelte@@ -301,6 +301,17 @@settings = {};}}/>+ {#if selectedFileId !== allFilesValue}+ <p class="text-xs text-muted mt-1">+ {m["convert.settings.file_id"]({+ id: targetFile.id ?? "N/A",+ })}+ </p>+ {:else}+ <p class="text-xs text-muted mt-1">+ {m["convert.settings.file_id"]({ id: "N/A" })}+ </p>+ {/if}</div><div class="flex items-center justify-between">diff --git a/src/lib/converters/converter.svelte.ts b/src/lib/converters/converter.svelte.tsindex c6e59b5..d1094ac 100644--- a/src/lib/converters/converter.svelte.ts+++ b/src/lib/converters/converter.svelte.ts@@ -16,6 +16,16 @@ export type WorkerStatus =| "partially-ready"| "error"; // actual failure during initialization+// human-readable conversion duration, e.g. "450ms" / "1.23s" / "1m 5.4s"+export function formatDuration(ms: number): string {+ if (ms < 1000) return `${Math.round(ms)}ms`;+ const seconds = ms / 1000;+ if (seconds < 60) return `${seconds.toFixed(2)}s`;+ const minutes = Math.floor(seconds / 60);+ const remaining = (seconds % 60).toFixed(1);+ return `${minutes}m ${remaining}s`;+}+export class FormatInfo {public name: string;diff --git a/src/lib/converters/ffmpeg/ffmpeg.svelte.ts b/src/lib/converters/ffmpeg/ffmpeg.svelte.tsindex 43badde..75c525d 100644--- a/src/lib/converters/ffmpeg/ffmpeg.svelte.ts+++ b/src/lib/converters/ffmpeg/ffmpeg.svelte.ts@@ -1,5 +1,5 @@import { VertFile } from "#lib/types";-import { Converter, FormatInfo } from "../converter.svelte";+import { Converter, FormatInfo, formatDuration } from "../converter.svelte";import { FFmpeg } from "@ffmpeg/ffmpeg";import { browser } from "$app/env";import { SvelteMap } from "svelte/reactivity";@@ -205,6 +205,8 @@ export class FFmpegConverter extends Converter {): Promise<VertFile> {this.trackConversion(input);if (!to.startsWith(".")) to = `.${to}`;+ this.log(`converting ${input.name} (${input.id}) to ${to}`);+ const startedAt = performance.now();const conversionSettings =Object.keys(settings).length > 4 // TODO: find better way to do this lmfao, rn we are just assuming all settings are present if there's at least 5 keys but ts bad@@ -275,7 +277,7 @@ export class FFmpegConverter extends Converter {}await ffmpeg.writeFile("input", buf);- this.log(`wrote ${input.name} to ffmpeg virtual fs`);+ this.log(`wrote ${input.name} (${input.id}) to ffmpeg virtual fs`);const specialHandled = await handleSpecialOutput(ffmpeg,@@ -309,9 +311,14 @@ export class FFmpegConverter extends Converter {const outputFileName =input.name.split(".").slice(0, -1).join(".") + to;- this.log(`read ${outputFileName} from ffmpeg virtual fs`);+ this.log(+ `read ${outputFileName} (${input.id}) from ffmpeg virtual fs`,+ );const outBuf = new Uint8Array(output).buffer.slice(0);+ this.log(+ `converted ${input.name} (${input.id}) to ${to} in ${formatDuration(performance.now() - startedAt)}`,+ );return new VertFile(new File([outBuf], outputFileName), to);}} finally {@@ -326,11 +333,13 @@ export class FFmpegConverter extends Converter {public async cancel(input: VertFile): Promise<void> {const ffmpeg = this.activeConversions.get(input.id);if (!ffmpeg) {- this.error(`no active conversion found for file ${input.name}`);+ this.error(+ `no active conversion found for file ${input.name} (${input.id})`,+ );return;}- this.log(`cancelling conversion for file ${input.name}`);+ this.log(`cancelling conversion for file ${input.name} (${input.id})`);ffmpeg.terminate();this.activeConversions.delete(input.id);@@ -371,7 +380,9 @@ export class FFmpegConverter extends Converter {// image sequences -> animated image // videoif (isImageSequence) {- this.log(`converting image sequence ${input.name} to ${to}`);+ this.log(+ `converting image sequence ${input.name} (${input.id}) to ${to}`,+ );const { extractZip } = await import("#lib/util/file");const entries = (await extractZip(input.file)).sort((a, b) =>@@ -464,7 +475,9 @@ export class FFmpegConverter extends Converter {// video to audioif (videoFormats.includes(inputFormat)) {- this.log(`Converting video ${input.from} to audio ${to}`);+ this.log(+ `Converting video ${input.from} to audio ${to} (${input.name} ${input.id})`,+ );return ["-i","input",@@ -481,7 +494,9 @@ export class FFmpegConverter extends Converter {// audio to videoif (videoFormats.includes(outputFormat)) {- this.log(`Converting audio ${input.from} to video ${to}`);+ this.log(+ `Converting audio ${input.from} to video ${to} (${input.name} ${input.id})`,+ );const hasAlbumArt = keepMetadata? await extractAlbumArt(ffmpeg)@@ -514,7 +529,9 @@ export class FFmpegConverter extends Converter {}// audio to audio- this.log(`Converting audio ${input.from} to audio ${to}`);+ this.log(+ `Converting audio ${input.from} to audio ${to} (${input.name} ${input.id})`,+ );const { audio: audioCodec } = getCodecs(to, isAlac);if (m4a && keepMetadata) extraArgs.push("-c:v", "copy"); // for album artdiff --git a/src/lib/converters/magick/magick.svelte.ts b/src/lib/converters/magick/magick.svelte.tsindex 14d43a7..d61ecac 100644--- a/src/lib/converters/magick/magick.svelte.ts+++ b/src/lib/converters/magick/magick.svelte.ts@@ -2,7 +2,7 @@ import { browser } from "$app/env";import { m } from "#lib/paraglide/messages";import { VertFile, type WorkerMessage } from "#lib/types";import MagickWorker from "#lib/workers/magick?worker&url";-import { Converter, FormatInfo } from "../converter.svelte";+import { Converter, FormatInfo, formatDuration } from "../converter.svelte";import { applyPriorities } from "../priority";import { imageFormats } from "./magick-automated";import {@@ -243,7 +243,8 @@ export class MagickConverter extends Converter {await this.init();this.trackConversion(input);- this.log(`converting ${input.name} to ${to}`);+ this.log(`converting ${input.name} (${input.id}) to ${to}`);+ const startedAt = performance.now();// handle converting from SVG manually because magick-wasm doesn't support itif (input.from === ".svg") {@@ -331,7 +332,9 @@ export class MagickConverter extends Converter {const res = await this.waitForMessage(worker);if (res.type === "finished") {- this.log(`converted ${input.name} to ${to}`);+ this.log(+ `converted ${input.name} (${input.id}) to ${to} in ${formatDuration(performance.now() - startedAt)}`,+ );return new VertFile(new File([res.output as unknown as BlobPart], input.name),res.zip ? ".zip" : to,@@ -353,11 +356,13 @@ export class MagickConverter extends Converter {public async cancel(input: VertFile): Promise<void> {const worker = this.activeConversions.get(input.id);if (!worker) {- this.error(`no active conversion found for file ${input.name}`);+ this.error(+ `no active conversion found for file ${input.name} (${input.id})`,+ );return;}- this.log(`cancelling conversion for file ${input.name}`);+ this.log(`cancelling conversion for file ${input.name} (${input.id})`);worker.terminate();this.activeConversions.delete(input.id);diff --git a/src/lib/converters/mediabunny/mediabunny.svelte.ts b/src/lib/converters/mediabunny/mediabunny.svelte.tsindex 044925d..24f302f 100644--- a/src/lib/converters/mediabunny/mediabunny.svelte.ts+++ b/src/lib/converters/mediabunny/mediabunny.svelte.ts@@ -25,7 +25,7 @@ import { registerMp3Encoder } from "@mediabunny/mp3-encoder";import { registerFlacEncoder } from "@mediabunny/flac-encoder";import { registerProresDecoder } from "@mediabunny/prores";import { SvelteMap } from "svelte/reactivity";-import { Converter, FormatInfo } from "../converter.svelte";+import { Converter, FormatInfo, formatDuration } from "../converter.svelte";import { applyPriorities } from "../priority";import { m } from "#lib/paraglide/messages";import type {@@ -350,6 +350,8 @@ export class MediabunnyConverter extends Converter {await this.init();this.trackConversion(file);+ this.log(`converting ${file.name} (${file.id}) to ${to}`);+ const startedAt = performance.now();const toFormat = to.startsWith(".") ? to.slice(1) : to;const originalName = file.file.name.split(".").slice(0, -1).join(".");const outputFilename = `${originalName}.${toFormat}`;@@ -433,7 +435,7 @@ export class MediabunnyConverter extends Converter {const isValid = conversion.isValid;const logMethod = isValid ? this.error : this.log;logMethod(- `${discardedTrackCount} discarded track(s) for ${file.name}:\n${discardedTrackList.join("\n")}`,+ `${discardedTrackCount} discarded track(s) for ${file.name} (${file.id}):\n${discardedTrackList.join("\n")}`,);ToastManager.add({type: isValid ? "warning" : "error", // warning if output created, error if nothing / conversion was completely invalid@@ -459,6 +461,10 @@ export class MediabunnyConverter extends Converter {await conversion.execute();+ this.log(+ `converted ${file.name} (${file.id}) to ${to} in ${formatDuration(performance.now() - startedAt)}`,+ );+if (streamTargetContext) {const streamedFile = await streamTargetContext.getFile();const result = new VertFile(streamedFile, toFormat);@@ -530,11 +536,13 @@ export class MediabunnyConverter extends Converter {public async cancel(input: VertFile): Promise<void> {const conversion = this.activeConversions.get(input.id);if (!conversion) {- this.error(`no active conversion found for file ${input.name}`);+ this.error(+ `no active conversion found for file ${input.name} (${input.id})`,+ );return;}- this.log(`cancelling conversion for file ${input.name}`);+ this.log(`cancelling conversion for file ${input.name} (${input.id})`);await conversion.cancel();}diff --git a/src/lib/converters/pandoc/pandoc.svelte.ts b/src/lib/converters/pandoc/pandoc.svelte.tsindex c5225d2..6e43a98 100644--- a/src/lib/converters/pandoc/pandoc.svelte.ts+++ b/src/lib/converters/pandoc/pandoc.svelte.ts@@ -1,5 +1,5 @@import { VertFile, type WorkerMessage } from "#lib/types";-import { Converter, FormatInfo } from "../converter.svelte";+import { Converter, FormatInfo, formatDuration } from "../converter.svelte";import { browser } from "$app/env";import PandocWorker from "#lib/workers/pandoc?worker&url";import { ToastManager } from "#lib/util/toast.svelte";@@ -42,6 +42,8 @@ export class PandocConverter extends Converter {await this.init();this.trackConversion(file);+ this.log(`converting ${file.name} (${file.id}) to ${to}`);+ const startedAt = performance.now();const worker = new Worker(PandocWorker, {type: "module",});@@ -104,6 +106,9 @@ export class PandocConverter extends Converter {}if (!to.startsWith(".")) to = `.${to}`;+ this.log(+ `converted ${file.name} (${file.id}) to ${to} in ${formatDuration(performance.now() - startedAt)}`,+ );return new VertFile(new File([result.output], file.name),result.isZip ? ".zip" : to,@@ -118,11 +123,13 @@ export class PandocConverter extends Converter {public async cancel(input: VertFile): Promise<void> {const worker = this.activeConversions.get(input.id);if (!worker) {- this.error(`no active conversion found for file ${input.name}`);+ this.error(+ `no active conversion found for file ${input.name} (${input.id})`,+ );return;}- this.log(`cancelling conversion for file ${input.name}`);+ this.log(`cancelling conversion for file ${input.name} (${input.id})`);worker.terminate();this.activeConversions.delete(input.id);diff --git a/src/lib/converters/vertd/vertd.svelte.ts b/src/lib/converters/vertd/vertd.svelte.tsindex cb6aac6..6d84e3e 100644--- a/src/lib/converters/vertd/vertd.svelte.ts+++ b/src/lib/converters/vertd/vertd.svelte.ts@@ -7,7 +7,7 @@ import {getVertdCustomHeaders,} from "#lib/sections/settings/vertdSettings.svelte";import { VertFile } from "#lib/types";-import { Converter, FormatInfo } from "../converter.svelte";+import { Converter, FormatInfo, formatDuration } from "../converter.svelte";import { applyPriorities } from "../priority";import { PUB_DISABLE_FAILURE_BLOCKS } from "$app/env/public";import { ToastManager } from "#lib/util/toast.svelte";@@ -654,6 +654,8 @@ export class VertdConverter extends Converter {): Promise<VertFile> {this.trackConversion(input);if (to.startsWith(".")) to = to.slice(1);+ this.log(`converting ${input.name} (${input.id}) to .${to}`);+ const startedAt = performance.now();const fileUpload = input;const apiUrl = await VertdInstance.instance.url();@@ -667,7 +669,9 @@ export class VertdConverter extends Converter {hash = await fileUpload.hash();if (this.blocked(hash)) {- this.log(`conversion blocked for file ${input.name}`);+ this.log(+ `conversion blocked for file ${input.name} (${input.id})`,+ );throw new Error(m["convert.errors.vertd.ratelimit"]({filename: input.name,@@ -692,7 +696,7 @@ export class VertdConverter extends Converter {if (uploadRes.sequence)this.log(- `received sequence upload for ${input.name} (kind: ${uploadRes.sequence.kind}, extension: ${uploadRes.sequence.extension}, entry: ${uploadRes.sequence.entry})`,+ `received sequence upload for ${input.name} (${input.id}) (kind: ${uploadRes.sequence.kind}, extension: ${uploadRes.sequence.extension}, entry: ${uploadRes.sequence.entry})`,);if (this.cancelledConversions.has(input.id))@@ -756,7 +760,7 @@ export class VertdConverter extends Converter {clearTimeout(connectTimeout);this.log(- `opened ws connection to vertd for file ${input.name}`,+ `opened ws connection to vertd for file ${input.name} (${input.id})`,);const msg: StartJobMessage = {type: "startJob",@@ -769,11 +773,13 @@ export class VertdConverter extends Converter {};ws.send(JSON.stringify(msg));this.log(JSON.stringify(msg, null, 2));- this.log(`sent startJob message for file ${input.name}`);+ this.log(+ `sent startJob message for file ${input.name} (${input.id})`,+ );};ws.onerror = () => {- this.error(`ws error for file ${input.name}`);+ this.error(`ws error for file ${input.name} (${input.id})`);rejectConversion(new Error("vertd websocket error"));};@@ -785,7 +791,7 @@ export class VertdConverter extends Converter {}this.error(- `ws closed unexpectedly for file ${input.name} (code: ${e.code})`,+ `ws closed unexpectedly for file ${input.name} (${input.id}) (code: ${e.code})`,);rejectConversion(new Error("vertd websocket closed unexpectedly"),@@ -807,7 +813,9 @@ export class VertdConverter extends Converter {return;}- this.log(`received message ${msg.type} for file ${input.name}`);+ this.log(+ `received message ${msg.type} for file ${input.name} (${input.id})`,+ );switch (msg.type) {case "progressUpdate": {const data = msg.data;@@ -821,7 +829,9 @@ export class VertdConverter extends Converter {}case "jobRetried": {- this.log(`job retrying for file ${input.name}`);+ this.log(+ `job retrying for file ${input.name} (${input.id})`,+ );ToastManager.add({type: "error",message: m["convert.errors.vertd.retry"]({@@ -832,7 +842,9 @@ export class VertdConverter extends Converter {}case "jobFinished": {- this.log(`job finished for file ${input.name}`);+ this.log(+ `job finished for file ${input.name} (${input.id})`,+ );try {if (settled) break;const url = `${apiUrl}/api/download/${msg.data.jobId}/${uploadRes.auth}`;@@ -855,14 +867,17 @@ export class VertdConverter extends Converter {apiUrl,);this.log(- `confirmed download for file ${input.name}`,+ `confirmed download for file ${input.name} (${input.id})`,);} catch (e) {this.error(`failed to confirm download: ${e}`);}+ this.log(+ `converted ${input.name} (${input.id}) to .${to} in ${formatDuration(performance.now() - startedAt)}`,+ );resolveConversion(- new VertFile(new File([res], input.name), to),+ new VertFile(new File([res], input.name), `.${to}`),);} catch (e) {// don't count cancellations as failures@@ -916,14 +931,16 @@ export class VertdConverter extends Converter {const activeUpload = this.activeUploads.get(input.id);if (activeUpload) {- this.log(`cancelling upload for file ${input.name}`);+ this.log(`cancelling upload for file ${input.name} (${input.id})`);activeUpload.abort();this.activeUploads.delete(input.id);}const activeDownload = this.activeDownloads.get(input.id);if (activeDownload) {- this.log(`cancelling download for file ${input.name}`);+ this.log(+ `cancelling download for file ${input.name} (${input.id})`,+ );activeDownload.abort();this.activeDownloads.delete(input.id);}@@ -931,11 +948,13 @@ export class VertdConverter extends Converter {const activeConversion = this.activeConversions.get(input.id);if (!activeConversion) {if (!activeUpload && !activeDownload)- this.error(`no active conversion found for file ${input.name}`);+ this.error(+ `no active conversion found for file ${input.name} (${input.id})`,+ );return;}- this.log(`cancelling conversion for file ${input.name}`);+ this.log(`cancelling conversion for file ${input.name} (${input.id})`);const { ws, jobId, token } = activeConversion;@@ -948,7 +967,9 @@ export class VertdConverter extends Converter {},};ws.send(JSON.stringify(cancelMsg));- this.log(`sent cancelJob message for file ${input.name}`);+ this.log(+ `sent cancelJob message for file ${input.name} (${input.id})`,+ );}ws.close();diff --git a/src/lib/converters/vips/vips.svelte.ts b/src/lib/converters/vips/vips.svelte.tsindex 97ff01c..953983f 100644--- a/src/lib/converters/vips/vips.svelte.ts+++ b/src/lib/converters/vips/vips.svelte.ts@@ -2,7 +2,7 @@ import { browser } from "$app/env";import { m } from "#lib/paraglide/messages";import { VertFile, type WorkerMessage } from "#lib/types";import VipsWorker from "#lib/workers/vips?worker&url";-import { Converter } from "../converter.svelte";+import { Converter, formatDuration } from "../converter.svelte";import { ToastManager } from "#lib/util/toast.svelte";import type {SettingDefinition,@@ -144,7 +144,8 @@ export class VipsConverter extends Converter {await this.init();this.trackConversion(input);- this.log(`converting ${input.name} to ${to}`);+ this.log(`converting ${input.name} (${input.id}) to ${to}`);+ const startedAt = performance.now();if (!this.isolated)throw new Error(@@ -174,7 +175,9 @@ export class VipsConverter extends Converter {const res = await this.waitForMessage(worker);if (res.type === "finished") {- this.log(`converted ${input.name} to ${to}`);+ this.log(+ `converted ${input.name} (${input.id}) to ${to} in ${formatDuration(performance.now() - startedAt)}`,+ );return new VertFile(new File([res.output as unknown as BlobPart], input.name),res.zip ? ".zip" : to,@@ -194,11 +197,13 @@ export class VipsConverter extends Converter {public async cancel(input: VertFile): Promise<void> {const worker = this.activeConversions.get(input.id);if (!worker) {- this.error(`no active conversion found for file ${input.name}`);+ this.error(+ `no active conversion found for file ${input.name} (${input.id})`,+ );return;}- this.log(`cancelling conversion for file ${input.name}`);+ this.log(`cancelling conversion for file ${input.name} (${input.id})`);worker.terminate();this.activeConversions.delete(input.id);diff --git a/src/lib/types/file.svelte.ts b/src/lib/types/file.svelte.tsindex f13ad99..4a87d6c 100644--- a/src/lib/types/file.svelte.ts+++ b/src/lib/types/file.svelte.ts@@ -1,5 +1,6 @@import { byNative, 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 { ToastManager } from "#lib/util/toast.svelte";import { addDialog } from "#lib/store/DialogProvider";@@ -386,10 +387,11 @@ export class VertFile {if (!this.retryingFallback) this.attemptedConverters.clear();this.cancelled = false;let res: VertFile | undefined;+ const startedAt = performance.now();try {log(["file", "convert"],- `Starting conversion for ${this.file.name} from ${this.from} to ${this.to}`,+ `Starting conversion for ${this.file.name} (${this.id}) from ${this.from} to ${this.to}`,);if (!this.converters.length) throw new Error("No converters found");@@ -524,6 +526,10 @@ export class VertFile {return;}this.result = res;+ log(+ ["file", "convert"],+ `finished conversion for ${this.file.name} (${this.id}) to ${this.to} in ${formatDuration(performance.now() - startedAt)}`,+ );if (this.fallbackToastId !== null) {ToastManager.remove(this.fallbackToastId);this.fallbackToastId = null;@@ -560,7 +566,7 @@ export class VertFile {log(["file", "convert"],- `retrying ${this.name} with next compatible converter: ${nextConverter.name}`,+ `retrying ${this.name} (${this.id}) with next compatible converter: ${nextConverter.name}`,);this.conversionSettings = {diff --git a/src/routes/convert/+page.svelte b/src/routes/convert/+page.svelteindex 69a9355..96f741e 100644--- a/src/routes/convert/+page.svelte+++ b/src/routes/convert/+page.svelte@@ -290,7 +290,7 @@{:else}<h2class="text-xl font-body overflow-hidden text-ellipsis whitespace-nowrap"- title={file.name}+ title={`${file.name} (${file.id})`}>{file.name}</h2>@@ -402,7 +402,7 @@<imgclass="object-cover w-full h-full"src={file.blobUrl}- alt={file.name}+ alt={`${file.name} (${file.id})`}/>{:else}{@const Icon = fileTypeBigIcons[fileType]}