This commit is contained in:
marzban-dev
2025-03-22 23:43:49 +03:30
parent 852a09c298
commit 2106f3f40b
56 changed files with 198 additions and 161 deletions
+19
View File
@@ -1,3 +1,6 @@
import fs from "fs/promises";
import path from "path";
export const dateFormatter = (date: string | undefined) => {
const formattedDate = useTimeAgo(date!);
return formattedDate.value;
@@ -77,3 +80,19 @@ export const isImage = (name: string | undefined) => {
}
return false;
};
// Ensure Exist
export const ensureFileExists = async (filePath: string, initialContent = "") => {
try {
await fs.access(filePath);
} catch (error) {
const err = error as any;
if (err.code === "ENOENT") {
await fs.mkdir(path.dirname(filePath), { recursive: true });
await fs.writeFile(filePath, initialContent, "utf-8");
} else {
throw err;
}
}
};