Answer the question
In order to leave comments, you need to log in
How to transfer the received value of a variable from one async function to another function in Node JS?
Good evening. There is some anticaptcha.getBalance function:
var anticaptcha = require('./anticaptcha')('***'), image2base64 = require('image-to-base64');
anticaptcha.getBalance(async function (err, balance) {
if (err) {
console.error(err);
return;
}
anticaptcha.setMinLength(5);
const API_URL = 'https://api.vk.com/captcha.php?sid=159568716370&s=1';
const body = await image2base64(API_URL).catch((error) => console.log(error));
if (balance > 0) {
anticaptcha.createImageToTextTask({
case: true, // or params can be set for every captcha specially
body
},
function (err, taskId) {
if (err) {
console.error(err);
return;
}
console.log(taskId);
anticaptcha.getTaskSolution(taskId, function (err, taskSolution) {
if (err) {
console.error(err);
return;
}
console.log(taskSolution);
});
}
);
}
});
// Init app
(async _=> {
setUTitle("Loading app");
if(!VK_TOKEN) {
let succ = await initToken();
if(!succ) { process.exit(); }
}
vk.token = VK_TOKEN;
vk.captchaHandler = async ({ src, type }, retry)=> {
let key = await rl.questionAsync("Введи капчу ["+src+"]: ");
try {
await retry(key);
con('Всё ок.');
} catch (e) { con("Всё фигово. "+e.message, true); }
};
})();
Answer the question
In order to leave comments, you need to log in
let getTaskSolution = (src) => {
return new Promise((resolve, reject) => {
anticaptcha.getBalance(async (err, balance) => {
if (err) {
reject(err);
return;
}
anticaptcha.setMinLength(5);
if (balance > 0) {
anticaptcha.createImageToTextTask({
case: true, // or params can be set for every captcha specially
body: await image2base64(src).catch(reject)
}, (err, taskId) => {
if (err) {
reject(err);
return;
}
anticaptcha.getTaskSolution(taskId, (err, taskSolution) => {
if (err) {
reject(err);
return;
}
resolve(taskSolution)
});
});
}
});
});
};
(async () => {
setUTitle("Loading app");
if (!VK_TOKEN) {
let succ = await initToken();
if (!succ) {
process.exit();
}
}
vk.token = VK_TOKEN;
vk.captchaHandler = async ({src, type}, retry) => {
let key = await getTaskSolution(src).catch((error) => console.log(error));
try {
await retry(key);
con('Всё ок.');
} catch (e) {
con("Всё фигово. " + e.message, true);
}
};
})();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question