pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 1 | import * as fs from 'fs'; |
2 | import * as crypto from 'crypto'; | ||||
3 | |||||
4 | export default function generateFileName(ending: string): string { | ||||
5 | let fileName = crypto.randomBytes(35).toString('hex'); | ||||
6 | fileName = fileName.replace(/([a-zA-Z0-9]{8})/g, '$1-'); | ||||
7 | if (fs.existsSync(`./${fileName}`)) { | ||||
8 | fileName = generateFileName(ending); | ||||
9 | } | ||||
10 | return fileName + '.' + ending; | ||||
11 | } |