import { v4 as uuidV4 } from 'uuid'; import { writeFileSync, mkdir } from 'fs'; export function saveImg(img: string): string { if(!img) return null; let filename = `${uuidV4()}.${img.split(';')[0].split('/')[1]}`; let path; if(process.env.DEV) { path = `/public/${filename}`; } else { path = `/dist/client/${filename}`; } writeFileSync(path, img.split(',')[1], "base64"); return filename; } export function getImgType(img: string): string { if(!img) return null; return img.split('/')[0].split(':')[1]; }