@loybung/launcher 5.0.0 → 5.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. package/index.js +25 -25
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,36 +1,36 @@
1
1
  const fs = require("fs");
2
- const path = require("path");
3
2
 
4
- async function launcher(
5
- { url: url, filepath: filepath, expire: expire },
6
- callback
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
- const response = await fetch(url);
12
- if (!response.ok) {
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
- fs.writeFile(filepath, textData, "utf8", (err) => {
18
- if (err) {
19
- console.error("เกิดข้อผิดพลาดในการเขียนไฟล์:", err);
20
- return;
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 { run } = require(filepath);
24
- callback(run, expire);
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
- if (expire) {
28
- if (expire < Math.floor(Date.now() / 1000)) process.exit();
24
+ console.clear();
25
+ console.log("[- LOYBUNG Launcher -] => Starting...");
29
26
 
30
- setInterval(() => {
31
- if (expire < Math.floor(Date.now() / 1000)) process.exit();
32
- }, 5000);
27
+ const { run } = require(filepath);
28
+ callback(run, expire);
29
+ });
30
+ } catch (error) {
31
+ console.log(error.message);
32
+ process.exit();
33
33
  }
34
- }
34
+ };
35
35
 
36
36
  module.exports = { launcher };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loybung/launcher",
3
- "version": "5.0.0",
3
+ "version": "5.2.0",
4
4
  "description": "LOYBUNG / Launcher",
5
5
  "main": "index.js",
6
6
  "scripts": {