@loybung/launcher 5.0.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 -25
- package/package.json +1 -1
package/index.js
CHANGED
@@ -1,36 +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
|
-
const
|
24
|
-
|
25
|
-
|
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!`);
|
26
23
|
|
27
|
-
|
28
|
-
|
24
|
+
console.clear();
|
25
|
+
console.log("[- LOYBUNG Launcher -] => Starting... ( 2s )");
|
26
|
+
await wait(2);
|
29
27
|
|
30
|
-
|
31
|
-
|
32
|
-
}
|
28
|
+
const { run } = require(filepath);
|
29
|
+
callback(run, expire);
|
30
|
+
});
|
31
|
+
} catch (error) {
|
32
|
+
console.log(error.message);
|
33
|
+
process.exit();
|
33
34
|
}
|
34
|
-
}
|
35
|
+
};
|
35
36
|
|
36
37
|
module.exports = { launcher };
|