diff --git a/src/lib/components/functional/ConversionPanel.svelte b/src/lib/components/functional/ConversionPanel.svelte index 173cfc3..35165f3 100644 --- a/src/lib/components/functional/ConversionPanel.svelte +++ b/src/lib/components/functional/ConversionPanel.svelte @@ -4,43 +4,41 @@ import Panel from "../visual/Panel.svelte"; import Dropdown from "./Dropdown.svelte"; import Tooltip from "../visual/Tooltip.svelte"; + import ProgressBar from "../visual/ProgressBar.svelte"; + import { fade } from "$lib/animation"; + + const length = $derived(files.files.length); + const progress = $derived(files.files.filter((f) => f.result).length); - -
- - - {#if $isMobile} + - {:else} - + {#if $isMobile} - - {/if} -
-
-
-

Set all to

- {#if files.requiredConverters.length === 1} - - {@const supported = files.files[0]?.converters - .flatMap((c) => c.supportedFormats) - ?.filter((format) => format !== ".svg" && format !== ".heif")} - - files.files.forEach((f) => { - f.to = r; - f.result = null; - })} - options={supported || []} - /> - {:else} - - {/if} + {:else} + + + + {/if} +
+
+
+

Set all to

+ {#if files.requiredConverters.length === 1} + + {@const supported = files.files[0]?.converters + .flatMap((c) => c.supportedFormats) + ?.filter( + (format) => format !== ".svg" && format !== ".heif", + )} + + files.files.forEach((f) => { + f.to = r; + f.result = null; + })} + options={supported || []} + /> + {:else} + + {/if} +
+ {#if files.files.length > 50} +
+
+ {progress}/{length} +
+
+ +
+
+ {/if}
diff --git a/src/lib/store/index.svelte.ts b/src/lib/store/index.svelte.ts index aa64a95..104fd36 100644 --- a/src/lib/store/index.svelte.ts +++ b/src/lib/store/index.svelte.ts @@ -23,43 +23,49 @@ class Files { this.files.length === 0 ? false : this.files.every((f) => f.result), ); - private _addThumbnail = async (file: VertFile) => { - const isAudio = converters - .find((c) => c.name === "ffmpeg") - ?.supportedFormats?.includes(file.from.toLowerCase()); - const isVideo = converters - .find((c) => c.name === "vertd") - ?.supportedFormats?.includes(file.from.toLowerCase()); + private thumbnailQueue = new PQueue({ + concurrency: navigator.hardwareConcurrency || 4, + }); - try { - if (isAudio) { - // try to get the thumbnail from the audio via music-metadata - const { common } = await parseBlob(file.file, { - skipPostHeaders: true, - }); - const cover = selectCover(common.picture); - if (cover) { - const blob = new Blob([cover.data], { - type: cover.format, + private _addThumbnail = async (file: VertFile) => { + this.thumbnailQueue.add(async () => { + const isAudio = converters + .find((c) => c.name === "ffmpeg") + ?.supportedFormats?.includes(file.from.toLowerCase()); + const isVideo = converters + .find((c) => c.name === "vertd") + ?.supportedFormats?.includes(file.from.toLowerCase()); + + try { + if (isAudio) { + // try to get the thumbnail from the audio via music-metadata + const { common } = await parseBlob(file.file, { + skipPostHeaders: true, }); - file.blobUrl = URL.createObjectURL(blob); + const cover = selectCover(common.picture); + if (cover) { + const blob = new Blob([cover.data], { + type: cover.format, + }); + file.blobUrl = URL.createObjectURL(blob); + } + } else if (isVideo) { + // video + file.blobUrl = await this._generateThumbnailFromMedia( + file.file, + true, + ); + } else { + // image + file.blobUrl = await this._generateThumbnailFromMedia( + file.file, + false, + ); } - } else if (isVideo) { - // video - file.blobUrl = await this._generateThumbnailFromMedia( - file.file, - true, - ); - } else { - // image - file.blobUrl = await this._generateThumbnailFromMedia( - file.file, - false, - ); + } catch (e) { + error(["files"], e); } - } catch (e) { - error(["files"], e); - } + }); }; private async _generateThumbnailFromMedia( diff --git a/src/lib/types/file.svelte.ts b/src/lib/types/file.svelte.ts index f6ac1f3..a8b8b4d 100644 --- a/src/lib/types/file.svelte.ts +++ b/src/lib/types/file.svelte.ts @@ -29,7 +29,6 @@ export class VertFile { const converter = this.converters.filter((converter) => converter.supportedFormats.map((f) => supportedFormats.includes(f)), ); - console.log(this.converters, supportedFormats); return converter; }