add await

This commit is contained in:
PAN Lei
2023-01-12 15:55:01 +01:00
parent aa8cb2da99
commit 0f4a990d1a
4 changed files with 24 additions and 16 deletions
+2 -1
View File
@@ -21,7 +21,8 @@
"node-xlsx": "^0.21.0",
"playwright": "1.23.0",
"read-ini-file": "^3.0.1",
"winston": "^3.8.2"
"winston": "^3.8.2",
"yarn": "^1.22.19"
},
"devDependencies": {
"@electron-forge/cli": "^6.0.0-beta.66",
+7 -5
View File
@@ -1,3 +1,5 @@
import {devices} from "playwright";
const {SolveCaptcha, TWO_CAPTCHA_CONNECTION_FAILED} = require("./SolveCaptcha");
const ReserveResultPojo = require("../models/ReserveResultPojo");
const BlackListContactPojo = require("../models/BlackListContactPojo");
@@ -9,7 +11,7 @@ const {
const GeoCaptchaSolver = require("./GeoCaptchaSolver");
// const RDV_URL = "http://192.168.0.41:8000/test_appointment.html"
const RDV_URL = "https://rendezvousparis.hermes.com/client/register";
BLANK_URL = "about:blank"
const BLANK_URL = "about:blank"
const ERROR_CAPTCHA_UNSOLVABLE = "ERROR_CAPTCHA_UNSOLVABLE";
const COUNTRY_ID = "#phone_country"
@@ -34,9 +36,9 @@ const TOO_MANY_REQUEST_ERROR_MESSAGE = "Due to a large number of requests"
const TOO_MANY_REQUEST_ERROR_MESSAGE_FR = "Suite à un trop grand nombre de demandes"
const CAPTCHA_ERROR_MESSAGE = "Error verifying captcha, please try again"
const CAPTCHA_ERROR_MESSAGE_FR = "La vérification du captcha a échoué"
REGEX_RDV_URL = "https:\/\/rendezvousparis\.hermes\.com\/client\/register\/[A-Z0-9]+"
const REGEX_RDV_URL = "https:\/\/rendezvousparis\.hermes\.com\/client\/register\/[A-Z0-9]+"
const DEFAULT_STORE = 'faubourg';
const searchTexts = ['hermes+rdv', 'hermes+rendezvous', 'hermes+appointment','hermes+appointment+online', 'appointment+hermes','hermes+rendez+vous', 'online+appointment+hermes', 'hermes+online+appointment']
const searchTexts = ['hermes+rdv', 'hermes+rendezvous', 'hermes+appointment', 'hermes+appointment+online', 'appointment+hermes', 'hermes+rendez+vous', 'online+appointment+hermes', 'hermes+online+appointment']
function delay(delayInMs) {
return new Promise(resolve => {
@@ -121,8 +123,8 @@ class CommandorPage {
let cancel
const intervalTask = setInterval(() => {
if (this.isTerminated) {
log("request terminated, will close device")
context.close()
log(this.device.model() + ":request terminated, will close device");
context.close();
// this.page.close()
this.device.close()
clearInterval(intervalTask)
+11 -5
View File
@@ -34,7 +34,13 @@ async function sendRequest(fileName, callback) {
headers: {
'Content-Type': 'wav',
'Authorization': 'Bearer 97e36f7e-340e-4c02-b329-9415faee38c3'
}
},
timeout: 30 * 1000
}).catch(err => {
console.log(err.code);
console.log(err.stack);
console.log(err.message);
callback([]);
})
if (response.status === 200) {
let result = response.data;
@@ -60,19 +66,19 @@ class GeoCaptchaSolver {
}
async solve(onResult) {
console.log("solve() called.")
console.log("play audio")
console.log(this.device.model() + ":solve() called.")
console.log(this.device.model() + ":play audio")
let iframeHandler = await this.page.frameLocator("body > iframe");
let playAudioBtn = await iframeHandler.locator(PLAY_AUDIO_BTN_ID);
try {
playAudioBtn.click();
await playAudioBtn.click();
} catch (e) {
console.log(e)
}
await delay(4000 + getRandomWaitTime());
let captcha_container = await iframeHandler.locator(CAPTCHA_CONTAINER)
let html = await captcha_container.innerHTML()
console.log("audio_tag: " + html);
console.log(this.device.model() + ":audio_tag: " + html);
if (!html.includes("You have been blocked")) {
// find wav from html
await this.findTextFromWavFile(html, async (number_list) => {
+4 -5
View File
@@ -79,7 +79,7 @@ class LinkValidator {
let cancel
const intervalTask = setInterval(() => {
if (this.isTerminated) {
log("request terminated, will close device")
log(this.device.model() + ":request terminated, will close device")
context.close()
// this.page.close()
this.device.close()
@@ -106,7 +106,7 @@ class LinkValidator {
let content = await currentPage.content();
let captcha_url = "geo.captcha-delivery.com/captcha";
if (content.toString().includes(captcha_url)) {
log("发现datadome");
log(this.device.model() + ":发现datadome");
await this.checkAudioBtn();
} else {
if (content.includes(CONFIRMED_MESSAGE) || content.includes(CONFIRMED_MESSAGE_FR) || content.includes(CONFIRMED_MESSAGE_CN)) {
@@ -129,10 +129,10 @@ class LinkValidator {
let audioBtn = await this.page.frameLocator("iframe").locator("#captcha__audio__button");
let isBlocked = await this.isBlocked()
if (!isBlocked) {
log("audioBtn found")
log(this.device.model() + ":audioBtn found")
if (!this.isTerminated) {
try {
audioBtn.click()
await audioBtn.click()
let captchaSolver = new GeoCaptchaSolver(this.page, this.device, this.isTerminated)
await captchaSolver.solve((isSuccessful) => {
if (!isSuccessful) {
@@ -148,7 +148,6 @@ class LinkValidator {
log("audioBtn not found")
console.log("audioBtn not found")
console.log("we are blocked")
//
await this.resetBrowser()
}
}