add possibility to validate url by mobile

This commit is contained in:
2022-12-08 13:13:25 +01:00
parent d1478e734b
commit 32347a3865
4 changed files with 286 additions and 3 deletions
+37
View File
@@ -0,0 +1,37 @@
const {MongoManager} = require("./workers/mongo_manager");
const {_android: android} = require("playwright");
const alert = require("alert");
const LinkValidator = require("./workers/LinkValidator");
const mongoManager = new MongoManager();
mongoManager.connect().then(r => {
android.devices().then((devices) => {
if (devices.length === 0) {
alert("未找到连接的设备");
return
}
mongoManager.getAllLinkToValidate().then(list => {
let segmentNumber = list.length / devices.length;
console.log("connected device number:" + devices.length)
console.log("segmentNumber:" + segmentNumber)
for (let i = 0; i < devices.length; i++) {
startWithList(list.slice(i * segmentNumber, segmentNumber * (i + 1)), devices[i]).then(result => {
console.log("stop")
})
}
})
})
});
async function startWithList(listOfUrls, device) {
await listOfUrls.reduce(async (promise, urlToValidate) => {
// This line will wait for the last async function to finish.
// The first iteration uses an already resolved Promise
// so, it will immediately continue.
await promise;
let commandor = new LinkValidator(device, urlToValidate.url, mongoManager);
await commandor.loadPage()
console.log("next");
}, Promise.resolve());
}