forked from Gimenz/nganu
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathserver.js
More file actions
87 lines (79 loc) · 2.69 KB
/
Copy pathserver.js
File metadata and controls
87 lines (79 loc) · 2.69 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
/**
* Author : Gimenz
* Name : nganu
* Version : 1.0
* Update : 09 Januari 2022
*
* If you are a reliable programmer or the best developer, please don't change anything.
* If you want to be appreciated by others, then don't change anything in this script.
* Please respect me for making this tool from the beginning.
*/
let express = require('express')
const http = require('http')
const app = express()
const httpServer = http.createServer(app)
const { color, humanFileSize } = require('./utils/index')
const si = require('systeminformation')
const io = require('socket.io')(httpServer)
const qrcode = require('qrcode')
const { resizeImage } = require('./lib/converter')
app.set('json spaces', 2);
app.use(express.json());
app.get('/', async (req, res) => {
try {
let ram = await si.mem()
let cpu = await si.cpuCurrentSpeed()
let disk = await si.fsSize()
let up = si.time()
let json = {
server_time: new Date(up.current).toLocaleString('jv'),
uptime: times(up.uptime),
memory: humanFileSize(ram.free, true, 1) + ' free of ' + humanFileSize(ram.total, true, 1),
memory_used: humanFileSize(ram.used, true, 1),
cpu: cpu.avg + ' Ghz',
disk: humanFileSize(disk[0].available, true, 1) + ' free of ' + humanFileSize(disk[0].size, true, 1),
}
res.status(200).json(json)
} catch (error) {
res.status(503).send(error)
}
})
app.get('/send', async (req, res, next) => {
const { id, text } = req.query;
if (!id) return res.status(403).json({
status: false,
code: 403,
creator: '@gimenz.id',
result: 'jid diperlukan'
})
if (!text) return res.status(403).json({
status: false,
code: 403,
creator: '@gimenz.id',
result: 'text diperlukan'
})
const data = await client.sendMessage(id, { text })
res.status(200).jsonp(data)
console.log(color(`[SEND] send message to ${id}`, 'green') + color(`${PORT}`, 'yellow'))
})
const qrPrint = (qr) => {
app.get('/qr', async (req, res) => {
res.setHeader("content-type", "image/png")
res.send(await resizeImage(await qrcode.toBuffer(qr), 512, 512))
})
}
// Run the server
const PORT = process.env.PORT || 3000
httpServer.listen(PORT, () => {
console.log(color('[INFO] Web api Server on port: ', 'green') + color(`${PORT}`, 'yellow'))
})
function times(second) {
days = Math.floor((second / 60) / 60 / 24)
hours = Math.floor((second / 60) / 60)
minute = Math.floor(second / 60)
sec = Math.floor(second)
return days + ' days, ' + hours + ' hours, ' + minute + ' minutes, ' + sec + ' seconds'
}
module.exports = {
qrPrint
}