-
Notifications
You must be signed in to change notification settings - Fork 18
/
start.js
80 lines (64 loc) · 1.71 KB
/
start.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
80
//WEB SERVER
let { startSock } = require("./index.js")
const express = require("express")
const cors = require("cors")
const request = require("request")
const got = require("got")
const fs = require('fs')
const app = express();
app.use(cors());
app.use(express.json());
app.get('/gambar', (req, res) => {
const path = __dirname + '/img.png';
const path2 = __dirname + '/done.jpg';
res.set('Cache-Control', 'no-cache, no-store, must-revalidate');
if (fs.existsSync('./img.png')) {
res.sendFile(path, (err) => {
if (err) {
console.error(err);
res.status(500).send('Internal Server Error');
}
});
} else {
res.sendFile(path2, (err) => {
if (err) {
console.error(err);
res.status(500).send('Internal Server Error');
}
});
}
});
app.get("/", (req, res) => {
if (fs.existsSync('./img.png')) {
res.sendFile(__dirname + '/qr.html')
} else {
res.sendFile(__dirname + '/megumi.html')
}
});
app.get('/ping', function(req, res) {
const ipAddress = req.socket.remoteAddress;
res.send(ipAddress);
});
app.get("/restart", (req, res) => {
try {
res.sendFile(__dirname + '/ping.html')
} finally {
var sys = require('sys')
var exec = require('child_process').exec;
function puts(error, stdout, stderr) { sys.puts(stdout) }
exec("kill 1", function(err, stdout, stderr) {
console.log(stdout);
})
}
})
app.get("/del", (req, res) => {
if (fs.existsSync('./multi_state/store.json')) {
fs.unlinkSync('./multi_state/store.json')
}
res.sendFile(__dirname + '/ping.html')
})
startSock()
const PORT = process.env.PORT || 8080;
app.listen(PORT, () => {
console.log("Megumi Server is Active in Port: " + PORT);
});