-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreqHTML.js
More file actions
94 lines (76 loc) · 2.26 KB
/
Copy pathreqHTML.js
File metadata and controls
94 lines (76 loc) · 2.26 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
const { Console } = require('console');
const http = require('http');
const config = require('./db').config; // config lida do TXT
const crypto = require('crypto');
async function requisitionHolyricsHTML(isFront = true, html_type = 2) {
const pathHTML = isFront ? `/stage-view/text.json?html_type=${html_type}` : `/stage-view/text-aux-control.json?html_type=${html_type}`;
const options = {
hostname: config.ip,
port: 7575,
path: pathHTML,
method: 'GET'
};
try {
const responseData = await new Promise((resolve, reject) => {
const req = http.get(options, res => {
let data = '';
res.on('data', chunk => {
data += chunk;
});
res.on('end', () => {
resolve(data);
});
});
req.on('error', reject);
req.end();
});
const jsonData = JSON.parse(responseData);
return jsonData; // Retorna os dados JSON da resposta
} catch (error) {
console.error(error);
return null;
}
}
async function requisitionWidescreen(isFront = true, html_type = 2) {
const options = {
hostname: config.ip,
port: 7575,
path: '/stage-view/widescreen.jpg',
method: 'GET'
};
try {
const responseData = await new Promise((resolve, reject) => {
const req = http.get(options, res => {
let data = '';
res.setEncoding('base64');
res.on('data', chunk => {
data += chunk;
});
res.on('end', () => {
resolve(data);
});
});
req.on('error', reject);
req.end();
});
// calcula um hash do base64 da imagem
const hash = calcularHash(responseData);
const jsonData = {
hash: hash,
base64: responseData
};
return jsonData; // Retorna os dados JSON da resposta
} catch (error) {
console.error(error);
return null;
}
}
function calcularHash(base64Data) {
const hash = crypto.createHash('sha256');
hash.update(base64Data, 'base64');
return hash.digest('hex');
}
module.exports = {
requisitionHolyricsHTML: requisitionHolyricsHTML,
requisitionWidescreen: requisitionWidescreen
}