adspower-browser 2.1.7-beta.0 → 2.1.7-beta.2
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/README.MD +56 -30
- package/cli/authWorker.js +123 -47
- package/cli/credentialWorker.js +179 -0
- package/cli/index.js +234 -98
- package/cwd/lib/main.min.js +2 -2
- package/package.json +2 -1
package/cli/index.js
CHANGED
|
@@ -23,23 +23,151 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
23
23
|
mod
|
|
24
24
|
));
|
|
25
25
|
|
|
26
|
-
// src/
|
|
26
|
+
// src/clientSession.ts
|
|
27
|
+
var fs2 = __toESM(require("fs"));
|
|
28
|
+
var import_node_path2 = __toESM(require("path"));
|
|
29
|
+
var import_node_crypto = require("crypto");
|
|
30
|
+
|
|
31
|
+
// src/credentialVault.ts
|
|
27
32
|
var import_node_child_process = require("child_process");
|
|
28
|
-
var import_node_fs = require("fs");
|
|
29
|
-
var import_node_os = __toESM(require("os"));
|
|
30
33
|
var import_node_path = __toESM(require("path"));
|
|
31
|
-
var
|
|
32
|
-
|
|
33
|
-
|
|
34
|
+
var CredentialStoreError = class extends Error {
|
|
35
|
+
constructor(code) {
|
|
36
|
+
super(`System credential store unavailable (${code}). Use the same OS account and an accessible credential store, then run ads login again. No plaintext fallback is permitted.`);
|
|
37
|
+
this.name = "CredentialStoreError";
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
function invoke(operation, account, secret) {
|
|
41
|
+
if (!["darwin", "win32"].includes(process.platform)) throw new CredentialStoreError("UNSUPPORTED_PLATFORM");
|
|
42
|
+
if (!/^[a-f0-9]{64}$/.test(account)) throw new CredentialStoreError("INVALID_ACCOUNT");
|
|
43
|
+
let output;
|
|
34
44
|
try {
|
|
35
|
-
|
|
45
|
+
output = (0, import_node_child_process.execFileSync)(process.execPath, [import_node_path.default.join(__dirname, "credentialWorker.js")], {
|
|
46
|
+
input: JSON.stringify({ operation, account, secret }),
|
|
47
|
+
windowsHide: true,
|
|
48
|
+
timeout: 5e3,
|
|
49
|
+
killSignal: "SIGKILL",
|
|
50
|
+
maxBuffer: 32768,
|
|
51
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
52
|
+
});
|
|
36
53
|
} catch {
|
|
37
|
-
|
|
54
|
+
throw new CredentialStoreError("HELPER_FAILED_OR_TIMED_OUT");
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
const result = JSON.parse(output.toString("utf8"));
|
|
58
|
+
if (result.ok !== true) {
|
|
59
|
+
const code = typeof result.code === "string" && /^[A-Z0-9_-]{1,64}$/.test(result.code) ? result.code : "NATIVE_FAILURE";
|
|
60
|
+
throw new CredentialStoreError(code);
|
|
61
|
+
}
|
|
62
|
+
if (operation === "read" && (typeof result.secret !== "string" || !result.secret.trim() || result.secret.length > 4096 || /[\r\n]/.test(result.secret))) throw new CredentialStoreError("INVALID_SECRET");
|
|
63
|
+
return result.secret;
|
|
64
|
+
} catch (error) {
|
|
65
|
+
if (error instanceof CredentialStoreError) throw error;
|
|
66
|
+
throw new CredentialStoreError("INVALID_HELPER_RESPONSE");
|
|
67
|
+
} finally {
|
|
68
|
+
output.fill(0);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
var credentialVault = {
|
|
72
|
+
write: (account, secret) => {
|
|
73
|
+
invoke("write", account, secret);
|
|
74
|
+
},
|
|
75
|
+
read: (account) => invoke("read", account),
|
|
76
|
+
remove: (account) => {
|
|
77
|
+
invoke("delete", account);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// src/tools/paths.ts
|
|
82
|
+
var os = __toESM(require("os"));
|
|
83
|
+
var path2 = __toESM(require("path"));
|
|
84
|
+
var fs = __toESM(require("fs"));
|
|
85
|
+
var import_fs_extra2 = require("fs-extra2");
|
|
86
|
+
var getHomedir = () => {
|
|
87
|
+
return (typeof os.homedir == "function" ? os.homedir() : process.env[process.platform == "win32" ? "USERPROFILE" : "HOME"]) || "~";
|
|
88
|
+
};
|
|
89
|
+
var getPidFileDir = (create = true) => {
|
|
90
|
+
const dir = path2.join(getHomedir(), ".adspowerCli");
|
|
91
|
+
if (create && !fs.existsSync(dir)) {
|
|
92
|
+
(0, import_fs_extra2.ensureDirSync)(dir);
|
|
38
93
|
}
|
|
94
|
+
return dir;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
// src/clientSession.ts
|
|
98
|
+
var isClientMode = () => process.env.IS_WORKBUDDY !== void 0;
|
|
99
|
+
var userFile = (userId) => import_node_path2.default.join(getPidFileDir(false), (0, import_node_crypto.createHash)("md5").update(userId).digest("hex"));
|
|
100
|
+
var indexFile = () => import_node_path2.default.join(getPidFileDir(false), "client-user.json");
|
|
101
|
+
var credentialAccount = (userId) => (0, import_node_crypto.createHash)("sha256").update(userId).digest("hex");
|
|
102
|
+
var validPort = (value) => Number.isInteger(value) && Number(value) > 0 && Number(value) <= 65535;
|
|
103
|
+
function isClientSession(value) {
|
|
104
|
+
if (!value || typeof value !== "object") return false;
|
|
105
|
+
const session = value;
|
|
106
|
+
return typeof session.apiKey === "string" && !!session.apiKey.trim() && session.apiKey.length <= 4096 && !/[\r\n]/.test(session.apiKey) && typeof session.userId === "string" && !!session.userId.trim() && session.userId.length <= 256 && session.userId !== "1.0.0" && validPort(session.apiPort) && validPort(session.rpaPort);
|
|
107
|
+
}
|
|
108
|
+
function readUserId() {
|
|
109
|
+
let value;
|
|
110
|
+
try {
|
|
111
|
+
value = JSON.parse(fs2.readFileSync(indexFile(), "utf8"));
|
|
112
|
+
} catch (error) {
|
|
113
|
+
if (error.code === "ENOENT") return;
|
|
114
|
+
throw new Error("Cannot read client user index. Run ads login again.");
|
|
115
|
+
}
|
|
116
|
+
const userId = value?.userId;
|
|
117
|
+
if (typeof userId !== "string" || !userId.trim() || userId.length > 256 || userId === "1.0.0") throw new Error("Invalid client user index. Run ads login again.");
|
|
118
|
+
return userId;
|
|
119
|
+
}
|
|
120
|
+
function readMetadata(userId) {
|
|
121
|
+
let value;
|
|
122
|
+
try {
|
|
123
|
+
value = JSON.parse(fs2.readFileSync(userFile(userId), "utf8"));
|
|
124
|
+
} catch {
|
|
125
|
+
throw new Error("Cannot read client connection metadata. Run ads login again.");
|
|
126
|
+
}
|
|
127
|
+
if (value && Object.prototype.hasOwnProperty.call(value, "apiKey")) {
|
|
128
|
+
throw new Error("Legacy plaintext credentials detected. Run ads login to replace them with system credentials, or ads logout to remove them. Plaintext credentials will not be used.");
|
|
129
|
+
}
|
|
130
|
+
if (!value || value.version !== 2 || value.userId !== userId || !validPort(value.apiPort) || !validPort(value.rpaPort) || value.credentialAccount !== credentialAccount(userId)) {
|
|
131
|
+
throw new Error("Invalid client connection metadata. Run ads login again.");
|
|
132
|
+
}
|
|
133
|
+
return value;
|
|
134
|
+
}
|
|
135
|
+
function hasClientSession() {
|
|
136
|
+
const userId = readUserId();
|
|
137
|
+
if (!userId) return false;
|
|
138
|
+
readMetadata(userId);
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
function readClientSession() {
|
|
142
|
+
const userId = readUserId();
|
|
143
|
+
if (!userId) return;
|
|
144
|
+
const metadata = readMetadata(userId);
|
|
145
|
+
const apiKey = credentialVault.read(metadata.credentialAccount);
|
|
146
|
+
const session = { apiKey, userId, apiPort: metadata.apiPort, rpaPort: metadata.rpaPort };
|
|
147
|
+
if (!isClientSession(session)) throw new Error("Invalid system credential. Run ads login again.");
|
|
148
|
+
return session;
|
|
149
|
+
}
|
|
150
|
+
function removeClientSession() {
|
|
151
|
+
const userId = readUserId();
|
|
152
|
+
if (!userId) return;
|
|
153
|
+
credentialVault.remove(credentialAccount(userId));
|
|
154
|
+
fs2.rmSync(userFile(userId), { force: true });
|
|
155
|
+
fs2.rmSync(indexFile(), { force: true });
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// src/auth.ts
|
|
159
|
+
var import_node_child_process2 = require("child_process");
|
|
160
|
+
var import_node_fs = require("fs");
|
|
161
|
+
var import_node_os = __toESM(require("os"));
|
|
162
|
+
var import_node_path3 = __toESM(require("path"));
|
|
163
|
+
var import_node_net = require("net");
|
|
164
|
+
var pendingPath = import_node_path3.default.join(import_node_os.default.homedir(), ".adspowerCli", "workbuddy-login.json");
|
|
165
|
+
async function cancelLogin() {
|
|
39
166
|
await import_node_fs.promises.rm(pendingPath, { force: true });
|
|
40
|
-
const deadline = Date.now() +
|
|
167
|
+
const deadline = Date.now() + 2e4;
|
|
41
168
|
while (await loginWorkerIsRunning()) {
|
|
42
|
-
if (Date.now() >= deadline) throw new Error("Login cancellation timed out; retry ads
|
|
169
|
+
if (Date.now() >= deadline) throw new Error("Login cancellation timed out; retry ads logout");
|
|
170
|
+
await import_node_fs.promises.rm(pendingPath, { force: true });
|
|
43
171
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
44
172
|
}
|
|
45
173
|
}
|
|
@@ -55,13 +183,13 @@ async function loginWorkerIsRunning() {
|
|
|
55
183
|
socket.setTimeout(500, () => done(true));
|
|
56
184
|
});
|
|
57
185
|
}
|
|
58
|
-
async function login() {
|
|
186
|
+
async function login(input = {}) {
|
|
59
187
|
const options = {
|
|
60
188
|
detached: true,
|
|
61
189
|
windowsHide: true,
|
|
62
190
|
stdio: ["ignore", "ignore", "ignore", "ipc"]
|
|
63
191
|
};
|
|
64
|
-
const child = (0,
|
|
192
|
+
const child = (0, import_node_child_process2.fork)(import_node_path3.default.join(__dirname, "authWorker.js"), [input.loginhost || "https://app.adspower.com"], options);
|
|
65
193
|
await new Promise((resolve, reject) => {
|
|
66
194
|
const timer = setTimeout(() => {
|
|
67
195
|
child.kill();
|
|
@@ -160,21 +288,20 @@ var Store = class {
|
|
|
160
288
|
var store = new Store();
|
|
161
289
|
|
|
162
290
|
// src/core/start.ts
|
|
163
|
-
var
|
|
164
|
-
var
|
|
165
|
-
var
|
|
291
|
+
var fs6 = __toESM(require("fs"));
|
|
292
|
+
var path8 = __toESM(require("path"));
|
|
293
|
+
var import_node_child_process5 = require("child_process");
|
|
166
294
|
|
|
167
295
|
// src/tools/index.ts
|
|
168
296
|
var readline = __toESM(require("readline/promises"));
|
|
169
|
-
var
|
|
170
|
-
var
|
|
171
|
-
var fs2 = __toESM(require("fs"));
|
|
297
|
+
var path5 = __toESM(require("path"));
|
|
298
|
+
var fs4 = __toESM(require("fs"));
|
|
172
299
|
var crypto = __toESM(require("crypto"));
|
|
173
300
|
var util = __toESM(require("util"));
|
|
174
|
-
var
|
|
301
|
+
var import_node_child_process3 = require("child_process");
|
|
175
302
|
var import_colors = require("colors");
|
|
176
|
-
var
|
|
177
|
-
var VERSION = (0,
|
|
303
|
+
var import_fs_extra22 = require("fs-extra2");
|
|
304
|
+
var VERSION = (0, import_fs_extra22.readJsonSync)(path5.join(__dirname, "../package.json")).version;
|
|
178
305
|
var VERSION_FILE = "1.0.0";
|
|
179
306
|
var toTerminalLink = (url, label) => {
|
|
180
307
|
const text = label || url;
|
|
@@ -203,7 +330,7 @@ var browsersKill = async () => {
|
|
|
203
330
|
};
|
|
204
331
|
var taskKillBrowser = () => new Promise((resolve) => {
|
|
205
332
|
const cmd = ["linux", "darwin"].includes(process.platform) ? 'pkill -u `whoami` -f "SunBrowser"' : "taskkill -PID SunBrowser.exe";
|
|
206
|
-
(0,
|
|
333
|
+
(0, import_node_child_process3.exec)(cmd, { windowsHide: true }, (err) => {
|
|
207
334
|
if (err) {
|
|
208
335
|
}
|
|
209
336
|
resolve();
|
|
@@ -211,48 +338,38 @@ var taskKillBrowser = () => new Promise((resolve) => {
|
|
|
211
338
|
});
|
|
212
339
|
var taskKillFlowser = () => new Promise((resolve) => {
|
|
213
340
|
const cmd = ["linux", "darwin"].includes(process.platform) ? 'pkill -u `whoami` -f "FlowerBrowser"' : "taskkill -PID FlowerBrowser.exe";
|
|
214
|
-
(0,
|
|
341
|
+
(0, import_node_child_process3.exec)(cmd, { windowsHide: true }, (err) => {
|
|
215
342
|
if (err) {
|
|
216
343
|
}
|
|
217
344
|
resolve();
|
|
218
345
|
});
|
|
219
346
|
});
|
|
220
|
-
var getHomedir = () => {
|
|
221
|
-
return (typeof os2.homedir == "function" ? os2.homedir() : process.env[process.platform == "win32" ? "USERPROFILE" : "HOME"]) || "~";
|
|
222
|
-
};
|
|
223
|
-
var getPidFileDir = (create = true) => {
|
|
224
|
-
const dir = path2.join(getHomedir(), ".adspowerCli");
|
|
225
|
-
if (create && !fs2.existsSync(dir)) {
|
|
226
|
-
(0, import_fs_extra2.ensureDirSync)(dir);
|
|
227
|
-
}
|
|
228
|
-
return dir;
|
|
229
|
-
};
|
|
230
347
|
var pidFileName = () => {
|
|
231
348
|
const md5 = crypto.createHash("md5").update(VERSION_FILE).digest("hex");
|
|
232
349
|
return md5;
|
|
233
350
|
};
|
|
234
351
|
var writePidFile = (config2) => {
|
|
235
|
-
const filePath =
|
|
236
|
-
(0,
|
|
237
|
-
if (process.platform !== "win32")
|
|
352
|
+
const filePath = path5.join(getPidFileDir(), pidFileName());
|
|
353
|
+
(0, import_fs_extra22.outputJsonSync)(filePath, config2 || {}, { mode: 384 });
|
|
354
|
+
if (process.platform !== "win32") fs4.chmodSync(filePath, 384);
|
|
238
355
|
};
|
|
239
356
|
var readPidFile = () => {
|
|
240
|
-
const filePath =
|
|
241
|
-
if (
|
|
242
|
-
return (0,
|
|
357
|
+
const filePath = path5.join(getPidFileDir(false), pidFileName());
|
|
358
|
+
if (fs4.existsSync(filePath)) {
|
|
359
|
+
return (0, import_fs_extra22.readJsonSync)(filePath);
|
|
243
360
|
}
|
|
244
361
|
return {};
|
|
245
362
|
};
|
|
246
363
|
var removePidFile = () => {
|
|
247
|
-
const filePath =
|
|
248
|
-
if (
|
|
249
|
-
(0,
|
|
364
|
+
const filePath = path5.join(getPidFileDir(), pidFileName());
|
|
365
|
+
if (fs4.existsSync(filePath)) {
|
|
366
|
+
(0, import_fs_extra22.removeSync)(filePath);
|
|
250
367
|
}
|
|
251
368
|
};
|
|
252
369
|
var isRunning = (pid) => {
|
|
253
370
|
return new Promise((resolve) => {
|
|
254
371
|
if (pid) {
|
|
255
|
-
(0,
|
|
372
|
+
(0, import_node_child_process3.exec)(
|
|
256
373
|
util.format(process.platform === "win32" ? 'tasklist /fi "PID eq %s" | findstr /i "node.exe"' : 'ps -f -p %s | grep "node"', pid),
|
|
257
374
|
{ windowsHide: true },
|
|
258
375
|
function(err, stdout, stderr) {
|
|
@@ -265,23 +382,30 @@ var isRunning = (pid) => {
|
|
|
265
382
|
});
|
|
266
383
|
};
|
|
267
384
|
var ensureBrowserPath = () => {
|
|
268
|
-
const dir =
|
|
269
|
-
if (!
|
|
270
|
-
(0,
|
|
385
|
+
const dir = path5.join(__dirname, "../cwd/source", ".browser");
|
|
386
|
+
if (!fs4.existsSync(dir)) {
|
|
387
|
+
(0, import_fs_extra22.ensureDirSync)(dir);
|
|
271
388
|
}
|
|
272
389
|
};
|
|
273
390
|
var getApiKeyAndPort = (options) => {
|
|
391
|
+
if (isClientMode()) {
|
|
392
|
+
const session = readClientSession();
|
|
393
|
+
if (!session) throw new Error("No saved client connection. Run ads login first.");
|
|
394
|
+
return { apiKey: session.apiKey, port: String(session.apiPort), rpaPort: String(session.rpaPort) };
|
|
395
|
+
}
|
|
274
396
|
const apiKey = options.apiKey;
|
|
275
397
|
const port = options.port;
|
|
276
398
|
if (port) {
|
|
277
399
|
return {
|
|
278
400
|
apiKey: apiKey || "",
|
|
279
|
-
port
|
|
401
|
+
port,
|
|
402
|
+
rpaPort: options.rpaPort
|
|
280
403
|
};
|
|
281
404
|
}
|
|
282
405
|
const result = {
|
|
283
406
|
apiKey,
|
|
284
|
-
port
|
|
407
|
+
port,
|
|
408
|
+
rpaPort: options.rpaPort
|
|
285
409
|
};
|
|
286
410
|
const processInstance = readPidFile();
|
|
287
411
|
if (!apiKey) {
|
|
@@ -297,6 +421,7 @@ var getApiKeyAndPort = (options) => {
|
|
|
297
421
|
return result;
|
|
298
422
|
};
|
|
299
423
|
var hasRunning = async (options) => {
|
|
424
|
+
if (isClientMode()) return hasClientSession();
|
|
300
425
|
const { port } = options;
|
|
301
426
|
if (port) {
|
|
302
427
|
return true;
|
|
@@ -334,8 +459,8 @@ var createLoading = (text) => {
|
|
|
334
459
|
};
|
|
335
460
|
};
|
|
336
461
|
var initSqlite3 = () => {
|
|
337
|
-
const sqliteFile =
|
|
338
|
-
if (
|
|
462
|
+
const sqliteFile = path5.join(__dirname, "../cwd/lib", "node_sqlite3.node");
|
|
463
|
+
if (fs4.existsSync(sqliteFile)) {
|
|
339
464
|
return;
|
|
340
465
|
}
|
|
341
466
|
const isMac = process.platform === "darwin";
|
|
@@ -347,13 +472,13 @@ var initSqlite3 = () => {
|
|
|
347
472
|
const winFolder = is32 ? "ia32" : "x64";
|
|
348
473
|
const linuxFolder = isLinux && isX64 && "linux";
|
|
349
474
|
const sqliteFolder = isMac ? macFolder : isLinux ? linuxFolder : winFolder;
|
|
350
|
-
const dir =
|
|
351
|
-
if (!
|
|
475
|
+
const dir = path5.join(__dirname, `../sqlite/${sqliteFolder}`);
|
|
476
|
+
if (!fs4.existsSync(dir)) {
|
|
352
477
|
throw new Error(`SQLite folder not found: ${dir}`);
|
|
353
478
|
} else {
|
|
354
|
-
const sqliteFile2 =
|
|
355
|
-
const cwdPath =
|
|
356
|
-
(0,
|
|
479
|
+
const sqliteFile2 = path5.join(dir, "node_sqlite3.node");
|
|
480
|
+
const cwdPath = path5.join(__dirname, "../cwd/lib");
|
|
481
|
+
(0, import_fs_extra22.copySync)(sqliteFile2, path5.join(cwdPath, "node_sqlite3.node"));
|
|
357
482
|
logSuccess(`[i] SQLite file initialized successfully!`);
|
|
358
483
|
}
|
|
359
484
|
};
|
|
@@ -386,7 +511,7 @@ async function promptYesNo(question) {
|
|
|
386
511
|
var import_axios = __toESM(require("axios"));
|
|
387
512
|
var import_fs = __toESM(require("fs"));
|
|
388
513
|
var import_path = __toESM(require("path"));
|
|
389
|
-
var
|
|
514
|
+
var import_node_child_process4 = require("child_process");
|
|
390
515
|
var NPM_PACKAGE_NAME = "adspower-browser";
|
|
391
516
|
var NPM_REGISTRY_URL = `https://registry.npmjs.org/${NPM_PACKAGE_NAME}/latest`;
|
|
392
517
|
var checkUpdates = async (apiKey, baseUrl) => {
|
|
@@ -463,7 +588,7 @@ var checkUpdateNpmPackage = async () => {
|
|
|
463
588
|
var updateNpmPackage = async () => {
|
|
464
589
|
const npmCommand = process.platform === "win32" ? "npm.cmd" : "npm";
|
|
465
590
|
await new Promise((resolve, reject) => {
|
|
466
|
-
const child = (0,
|
|
591
|
+
const child = (0, import_node_child_process4.spawn)(npmCommand, ["install", "-g", `${NPM_PACKAGE_NAME}@latest`], {
|
|
467
592
|
stdio: "inherit",
|
|
468
593
|
windowsHide: true
|
|
469
594
|
});
|
|
@@ -2912,11 +3037,11 @@ var import_axios3 = __toESM(require("axios"));
|
|
|
2912
3037
|
|
|
2913
3038
|
// ../core/src/rpa/local/fileTransport.ts
|
|
2914
3039
|
var import_promises = require("fs/promises");
|
|
2915
|
-
var
|
|
3040
|
+
var import_node_path4 = require("path");
|
|
2916
3041
|
var import_node_zlib = require("zlib");
|
|
2917
3042
|
var MAX_FLOW_BYTES = 32 * 1024 * 1024;
|
|
2918
3043
|
async function readDebugProcess(filePath) {
|
|
2919
|
-
if (!(0,
|
|
3044
|
+
if (!(0, import_node_path4.isAbsolute)(filePath)) throw new Error("process_file must be an absolute local path");
|
|
2920
3045
|
const file = await (0, import_promises.open)(filePath, "r");
|
|
2921
3046
|
let bytes;
|
|
2922
3047
|
try {
|
|
@@ -2939,7 +3064,7 @@ async function readDebugProcess(filePath) {
|
|
|
2939
3064
|
}
|
|
2940
3065
|
async function writeRpaLogResult(data, outputFile) {
|
|
2941
3066
|
if (!outputFile) return JSON.stringify(data, null, 2);
|
|
2942
|
-
if (!(0,
|
|
3067
|
+
if (!(0, import_node_path4.isAbsolute)(outputFile)) throw new Error("output_file must be an absolute local path");
|
|
2943
3068
|
await (0, import_promises.writeFile)(outputFile, JSON.stringify(data), { flag: "wx", mode: 384 });
|
|
2944
3069
|
const result = Array.isArray(data) ? { total_items: data.length, items: data.slice(0, 10).map(summarizeLog), next_offset: data.length > 10 ? 10 : null } : summarizeLog(data);
|
|
2945
3070
|
return JSON.stringify({ output_file: outputFile, ...result }, null, 2);
|
|
@@ -4658,13 +4783,18 @@ var trackKernelDownload = async (fnc, args) => {
|
|
|
4658
4783
|
var handleAction = async (params, options, command, fnc) => {
|
|
4659
4784
|
const isRun = await hasRunning(options);
|
|
4660
4785
|
if (!isRun) {
|
|
4786
|
+
if (isClientMode()) {
|
|
4787
|
+
logError("[!] No saved client connection. Run ads login first.");
|
|
4788
|
+
process.exitCode = 1;
|
|
4789
|
+
return;
|
|
4790
|
+
}
|
|
4661
4791
|
logError("[!] Adspower runtime is not running");
|
|
4662
4792
|
const info = `[i] Please run "${(0, import_colors2.green)("adspower-browser start -k <apiKey>")}" to start the adspower runtime`;
|
|
4663
4793
|
console.log(info);
|
|
4664
4794
|
return;
|
|
4665
4795
|
}
|
|
4666
|
-
const { apiKey, port } = getApiKeyAndPort(options);
|
|
4667
|
-
updateConfig(apiKey, port,
|
|
4796
|
+
const { apiKey, port, rpaPort } = getApiKeyAndPort(options);
|
|
4797
|
+
updateConfig(apiKey, port, rpaPort);
|
|
4668
4798
|
const commandName = command.name();
|
|
4669
4799
|
const isRpaCommand = Object.prototype.hasOwnProperty.call(RPA_HANDLERS, commandName);
|
|
4670
4800
|
const resolved = resolveStatelessCommandArgs(commandName, params);
|
|
@@ -4688,7 +4818,7 @@ ${out}
|
|
|
4688
4818
|
} else if (commandName === "update-patch") {
|
|
4689
4819
|
const result = await fnc(args);
|
|
4690
4820
|
const out = typeof result === "string" ? result : JSON.stringify(result, null, 2);
|
|
4691
|
-
if (!out.includes("The client is already on the latest patch version. No update is required")) {
|
|
4821
|
+
if (!isClientMode() && !out.includes("The client is already on the latest patch version. No update is required")) {
|
|
4692
4822
|
await sleepTime(1e3 * 60);
|
|
4693
4823
|
loading.stop();
|
|
4694
4824
|
await restartChild();
|
|
@@ -4793,8 +4923,8 @@ var getRuntimeExecArgv = () => {
|
|
|
4793
4923
|
if (process.platform !== "win32") {
|
|
4794
4924
|
return [];
|
|
4795
4925
|
}
|
|
4796
|
-
const preload =
|
|
4797
|
-
if (!
|
|
4926
|
+
const preload = path8.join(__dirname, "core/winHideChildProcess.js");
|
|
4927
|
+
if (!fs6.existsSync(preload)) {
|
|
4798
4928
|
return [];
|
|
4799
4929
|
}
|
|
4800
4930
|
return ["--require", preload];
|
|
@@ -4833,7 +4963,7 @@ var startChild = (type) => {
|
|
|
4833
4963
|
Object.entries(getEnv()).map(([key, value]) => [key, value == null ? value : String(value)])
|
|
4834
4964
|
);
|
|
4835
4965
|
try {
|
|
4836
|
-
const mainJs =
|
|
4966
|
+
const mainJs = path8.join(__dirname, "../cwd/lib", "main.min.js");
|
|
4837
4967
|
const forkOptions = {
|
|
4838
4968
|
env,
|
|
4839
4969
|
detached: true,
|
|
@@ -4842,7 +4972,7 @@ var startChild = (type) => {
|
|
|
4842
4972
|
stdio: ["ignore", "ignore", "ignore", "ipc"],
|
|
4843
4973
|
execArgv: getRuntimeExecArgv()
|
|
4844
4974
|
};
|
|
4845
|
-
child = (0,
|
|
4975
|
+
child = (0, import_node_child_process5.fork)(mainJs, [], forkOptions);
|
|
4846
4976
|
ensureBrowserPath();
|
|
4847
4977
|
store.setStoreValue("status", "starting");
|
|
4848
4978
|
logSuccess(`[i] Adspower program is starting...`);
|
|
@@ -5114,37 +5244,43 @@ function wrapShellScriptOutput(shell) {
|
|
|
5114
5244
|
// src/index.ts
|
|
5115
5245
|
var program = new import_commander2.Command();
|
|
5116
5246
|
program.description("CLI and runtime for adspower-browser").version(VERSION);
|
|
5117
|
-
|
|
5118
|
-
program.command("
|
|
5119
|
-
|
|
5120
|
-
|
|
5121
|
-
|
|
5122
|
-
|
|
5123
|
-
|
|
5124
|
-
|
|
5125
|
-
|
|
5126
|
-
|
|
5127
|
-
|
|
5128
|
-
|
|
5129
|
-
|
|
5130
|
-
|
|
5131
|
-
|
|
5132
|
-
|
|
5133
|
-
|
|
5134
|
-
|
|
5135
|
-
|
|
5136
|
-
|
|
5137
|
-
|
|
5138
|
-
|
|
5139
|
-
|
|
5140
|
-
|
|
5141
|
-
}
|
|
5142
|
-
|
|
5143
|
-
|
|
5144
|
-
|
|
5145
|
-
|
|
5146
|
-
|
|
5147
|
-
|
|
5247
|
+
if (isClientMode()) {
|
|
5248
|
+
program.command("login").description("Authorize AdsPower CLI from WorkBuddy in your browser").option("--loginhost <loginhost>", "Set the authorization site origin (or /login URL)").action(login);
|
|
5249
|
+
program.command("logstatus").description("Check the saved client connection").action(async () => {
|
|
5250
|
+
const authenticated = !!readClientSession();
|
|
5251
|
+
console.log(JSON.stringify({ authenticated, state: authenticated ? "ready" : "logged_out" }));
|
|
5252
|
+
process.exitCode = authenticated ? 0 : 1;
|
|
5253
|
+
});
|
|
5254
|
+
program.command("logout").description("Remove the saved WorkBuddy client connection").action(async () => {
|
|
5255
|
+
await cancelLogin();
|
|
5256
|
+
removeClientSession();
|
|
5257
|
+
});
|
|
5258
|
+
} else {
|
|
5259
|
+
program.command("start").description("Start the adspower runtime").option("-k, --api-key <apiKey>", "Set the API key for the adspower runtime").addOption(new import_commander2.Option("--base-url <baseUrl>", "Set the base URL for the adspower runtime").hideHelp()).addOption(new import_commander2.Option("--node-env <nodeEnv>", "Set the node environment for the adspower runtime").hideHelp()).action(async (options) => {
|
|
5260
|
+
const resolvedApiKey = resolveStartApiKey(options.apiKey, process.env);
|
|
5261
|
+
if (!resolvedApiKey.ok) {
|
|
5262
|
+
logError(resolvedApiKey.error);
|
|
5263
|
+
process.exit(1);
|
|
5264
|
+
}
|
|
5265
|
+
store.setStoreValue("apiKey", resolvedApiKey.apiKey);
|
|
5266
|
+
if (options.baseUrl) {
|
|
5267
|
+
store.setStoreValue("baseUrl", options.baseUrl);
|
|
5268
|
+
}
|
|
5269
|
+
if (options.nodeEnv) {
|
|
5270
|
+
store.setStoreValue("nodeEnv", options.nodeEnv);
|
|
5271
|
+
}
|
|
5272
|
+
await startChild();
|
|
5273
|
+
});
|
|
5274
|
+
program.command("stop").description("Stop the adspower runtime").action(async () => {
|
|
5275
|
+
await stopChild();
|
|
5276
|
+
});
|
|
5277
|
+
program.command("restart").description("Restart the adspower runtime").action(async () => {
|
|
5278
|
+
await restartChild();
|
|
5279
|
+
});
|
|
5280
|
+
program.command("status").description("Get the status of the adspower runtime").action(async () => {
|
|
5281
|
+
await getChildStatus();
|
|
5282
|
+
});
|
|
5283
|
+
}
|
|
5148
5284
|
for (const cmd of Object.keys(STATELESS_HANDLERS)) {
|
|
5149
5285
|
const fnc = STATELESS_HANDLERS[cmd].fn;
|
|
5150
5286
|
program.command(`${cmd}`).description(STATELESS_HANDLERS[cmd].description).option("-k, --api-key <apiKey>", "Set the API key for the adspower runtime").option("-p, --port <port>", "Set the port for the adspower runtime").addOption(Object.assign(new import_commander2.Option("--rpa-port <port>", "Set the port for the local RPA Plus service"), {
|