Initial commit
This commit is contained in:
23
api/utils/tempDir.ts
Normal file
23
api/utils/tempDir.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
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()
|
||||
}
|
||||
Reference in New Issue
Block a user