add support for LinkValidator
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
"electron-squirrel-startup": "^1.0.0",
|
||||
"mongodb": "^4.9.1",
|
||||
"mongoose": "^6.5.4",
|
||||
"node-schedule": "^2.1.0",
|
||||
"node-wget": "^0.4.3",
|
||||
"node-xlsx": "^0.21.0",
|
||||
"playwright": "1.23.0",
|
||||
|
||||
+18
-2
@@ -3,8 +3,11 @@ const {_android: android} = require("playwright");
|
||||
const alert = require("alert");
|
||||
const LinkValidator = require("./workers/LinkValidator");
|
||||
const mongoManager = new MongoManager();
|
||||
const schedule = require('node-schedule');
|
||||
let canContinue = true;
|
||||
|
||||
function validateLinks() {
|
||||
|
||||
mongoManager.connect().then(r => {
|
||||
android.devices().then((devices) => {
|
||||
if (devices.length === 0) {
|
||||
alert("未找到连接的设备");
|
||||
@@ -14,15 +17,18 @@ mongoManager.connect().then(r => {
|
||||
let segmentNumber = list.length / devices.length;
|
||||
console.log("connected device number:" + devices.length)
|
||||
console.log("segmentNumber:" + segmentNumber)
|
||||
canContinue = false;
|
||||
for (let i = 0; i < devices.length; i++) {
|
||||
startWithList(list.slice(i * segmentNumber, segmentNumber * (i + 1)), devices[i]).then(result => {
|
||||
console.log("stop")
|
||||
canContinue = true;
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
async function startWithList(listOfUrls, device) {
|
||||
await listOfUrls.reduce(async (promise, urlToValidate) => {
|
||||
@@ -35,3 +41,13 @@ async function startWithList(listOfUrls, device) {
|
||||
console.log("next");
|
||||
}, Promise.resolve());
|
||||
}
|
||||
|
||||
mongoManager.connect().then(r => {
|
||||
const job = schedule.scheduleJob('*/1 * * * *', function () {
|
||||
if (canContinue) {
|
||||
validateLinks()
|
||||
} else {
|
||||
console.log("job is executing, ignored")
|
||||
}
|
||||
})
|
||||
});
|
||||
@@ -30,6 +30,7 @@ REGEX_RDV_URL = "https:\/\/rendezvousparis\.hermes\.com\/client\/register\/[A-Z0
|
||||
const PLAY_AUDIO_BTN_ID = ".audio-captcha-play-button"
|
||||
const homedir = require('os').homedir();
|
||||
const CAPTCHA_CONTAINER = "#captcha-container";
|
||||
|
||||
function delay(delayInMs) {
|
||||
return new Promise(resolve => {
|
||||
setTimeout(() => {
|
||||
@@ -62,6 +63,7 @@ class LinkValidator {
|
||||
// Connect to the device.
|
||||
log("loadPage() called for url " + this.urlToValidate);
|
||||
// await this.device.shell('am force-stop com.android.chrome');
|
||||
try {
|
||||
const context = await this.device.launchBrowser();
|
||||
// await context.clearCookies()
|
||||
|
||||
@@ -100,6 +102,10 @@ class LinkValidator {
|
||||
}
|
||||
setTimeout(fulfill, TIME_OUT, 5)
|
||||
}).then(log)
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async onPageLoad(currentPage) {
|
||||
|
||||
Reference in New Issue
Block a user