@loybung/launcher 7.0.3 → 7.0.5
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.js +82 -3
- package/package.json +1 -1
- package/dist/launcher.js +0 -89
package/dist/index.js
CHANGED
@@ -1,5 +1,84 @@
|
|
1
1
|
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
+
}) : function(o, v) {
|
16
|
+
o["default"] = v;
|
17
|
+
});
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
19
|
+
if (mod && mod.__esModule) return mod;
|
20
|
+
var result = {};
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22
|
+
__setModuleDefault(result, mod);
|
23
|
+
return result;
|
24
|
+
};
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
32
|
+
});
|
33
|
+
};
|
2
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
|
4
|
-
const
|
5
|
-
|
35
|
+
const fs = __importStar(require("fs"));
|
36
|
+
const path = __importStar(require("path"));
|
37
|
+
class Launcher {
|
38
|
+
constructor(apiURL) {
|
39
|
+
this.apiURL = apiURL;
|
40
|
+
this.filePath = path.join(__dirname, "app.js");
|
41
|
+
this.expireTimestamp = null;
|
42
|
+
this.expireTimeout = null;
|
43
|
+
}
|
44
|
+
setExpire(unixTimestamp) {
|
45
|
+
this.expireTimestamp = unixTimestamp;
|
46
|
+
const now = Date.now();
|
47
|
+
const expireIn = unixTimestamp * 1000 - now;
|
48
|
+
if (expireIn <= 0) {
|
49
|
+
console.log("Code has already expired.");
|
50
|
+
process.exit(0);
|
51
|
+
}
|
52
|
+
else {
|
53
|
+
console.log(`Code will expire at: ${new Date(unixTimestamp * 1000).toISOString()}`);
|
54
|
+
if (this.expireTimeout) {
|
55
|
+
clearTimeout(this.expireTimeout);
|
56
|
+
}
|
57
|
+
this.expireTimeout = setTimeout(() => {
|
58
|
+
console.log("Code has expired. Shutting down...");
|
59
|
+
process.exit(0);
|
60
|
+
}, expireIn);
|
61
|
+
}
|
62
|
+
}
|
63
|
+
Run() {
|
64
|
+
return __awaiter(this, void 0, void 0, function* () {
|
65
|
+
try {
|
66
|
+
if (this.expireTimestamp && Date.now() / 1000 > this.expireTimestamp) {
|
67
|
+
throw new Error("Code has expired.");
|
68
|
+
}
|
69
|
+
const response = yield fetch(this.apiURL);
|
70
|
+
if (!response.ok) {
|
71
|
+
throw new Error(`HTTP error! Status: ${response.status}`);
|
72
|
+
}
|
73
|
+
const data = yield response.text();
|
74
|
+
const code = data;
|
75
|
+
fs.writeFileSync(this.filePath, code);
|
76
|
+
require(this.filePath).default;
|
77
|
+
}
|
78
|
+
catch (error) {
|
79
|
+
console.error("Error during fetch or execution:", error);
|
80
|
+
}
|
81
|
+
});
|
82
|
+
}
|
83
|
+
}
|
84
|
+
exports.default = Launcher;
|
package/package.json
CHANGED
package/dist/launcher.js
DELETED
@@ -1,89 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
-
if (k2 === undefined) k2 = k;
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
-
}
|
8
|
-
Object.defineProperty(o, k2, desc);
|
9
|
-
}) : (function(o, m, k, k2) {
|
10
|
-
if (k2 === undefined) k2 = k;
|
11
|
-
o[k2] = m[k];
|
12
|
-
}));
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
-
}) : function(o, v) {
|
16
|
-
o["default"] = v;
|
17
|
-
});
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
19
|
-
if (mod && mod.__esModule) return mod;
|
20
|
-
var result = {};
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22
|
-
__setModuleDefault(result, mod);
|
23
|
-
return result;
|
24
|
-
};
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
32
|
-
});
|
33
|
-
};
|
34
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
35
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
36
|
-
};
|
37
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
38
|
-
exports.Launcher = void 0;
|
39
|
-
const node_fetch_1 = __importDefault(require("node-fetch"));
|
40
|
-
const fs = __importStar(require("fs"));
|
41
|
-
const path = __importStar(require("path"));
|
42
|
-
class Launcher {
|
43
|
-
constructor(apiURL) {
|
44
|
-
this.apiURL = apiURL;
|
45
|
-
this.filePath = path.join(__dirname, "app.js");
|
46
|
-
this.expireTimestamp = null;
|
47
|
-
this.expireTimeout = null;
|
48
|
-
}
|
49
|
-
setExpire(unixTimestamp) {
|
50
|
-
this.expireTimestamp = unixTimestamp;
|
51
|
-
const now = Date.now();
|
52
|
-
const expireIn = unixTimestamp * 1000 - now;
|
53
|
-
if (expireIn <= 0) {
|
54
|
-
console.log("Code has already expired.");
|
55
|
-
process.exit(0);
|
56
|
-
}
|
57
|
-
else {
|
58
|
-
console.log(`Code will expire at: ${new Date(unixTimestamp * 1000).toISOString()}`);
|
59
|
-
if (this.expireTimeout) {
|
60
|
-
clearTimeout(this.expireTimeout);
|
61
|
-
}
|
62
|
-
this.expireTimeout = setTimeout(() => {
|
63
|
-
console.log("Code has expired. Shutting down...");
|
64
|
-
process.exit(0);
|
65
|
-
}, expireIn);
|
66
|
-
}
|
67
|
-
}
|
68
|
-
Run() {
|
69
|
-
return __awaiter(this, void 0, void 0, function* () {
|
70
|
-
try {
|
71
|
-
if (this.expireTimestamp && Date.now() / 1000 > this.expireTimestamp) {
|
72
|
-
throw new Error("Code has expired.");
|
73
|
-
}
|
74
|
-
const response = yield (0, node_fetch_1.default)(this.apiURL);
|
75
|
-
if (!response.ok) {
|
76
|
-
throw new Error(`HTTP error! Status: ${response.status}`);
|
77
|
-
}
|
78
|
-
const data = yield response.json();
|
79
|
-
const code = data;
|
80
|
-
fs.writeFileSync(this.filePath, code);
|
81
|
-
require(this.filePath).default;
|
82
|
-
}
|
83
|
-
catch (error) {
|
84
|
-
console.error("Error during fetch or execution:", error);
|
85
|
-
}
|
86
|
-
});
|
87
|
-
}
|
88
|
-
}
|
89
|
-
exports.Launcher = Launcher;
|