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