@cexy/hoonfca 1.0.5 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/func/checkUpdate.js +18 -7
- package/module/config.js +53 -20
- package/module/login.js +29 -11
- package/module/options.js +23 -14
- package/package.json +1 -1
package/func/checkUpdate.js
CHANGED
|
@@ -3,7 +3,7 @@ const fs = require("fs");
|
|
|
3
3
|
const path = require("path");
|
|
4
4
|
const { exec } = require("child_process");
|
|
5
5
|
const https = require("https");
|
|
6
|
-
const pkgName = "@
|
|
6
|
+
const pkgName = "@cexy/hoonfca";
|
|
7
7
|
|
|
8
8
|
let axios = null;
|
|
9
9
|
try {
|
|
@@ -201,14 +201,25 @@ async function _checkAndUpdateVersionImpl() {
|
|
|
201
201
|
let after = getInstalledVersion();
|
|
202
202
|
if (!after) after = await getInstalledVersionByNpm();
|
|
203
203
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
204
|
+
if (after && after === latest) {
|
|
205
|
+
writeLock({ ts: Date.now(), latest, status: "updated" });
|
|
206
|
+
|
|
207
|
+
logger(
|
|
208
|
+
`Updated fca to the latest version: ${latest}. Restart manually to apply.`,
|
|
209
|
+
"info"
|
|
210
|
+
);
|
|
211
|
+
|
|
212
|
+
if (process.env.FCA_AUTO_RESTART === "true") {
|
|
207
213
|
process.exit(1);
|
|
208
|
-
} else {
|
|
209
|
-
writeLock({ ts: Date.now(), latest, status: "mismatch" });
|
|
210
|
-
logger(`Installed but version mismatch (have: ${after || "unknown"}, want: ${latest}). Skip restart to avoid loop`, "error");
|
|
211
214
|
}
|
|
215
|
+
} else {
|
|
216
|
+
writeLock({ ts: Date.now(), latest, status: "mismatch" });
|
|
217
|
+
logger(
|
|
218
|
+
`Installed but version mismatch (have: ${after || "unknown"}, want: ${latest}). Skip restart to avoid loop`,
|
|
219
|
+
"error"
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
|
|
212
223
|
}
|
|
213
224
|
|
|
214
225
|
function checkAndUpdateVersion(callback) {
|
package/module/config.js
CHANGED
|
@@ -1,34 +1,67 @@
|
|
|
1
1
|
const fs = require("fs");
|
|
2
2
|
const path = require("path");
|
|
3
3
|
const logger = require("../func/logger");
|
|
4
|
+
|
|
4
5
|
const defaultConfig = {
|
|
5
|
-
autoUpdate:
|
|
6
|
-
mqtt: {
|
|
6
|
+
autoUpdate: false,
|
|
7
|
+
mqtt: {
|
|
8
|
+
enabled: true,
|
|
9
|
+
reconnectInterval: 3600
|
|
10
|
+
},
|
|
7
11
|
autoLogin: true,
|
|
8
|
-
credentials: {
|
|
12
|
+
credentials: {
|
|
13
|
+
email: "",
|
|
14
|
+
password: "",
|
|
15
|
+
twofactor: ""
|
|
16
|
+
}
|
|
9
17
|
};
|
|
10
18
|
|
|
11
19
|
function loadConfig() {
|
|
12
20
|
const configPath = path.join(process.cwd(), "fca-config.json");
|
|
13
|
-
let config;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
config = defaultConfig;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
config = defaultConfig;
|
|
21
|
-
}
|
|
22
|
-
} else {
|
|
23
|
-
try {
|
|
21
|
+
let config = {};
|
|
22
|
+
|
|
23
|
+
try {
|
|
24
|
+
if (!fs.existsSync(configPath)) {
|
|
25
|
+
config = { ...defaultConfig };
|
|
26
|
+
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
|
27
|
+
} else {
|
|
24
28
|
const fileContent = fs.readFileSync(configPath, "utf8");
|
|
25
|
-
config =
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
config =
|
|
29
|
+
config = JSON.parse(fileContent);
|
|
30
|
+
|
|
31
|
+
// Merge with defaults
|
|
32
|
+
config = {
|
|
33
|
+
...defaultConfig,
|
|
34
|
+
...config,
|
|
35
|
+
mqtt: {
|
|
36
|
+
...defaultConfig.mqtt,
|
|
37
|
+
...(config.mqtt || {})
|
|
38
|
+
},
|
|
39
|
+
credentials: {
|
|
40
|
+
...defaultConfig.credentials,
|
|
41
|
+
...(config.credentials || {})
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// Save updated config if new keys were added
|
|
46
|
+
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
|
29
47
|
}
|
|
48
|
+
} catch (err) {
|
|
49
|
+
logger(`Config error: ${err.message}`, "error");
|
|
50
|
+
|
|
51
|
+
config = { ...defaultConfig };
|
|
52
|
+
|
|
53
|
+
try {
|
|
54
|
+
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
|
55
|
+
} catch (_) {}
|
|
30
56
|
}
|
|
31
|
-
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
config,
|
|
60
|
+
configPath
|
|
61
|
+
};
|
|
32
62
|
}
|
|
33
63
|
|
|
34
|
-
module.exports = {
|
|
64
|
+
module.exports = {
|
|
65
|
+
loadConfig,
|
|
66
|
+
defaultConfig
|
|
67
|
+
};
|
package/module/login.js
CHANGED
|
@@ -119,18 +119,36 @@ function login(loginData, options, callback) {
|
|
|
119
119
|
};
|
|
120
120
|
callback = prCallback;
|
|
121
121
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
const proceed = () =>
|
|
125
|
+
loginHelper(
|
|
126
|
+
loginData.appState,
|
|
127
|
+
loginData.Cookie,
|
|
128
|
+
loginData.email,
|
|
129
|
+
loginData.password,
|
|
130
|
+
globalOptions,
|
|
131
|
+
callback,
|
|
132
|
+
prCallback
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
// Login immediately
|
|
136
|
+
proceed();
|
|
137
|
+
|
|
138
|
+
// Run update check in background (never block login)
|
|
139
|
+
if (config && config.autoUpdate) {
|
|
140
|
+
setImmediate(async () => {
|
|
141
|
+
try {
|
|
142
|
+
await checkAndUpdateVersion();
|
|
143
|
+
} catch (err) {
|
|
144
|
+
logger(
|
|
145
|
+
`Background update check failed: ${err.message || err}`,
|
|
146
|
+
"warn"
|
|
147
|
+
);
|
|
129
148
|
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
return returnPromise;
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
return returnPromise;
|
|
134
152
|
}
|
|
135
153
|
|
|
136
154
|
module.exports = login;
|
package/module/options.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
const { getType } = require("../src/utils/format");
|
|
2
1
|
const { setProxy } = require("../src/utils/request");
|
|
3
|
-
|
|
2
|
+
|
|
4
3
|
const Boolean_Option = [
|
|
5
4
|
"online",
|
|
6
5
|
"selfListen",
|
|
@@ -14,32 +13,42 @@ const Boolean_Option = [
|
|
|
14
13
|
"emitReady",
|
|
15
14
|
"selfListenEvent"
|
|
16
15
|
];
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
|
|
17
|
+
function setOptions(globalOptions, options = {}) {
|
|
18
|
+
for (const key of Object.keys(options)) {
|
|
19
19
|
if (Boolean_Option.includes(key)) {
|
|
20
20
|
globalOptions[key] = Boolean(options[key]);
|
|
21
21
|
continue;
|
|
22
22
|
}
|
|
23
|
+
|
|
23
24
|
switch (key) {
|
|
24
|
-
case "userAgent":
|
|
25
|
-
globalOptions.userAgent =
|
|
25
|
+
case "userAgent":
|
|
26
|
+
globalOptions.userAgent =
|
|
27
|
+
options.userAgent ||
|
|
28
|
+
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36";
|
|
26
29
|
break;
|
|
27
|
-
|
|
28
|
-
case "proxy":
|
|
30
|
+
|
|
31
|
+
case "proxy":
|
|
29
32
|
if (typeof options.proxy !== "string") {
|
|
30
33
|
delete globalOptions.proxy;
|
|
31
34
|
setProxy();
|
|
32
35
|
} else {
|
|
33
36
|
globalOptions.proxy = options.proxy;
|
|
34
|
-
setProxy(
|
|
37
|
+
setProxy(options.proxy);
|
|
35
38
|
}
|
|
36
39
|
break;
|
|
37
|
-
|
|
38
|
-
default:
|
|
39
|
-
|
|
40
|
+
|
|
41
|
+
default:
|
|
42
|
+
// Accept any future/custom option silently
|
|
43
|
+
globalOptions[key] = options[key];
|
|
40
44
|
break;
|
|
41
|
-
}
|
|
42
45
|
}
|
|
43
46
|
}
|
|
47
|
+
|
|
48
|
+
return globalOptions;
|
|
44
49
|
}
|
|
45
|
-
|
|
50
|
+
|
|
51
|
+
module.exports = {
|
|
52
|
+
setOptions,
|
|
53
|
+
Boolean_Option
|
|
54
|
+
};
|