add current ip to db

This commit is contained in:
2024-03-05 15:01:51 +01:00
parent 2dd7abcb51
commit 25ce0eec2d
2 changed files with 23 additions and 12 deletions
+3 -1
View File
@@ -17,6 +17,7 @@ class ReserveResultPojo {
this.source_from = "" this.source_from = ""
this.serial = "" this.serial = ""
this.hostName = hostName this.hostName = hostName
this.currentIp = ""
this.created_at = new Date().toLocaleString() this.created_at = new Date().toLocaleString()
} }
@@ -33,7 +34,8 @@ class ReserveResultPojo {
source_from: this.source_from, source_from: this.source_from,
serial: this.serial, serial: this.serial,
created_at: this.created_at, created_at: this.created_at,
hostName: this.hostName hostName: this.hostName,
current_ip: this.currentIp
} }
} }
+20 -11
View File
@@ -173,8 +173,6 @@ class CommandorPage {
// await this.device.shell(swipCmd); // await this.device.shell(swipCmd);
await delay(3 * getRandomWaitTime()); await delay(3 * getRandomWaitTime());
} }
// await this.openGoogle()
// await delay(3 * getRandomWaitTime());
await this.clickOnHomeBtn(); await this.clickOnHomeBtn();
await this.checkResultWithOcr(); await this.checkResultWithOcr();
} }
@@ -762,6 +760,9 @@ class CommandorPage {
} }
async push_message_to_db(publishType, url) { async push_message_to_db(publishType, url) {
let currentIp = await this.getCurrentIP()
logWithDevice("currentIp is " + currentIp, this.device)
let splitedUrl = url.split("/"); let splitedUrl = url.split("/");
let id = splitedUrl[splitedUrl.length - 1]; let id = splitedUrl[splitedUrl.length - 1];
if (id === "register") { if (id === "register") {
@@ -773,6 +774,7 @@ class CommandorPage {
// save to mongoDb // save to mongoDb
let reserve = ReserveResultPojo.create_from_contact(this.contact, id, url, this.choosedStore, publishType); let reserve = ReserveResultPojo.create_from_contact(this.contact, id, url, this.choosedStore, publishType);
reserve.source_from = this.device.model(); reserve.source_from = this.device.model();
reserve.currentIp = currentIp
reserve.serial = this.device.serial(); reserve.serial = this.device.serial();
await this.mongoManager.saveReserveToDb(reserve.to_mongo_dict()) await this.mongoManager.saveReserveToDb(reserve.to_mongo_dict())
if (!this.page.isClosed()) { if (!this.page.isClosed()) {
@@ -1002,11 +1004,6 @@ class CommandorPage {
// reconnect to page and get url // reconnect to page and get url
if (!this.isTerminated) { if (!this.isTerminated) {
await this.connect_to_browser(OCRResult.SUCCESS) 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; break;
case case
@@ -1373,10 +1370,22 @@ class CommandorPage {
await delay(2000); await delay(2000);
} }
async startPage(device, activity) { async getCurrentIP() {
let cmd = `adb -s ${device.serial()} shell am start -n ${activity}` let findIp = ""
logWithDevice("cmd is " + cmd, this.device) try {
await exec(cmd); 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
} }
} }