Skip to content

armgit / VERT

Public Imported from GitHub
0

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

feat: more file name format options (#241)

Maya8b965c4e771c
diff --git a/messages/en.json b/messages/en.json
index a6ed3e0..3df9e3d 100644
--- a/messages/en.json
+++ b/messages/en.json
@@ -206,7 +206,7 @@
"title": "Conversion",
"advanced_settings": "Advanced settings",
"filename_format": "File name format",
- "filename_description": "This will determine the name of the file on download, <b>not including the file extension.</b> You can put these 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, and <b>%date%</b> for a date string of when the file was converted.",
+ "filename_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%",
"default_format": "Default conversion format",
"default_format_enable": "Enable",
diff --git a/src/lib/types/file.svelte.ts b/src/lib/types/file.svelte.ts
index f2eaccf..7113499 100644
--- a/src/lib/types/file.svelte.ts
+++ b/src/lib/types/file.svelte.ts
@@ -483,11 +483,18 @@ export class VertFile {
const filenameFormat = settings.filenameFormat || "VERT_%name%";
const format = (name: string) => {
- const date = new Date().toISOString();
+ const now = new Date();
+ const iso = now.toISOString();
+ const date = iso.split("T")[0];
+ const time = iso.split("T")[1].split(".")[0].replace(/:/g, "-");
+ const unix = now.getTime().toString();
const baseName = this.file.name.replace(/\.[^/.]+$/, "");
const originalExtension = this.file.name.split(".").pop()!;
return name
+ .replace(/%datetime%/g, iso)
.replace(/%date%/g, date)
+ .replace(/%time%/g, time)
+ .replace(/%unix%/g, unix)
.replace(/%name%/g, baseName)
.replace(/%extension%/g, originalExtension);
};