blob: 3f191282010a6dff8d9e216d7be9430b0b690047 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
import { v4 as uuidV4 } from 'uuid';
import { writeFileSync } from 'fs';
export function saveImg(img: string): string
{
if(!img) return null;
let filename = `/images/${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];
}
|