From 25ce0eec2d53728c84afa979bd3943b0a4e99b69 Mon Sep 17 00:00:00 2001 From: PAN Lei Date: Tue, 5 Mar 2024 15:01:51 +0100 Subject: [PATCH] add current ip to db --- src/models/ReserveResultPojo.js | 4 +++- src/workers/CommandorPage.js | 31 ++++++++++++++++++++----------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/models/ReserveResultPojo.js b/src/models/ReserveResultPojo.js index 219a896..b1f335c 100644 --- a/src/models/ReserveResultPojo.js +++ b/src/models/ReserveResultPojo.js @@ -17,6 +17,7 @@ class ReserveResultPojo { this.source_from = "" this.serial = "" this.hostName = hostName + this.currentIp = "" this.created_at = new Date().toLocaleString() } @@ -33,7 +34,8 @@ class ReserveResultPojo { source_from: this.source_from, serial: this.serial, created_at: this.created_at, - hostName: this.hostName + hostName: this.hostName, + current_ip: this.currentIp } } diff --git a/src/workers/CommandorPage.js b/src/workers/CommandorPage.js index 3c888fd..0324e1e 100644 --- a/src/workers/CommandorPage.js +++ b/src/workers/CommandorPage.js @@ -173,8 +173,6 @@ class CommandorPage { // await this.device.shell(swipCmd); await delay(3 * getRandomWaitTime()); } - // await this.openGoogle() - // await delay(3 * getRandomWaitTime()); await this.clickOnHomeBtn(); await this.checkResultWithOcr(); } @@ -762,6 +760,9 @@ class CommandorPage { } async push_message_to_db(publishType, url) { + let currentIp = await this.getCurrentIP() + logWithDevice("currentIp is " + currentIp, this.device) + let splitedUrl = url.split("/"); let id = splitedUrl[splitedUrl.length - 1]; if (id === "register") { @@ -773,6 +774,7 @@ class CommandorPage { // save to mongoDb let reserve = ReserveResultPojo.create_from_contact(this.contact, id, url, this.choosedStore, publishType); reserve.source_from = this.device.model(); + reserve.currentIp = currentIp reserve.serial = this.device.serial(); await this.mongoManager.saveReserveToDb(reserve.to_mongo_dict()) if (!this.page.isClosed()) { @@ -1002,11 +1004,6 @@ class CommandorPage { // reconnect to page and get url if (!this.isTerminated) { await this.connect_to_browser(OCRResult.SUCCESS) - // if (!this.isTerminated) { - // logWithDevice("will save success appointment", this.device) - // await this.push_message_to_queue(PublishType.SUCCESS); - // await this.closePage() - // } } break; case @@ -1373,10 +1370,22 @@ class CommandorPage { await delay(2000); } - async startPage(device, activity) { - let cmd = `adb -s ${device.serial()} shell am start -n ${activity}` - logWithDevice("cmd is " + cmd, this.device) - await exec(cmd); + async getCurrentIP() { + let findIp = "" + try { + findIp = await this.page.evaluate(async () => { + const response = await fetch("https://api.ipify.org/", { + "headers": { + "content-type": "application/x-www-form-urlencoded; charset=UTF-8" + }, + "method": "GET" + }); + return await response.text(); + }) + } catch (e) { + console.log(e) + } + return findIp } }