Files
XCDesktop/api/utils/tempDir.ts
2026-03-08 01:34:54 +08:00

24 lines
522 B
TypeScript

import { existsSync, mkdirSync } from 'fs'
import path from 'path'
import { PATHS } from '../config/paths.js'
let tempDir: string | null = null
export const getTempDir = (): string => {
if (!tempDir) {
tempDir = PATHS.TEMP_ROOT
if (!existsSync(tempDir)) {
mkdirSync(tempDir, { recursive: true })
}
}
return tempDir
}
export const getTempFilePath = (filename: string): string => {
return path.join(getTempDir(), filename)
}
export const ensureTempDir = (): string => {
return getTempDir()
}