From 1d7671ce54d55f584a2997638de0e2af3589ca10 Mon Sep 17 00:00:00 2001 From: JovannMC Date: Wed, 13 Nov 2024 19:58:36 +0300 Subject: [PATCH] Add filename options Adds a new option "Output filename": - "Default" uses the current default (VERT-Converted_date) - "Original" uses the original filename zip file is unchanged --- src/lib/store/index.svelte.ts | 2 ++ src/routes/convert/+page.svelte | 32 ++++++++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/lib/store/index.svelte.ts b/src/lib/store/index.svelte.ts index c837707..f2119f8 100644 --- a/src/lib/store/index.svelte.ts +++ b/src/lib/store/index.svelte.ts @@ -18,3 +18,5 @@ class Files { } export const files = new Files(); + +export const outputFilenameOption = ['default', 'original']; diff --git a/src/routes/convert/+page.svelte b/src/routes/convert/+page.svelte index 29fd5e4..89a843e 100644 --- a/src/routes/convert/+page.svelte +++ b/src/routes/convert/+page.svelte @@ -5,7 +5,7 @@ import ProgressiveBlur from "$lib/components/visual/effects/ProgressiveBlur.svelte"; import { converters } from "$lib/converters"; import type { Converter } from "$lib/converters/converter.svelte"; - import { files } from "$lib/store/index.svelte"; + import { files, outputFilenameOption } from "$lib/store/index.svelte"; import clsx from "clsx"; import { ArrowRight, XIcon } from "lucide-svelte"; import { onMount } from "svelte"; @@ -45,6 +45,9 @@ const allConvertersReady = $derived( convertersRequired.every((c) => c.ready), ); + + // Options + let outputFilename = $state(outputFilenameOption[0]); onMount(() => { isSm = window.innerWidth < 640; @@ -107,6 +110,7 @@ }; const downloadAll = async () => { + const date = new Date().toISOString(); const dlFiles: any[] = []; for (let i = 0; i < files.files.length; i++) { const file = files.files[i]; @@ -124,6 +128,9 @@ if (files.files.length === 0) return; if (files.files.length === 1) { // download the image only + const filename = outputFilename === "default" + ? `VERT-Converted_${date}` + : files.files[0].file.name.replace(/\.[^/.]+$/, ""); const blob = URL.createObjectURL( new Blob([dlFiles[0].input], { type: files.files[0].to.slice(1), @@ -131,9 +138,7 @@ ); const a = document.createElement("a"); a.href = blob; - a.download = `VERT-Converted_${new Date().toISOString()}${ - files.files[0].to - }`; + a.download = `${filename}${files.files[0].to}`; a.click(); URL.revokeObjectURL(blob); a.remove(); @@ -177,6 +182,25 @@ >

Options

+
+

Output filename

+
+
+ outputFilename = o} + /> +
+
+

Set all target formats