-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelper.ts
More file actions
63 lines (60 loc) · 1.79 KB
/
helper.ts
File metadata and controls
63 lines (60 loc) · 1.79 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
export const encodeBase64 = (str: string): string => {
const bytes = new TextEncoder().encode(str);
const binString = String.fromCodePoint(...bytes);
return btoa(binString);
};
export const decodeBase64 = (base64: string): string => {
const binString = atob(base64);
const bytes = Uint8Array.from(binString, (char) => char.codePointAt(0)!);
return new TextDecoder().decode(bytes);
};
export const generateQR = async (data: string): Promise<string> => {
const response = await fetch(`https://api.qrcode-monkey.com/qr/custom`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
data,
config: {
body: "square",
eye: "frame1",
eyeBall: "ball14",
erf1: ["fh"],
erf2: [],
erf3: ["fh", "fv"],
brf1: [],
brf2: [],
brf3: [],
bodyColor: "#000000",
bgColor: "#FFFFFF",
eye1Color: "#009D4F",
eye2Color: "#009D4F",
eye3Color: "#009D4F",
eyeBall1Color: "#FCC714",
eyeBall2Color: "#FCC714",
eyeBall3Color: "#FCC714",
gradientColor1: "#009D4F",
gradientColor2: "#009D4F",
gradientType: "linear",
gradientOnEyes: false,
logo: "https://i.ibb.co/WpMCTdZD/no-text.png", // logo f-code
logoMode: "clean",
},
size: 2000,
download: "imageUrl",
file: "png",
}),
});
const result: { imageUrl: string } = await response.json();
return result.imageUrl;
};
export const downloadQR = async (url: string, filename: string) => {
try {
const response = await fetch(url);
const bytesWritten = await Bun.write(`qrcode/${filename}`, response);
return bytesWritten;
} catch (error) {
console.error("Lỗi khi tải QR code:", error);
}
};