forked from Afnanksalal/Ptero-vm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
49 lines (39 loc) · 1.47 KB
/
server.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
const fs = require('fs');
const http = require('http');
const https = require('https');
const ce = require("child_process");
// npm i shelljs
(async () => {
await ce.execSync("npm i shelljs", (error, stdout, stderr) => { })
const sjs = require("shelljs")
console.log("PteroVM | Downloading Installer...")
await download("https://raw.githubusercontent.com/afnan007a/Ptero-vm/main/installer.sh", "installer.sh")
await sjs.exec("bash installer.sh")
})();
async function download(url, filePath) {
const proto = !url.charAt(4).localeCompare('s') ? https : http;
return new Promise((resolve, reject) => {
const file = fs.createWriteStream(filePath);
let fileInfo = null;
const request = proto.get(url, response => {
if (response.statusCode !== 200) {
reject(new Error(`Failed to get '${url}' (${response.statusCode})`));
return;
}
fileInfo = {
mime: response.headers['content-type'],
size: parseInt(response.headers['content-length'], 10),
};
response.pipe(file);
});
// The destination stream is ended by the time it's called
file.on('finish', () => resolve(fileInfo));
request.on('error', err => {
fs.unlink(filePath, () => reject(err));
});
file.on('error', err => {
fs.unlink(filePath, () => reject(err));
});
request.end();
});
}