feat: more file name format options (#241)

adds %datetime%, %time%, %unix%

fixes #241
This commit is contained in:
Maya 2026-03-20 10:42:43 +03:00
parent 85f4ead847
commit 8b965c4e77
2 changed files with 9 additions and 2 deletions

View File

@ -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",

View File

@ -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);
};