print pdfs and send mails with ics file

This commit is contained in:
Julian Krauser 2024-12-30 14:47:00 +01:00
parent 5f827fb177
commit 728c4e05fa
12 changed files with 461 additions and 183 deletions

View file

@ -1,29 +1,43 @@
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
import { existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from "fs";
import { join } from "path";
import { readdirSync } from "fs";
export abstract class FileSystemHelper {
static createFolder(newFolder: string) {
const exportPath = join(process.cwd(), "export", newFolder);
static createFolder(...args: string[]) {
const exportPath = this.formatPath(...args);
if (!existsSync(exportPath)) {
mkdirSync(exportPath, { recursive: true });
}
}
static readFile(filePath: string) {
return readFileSync(join(process.cwd(), filePath), "utf8");
static readFile(...filePath: string[]) {
return readFileSync(this.formatPath(...filePath), "utf8");
}
static writeFile(filePath: string, file: any) {
writeFileSync(filePath, file);
static readFileasBase64(...filePath: string[]) {
return readFileSync(this.formatPath(...filePath), "base64");
}
static readTemplateFile(filePath: string) {
return readFileSync(process.cwd() + filePath, "utf8");
}
static writeFile(filePath: string, filename: string, file: any) {
this.createFolder(filePath);
let path = this.formatPath(filePath, filename);
writeFileSync(path, file);
}
static formatPath(...args: string[]) {
return join(process.cwd(), "export", ...args);
}
static normalizePath(...args: string[]) {
return join(...args);
}
static getFilesInDirectory(directoryPath: string, filetype?: string): string[] {
const fullPath = join(process.cwd(), directoryPath);
const fullPath = this.formatPath(directoryPath);
if (!existsSync(fullPath)) {
return [];
}
@ -31,4 +45,17 @@ export abstract class FileSystemHelper {
.filter((dirent) => !dirent.isDirectory() && (!filetype || dirent.name.endsWith(filetype)))
.map((dirent) => dirent.name);
}
static clearDirectoryByFiletype(directoryPath: string, filetype: string) {
const fullPath = this.formatPath(directoryPath);
if (!existsSync(fullPath)) {
return;
}
readdirSync(fullPath, { withFileTypes: true })
.filter((dirent) => !dirent.isDirectory() && dirent.name.endsWith(filetype))
.forEach((dirent) => {
const filePath = join(fullPath, dirent.name);
unlinkSync(filePath);
});
}
}