blob: 98240a1b5a99c078e6f0b47addfab77ab1ca7bb3 [file] [log] [blame]
pineafan32767212022-03-14 21:27:39 +00001import * as fs from 'fs';
2import * as crypto from 'crypto';
3
4export 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}