@loybung/launcher 4.3.0 → 5.1.0
Sign up to get free protection for your applications and to get access to all the features.
- package/index.js +26 -28
- package/package.json +1 -1
package/index.js
CHANGED
@@ -1,39 +1,37 @@
|
|
1
1
|
const fs = require("fs");
|
2
|
-
const path = require("path");
|
3
2
|
|
4
|
-
async
|
5
|
-
{
|
6
|
-
|
7
|
-
) {
|
8
|
-
console.clear();
|
9
|
-
console.log("( LOYBUNG Launcher ) => Fetching...");
|
3
|
+
const launcher = async ({ url, filepath, expire }, callback) => {
|
4
|
+
try {
|
5
|
+
const wait = (ms) => new Promise((res) => setTimeout(res, ms * 1000));
|
10
6
|
|
11
|
-
|
12
|
-
|
13
|
-
throw new Error(`ดึงข้อมูลผิดพลาด! | Status: ${response.status}`);
|
14
|
-
}
|
15
|
-
const textData = await response.text();
|
7
|
+
console.clear();
|
8
|
+
console.log("[- LOYBUNG Launcher -] => Fetching...");
|
16
9
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
10
|
+
if (expire) {
|
11
|
+
setInterval(() => {
|
12
|
+
if (expire < Math.floor(Date.now() / 1000)) {
|
13
|
+
throw new Error("[- LOYBUNG Launcher -] => Expired!");
|
14
|
+
}
|
15
|
+
}, 1000);
|
21
16
|
}
|
22
17
|
|
23
|
-
|
24
|
-
if (!
|
25
|
-
|
26
|
-
|
18
|
+
const res = await fetch(url);
|
19
|
+
if (!res.ok) throw new Error(`[- LOYBUNG Launcher -] => Fetch error!`);
|
20
|
+
const textData = await res.text();
|
21
|
+
fs.writeFile(filepath, textData, "utf8", async (err) => {
|
22
|
+
if (err) throw new Error(`[- LOYBUNG Launcher -] => Error!`);
|
27
23
|
|
28
|
-
|
29
|
-
|
30
|
-
|
24
|
+
console.clear();
|
25
|
+
console.log("[- LOYBUNG Launcher -] => Starting... ( 2s )");
|
26
|
+
await wait(2);
|
31
27
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
28
|
+
const { run } = require(filepath);
|
29
|
+
callback(run, expire);
|
30
|
+
});
|
31
|
+
} catch (error) {
|
32
|
+
console.log(error.message);
|
33
|
+
process.exit();
|
36
34
|
}
|
37
|
-
}
|
35
|
+
};
|
38
36
|
|
39
37
|
module.exports = { launcher };
|