UNPKG

private-key-manager

Version:
52 lines (51 loc) 1.49 kB
import fs from 'fs/promises'; import path from "path"; import config from '../../src/config.js'; import { logError } from './logger.js'; export function safeTimestamp() { const d = new Date(); const pad = (n) => n.toString().padStart(2, '0'); return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}_${pad(d.getHours())}-${pad(d.getMinutes())}-${pad(d.getSeconds())}`; } export function genBackupFileName(suffix = '.enc') { return `backup_${safeTimestamp()}${suffix}`; } export async function getBackupFilePath(filePath, suffix = '.enc') { let backupFile = filePath || path.join(config.BACKUP_DIR, genBackupFileName()); if (!backupFile.endsWith(suffix)) { backupFile += suffix; } await fs.mkdir(path.dirname(backupFile), { recursive: true }); return backupFile; } export async function fileExists(path) { try { await fs.access(path); return true; } catch (error) { logError('Error occured', { error }); return false; } } export function getLogDir() { return config.LOG_DIR; } export function getAuthFilePath() { return config.AUTH_FILE; } export function getDatabaseDir() { return config.DB_DIR; } export function getBackupDir() { return config.BACKUP_DIR; } export function getCredentialsFilePath() { return config.CREDENTIALS_FILE; } export function getTokenFilePath() { return config.TOKEN_FILE; } export function getTempDir() { return config.TEMP_DIR; }