-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathqr.js
79 lines (69 loc) · 1.77 KB
/
qr.js
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
var exports = module.exports = {};
const qr = require('qrcode')
const fs = require('fs-extra')
const sharp = require('sharp')
const db = require('./db.js')
async function checkQRDir() {
try {
await fs.ensureDir("./qr")
console.log('qr directory created')
} catch (err) {
console.error(err)
}
}
checkQRDir()
// adds a logo to the middle of the qr code, cuz it looks cool...
async function addLogo(pathToFile, pathToLogoQR) {
try {
var image = await sharp(pathToFile)
.composite([{ input: './qr/syscoin.png', blend: 'atop'}])
await image.toFile(pathToLogoQR)
fs.remove(pathToFile)
return pathToLogoQR
} catch (error) {
console.log("Error adding logo to QR")
console.log(error)
return null
}
}
// returns the qr code with the deposit address in the given user's profile
exports.getQR = async function(userID) {
try {
var profile = await db.getProfile(userID)
} catch (error) {
console.log(error)
return
}
var pathToFile = `./qr/${userID}qr.png`
var pathToLogoQR = `./qr/${userID}.png`
var qrFile
try {
qrFile = await qr.toFile(pathToFile, profile.address, {
color: {
dark: "#000000",
light: "#ffffff"
}
})
} catch (error) {
console.log(error)
return null
}
return addLogo(pathToFile, pathToLogoQR)
}
exports.getNevmQR = async function (userId) {
try {
const pathToFile = `./qr/${userId}qr-nevm.png`;
const pathToLogoQR = `./qr/${userId}-nevm.png`;
const nevmWallet = await db.nevm.getNevmWallet(userId);
await qr.toFile(pathToFile, nevmWallet.address, {
color: {
dark: "#000000",
light: "#ffffff",
},
});
return addLogo(pathToFile, pathToLogoQR);
} catch (error) {
console.log(error);
return null;
}
};