1
0
mirror of https://github.com/sasjs/server.git synced 2026-01-04 21:30:05 +00:00
Files
server/src/utils/file.ts
Mihajlo Medjedovic 91c7c60dc9 style: lint
2021-10-19 09:19:03 +00:00

37 lines
1008 B
TypeScript

import path from 'path'
import { getRealPath, generateTimestamp } from '@sasjs/utils'
export const getTmpFolderPath = () =>
getRealPath(path.join(__dirname, '..', '..', 'tmp'))
export const getTmpFilesFolderPath = () =>
path.join(getTmpFolderPath(), 'files')
export const getTmpLogFolderPath = () => path.join(getTmpFolderPath(), 'logs')
export const getTmpWeboutFolderPath = () =>
path.join(getTmpFolderPath(), 'webouts')
export const getTmpSessionsFolderPath = () =>
path.join(getTmpFolderPath(), 'sessions')
export const generateUniqueFileName = (fileName: string, extension = '') =>
[
fileName,
'-',
Math.round(Math.random() * 100000),
'-',
new Date().getTime(),
extension
].join('')
export const addExtensionIfNotFound = (value: string, extension: string) => {
const valueSplit = value.split('.')
if (valueSplit.length < 2) return `.${extension}`
const hasExt = valueSplit[valueSplit.length - 1].length === 3
return !hasExt ? `.${extension}` : ''
}