-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathwxImagePing.js
49 lines (43 loc) · 1.27 KB
/
wxImagePing.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
function mkSvg(width, height){
// make fake svg figure
return `<svg width="${width}" height="${height}" xmlns="http://www.w3.org/2000/svg"></svg>`
// max width 33554428
}
function pingStr(content){
// send char list infomation
res = this;
res.set('Content-Type', 'image/svg+xml')
if(res.pingLength){
res.send(Buffer.from(mkSvg(content.length,1)))
return
}
if(res.pingIndex){
res.send(Buffer.from(mkSvg(content.charCodeAt(res.pingIndex),1)))
return
}
res.sendStatus(404)
}
function pingCodelist(codeList){
// send number infomation
res = this;
res.set('Content-Type', 'image/svg+xml')
if(res.pingLength){
res.send(Buffer.from(mkSvg(codeList[0].length,1)))
return
}
if(res.pingIndex !== undefined){
res.send(Buffer.from(mkSvg(
Math.floor(codeList[0][res.pingIndex]),
Math.floor(codeList[1][res.pingIndex]))))
return
}
res.sendStatus(404)
}
function wxImagePing(req, res, next) {
res.pingIndex = req.query.__index && parseInt(req.query.__index);
res.pingLength = req.query.__length && parseInt(req.query.__length);
res.pingStr = pingStr;
res.pingCodelist = pingCodelist;
next();
}
module.exports = wxImagePing