Skip to content

Commit

Permalink
More changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamikadze4GAME committed Nov 28, 2018
1 parent add2b47 commit be6c8ac
Show file tree
Hide file tree
Showing 9 changed files with 179 additions and 40 deletions.
7 changes: 4 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
const Anticaptcha = require('./lib/anticaptcha');
const Proxy = require('./lib/proxy');
const Tasks = require('./lib/tasks');
const FormBuilder = require('./lib/formBuilder');
const Errors = require('./lib/errors');
const Form = require('./lib/form');
const Errors = require('./lib/errors');

module.exports = Anticaptcha;
module.exports.Anticaptcha = Anticaptcha;
module.exports.Proxy = Proxy;
module.exports.Form = Form;
module.exports.Errors = Errors;
module.exports.FormBuilder = FormBuilder;
module.exports.ApiError = Errors.ApiError;

Object.keys(Tasks).forEach(task => {
module.exports[task] = Tasks[task];
Expand Down
4 changes: 2 additions & 2 deletions lib/anticaptcha.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class Anticaptcha {
return this.getTaskResult(taskId, { extended: true })
.then(res => {
if(!res) return res;

if(res.status === 'processing') {
return Promise.delay(waitTime[(opts._step === 1 ? 1 : 0)])
.then(_ => {
Expand All @@ -189,7 +189,7 @@ class Anticaptcha {
if(!opts.extended) {
return res.solution;
}

delete res.status;
return res;
})
Expand Down
3 changes: 2 additions & 1 deletion lib/fields/field.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@ class ContentField extends Field {
}

class InputField extends Field {
constructor(label, type, name, opts) {
constructor(label, type, name, opts, value) {
super(label);
this._type = type;
this._name = name;
this._options = opts;
this._value = value;
}

toJSON() {
Expand Down
5 changes: 3 additions & 2 deletions lib/fields/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
const Field = require('./field');
const ContentField = Field.ContentField;
const InputField = Field.InputField;
//

const TextField = require('./text');
const LinkField = require('./link');
const ImageField = require('./image');
//

const TextboxField = require('./textbox');
const TextareaField = require('./textarea');
const CheckboxField = require('./checkbox');
Expand All @@ -24,6 +24,7 @@ module.exports = {
TextField,
LinkField,
ImageField,

TextboxField,
TextareaField,
CheckboxField,
Expand Down
2 changes: 1 addition & 1 deletion lib/fields/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const ContentField = require('./field').ContentField;

class LinkField extends ContentField {
constructor(label, url, text) {
super(label, 'link', {url, text});
super(label, 'link', { url, text });
}
}

Expand Down
10 changes: 5 additions & 5 deletions lib/formBuilder.js → lib/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
const Fields = require('./fields');
const Field = Fields.Field;

class FormBuilder {
// TODO: add check name func
class Form {
// TODO: add check fields name
constructor(opts = {/*checkname:false*/}) {
this._opts = opts;

Expand All @@ -16,7 +16,7 @@ class FormBuilder {
add(field) {
let id;
if(!(field instanceof Field)) {
throw new Error('Field is not instance of Field class');
throw new Error('Argument is not instance of Field class');
}
id = this._lastId++;
this._fields[id] = field;
Expand All @@ -40,7 +40,7 @@ class FormBuilder {
}

Object.keys(Fields).forEach(field => {
FormBuilder[field] = Fields[field];
Form[field] = Fields[field];
});

module.exports = FormBuilder;
module.exports = Form;
15 changes: 11 additions & 4 deletions lib/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const VALID_PROXY_TYPES = ['http', 'socks4', 'socks5'];

class Proxy {
constructor(data = {/* type, address, port, ?login, ?password, agent, ?cookies */}) {
this._data = {};

if(data instanceof Proxy) {
data = data.get();
}
Expand Down Expand Up @@ -40,24 +42,29 @@ class Proxy {
res.proxyType = data.type;
res.proxyAddress = data.address;
res.proxyPort = data.port;
res.userAgent = data.agent;

if(typeof this._login !== 'undefined') {
if(typeof data.login !== 'undefined') {
res.proxyLogin = data.login;
}

if(typeof this._password !== 'undefined') {
if(typeof data.password!== 'undefined') {
res.proxyPassword = data.password;
}

if(typeof this._cookies !== 'undefined') {
res.userAgent = data.agent;

if(typeof data.cookies !== 'undefined') {
res.cookies = data.cookies;
}

return res;
}

static checkProxy(proxyData = {}) {
if(proxyData instanceof Proxy) {
proxyData = proxyData.get();
}

if(VALID_PROXY_TYPES.indexOf(proxyData.type) === -1) {
throw new Error(`Invalid proxy type '${res.type}'. Valid: ${VALID_PROXY_TYPES.join(', ')}. `);
}
Expand Down
35 changes: 18 additions & 17 deletions lib/tasks/customCaptchaTask.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,41 @@
const clone = require('clone');

const Task = require('./task');
const FormBuilder = require('../formBuilder');
const Form = require('../form');

class CustomCaptchaTask extends Task {
constructor(opts = {/*url, assignment, forms*/}) {
let forms = opts.forms;
constructor(opts = {/*url, assignment, form*/}) {
let form = opts.forms;

if(forms instanceof FormBuilder) {
forms = forms.toJSON();
if(form instanceof Form) {
form = form.toJSON();
}

super('SquareNetTextTask', {
super('CustomCaptchaTask', {
url : opts.url,
assignment: opts.assignment,
forms : forms
form : form
}, false, 5*1000);
}

toJSON() {
let data = this.data;
return super.toJSON({
imageUrl : opts.url,
assignment: opts.assignment,
forms : opts.forms
imageUrl : data.url,
assignment: data.assignment,
forms : data.form
});
}

static parseResult(data = {}) {
return {
taskId : data.taskId,
imageUrl : data.imageUrl,
assignment: data.assignment,
status : data.status,
answers : clone(data.answers)
};
return clone(data.answers);
// return {
// taskId : data.taskId,
// imageUrl : data.imageUrl,
// assignment: data.assignment,
// status : data.status,
// answers : clone(data.answers)
// };
}
}

Expand Down
138 changes: 133 additions & 5 deletions tests/test_1.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

const Anticaptcha = require('..');
const Proxy = Anticaptcha.Proxy;


const Form = Anticaptcha.Form;


let proxy = new Proxy({
Expand All @@ -15,10 +14,139 @@ let proxy = new Proxy({

let a = new Anticaptcha('c4fbd67246c4b57dc89c2c3187ae2e71');

let task = new Anticaptcha.NoCaptchaTask({url:'https://www.boards.ie/', sitekey: '6LfBixYUAAAAABhdHynFUIMA_sa4s-XsJvnjtgB0'}, proxy);
let task = new Anticaptcha.NoCaptchaTask({url:'https://www.boards.ie/', sitekey: '6LfBixYUAAAAABhdHynFUIMA_sa4s-XsJvnjtgB0'});
//
// a.getTaskResult(123518664, {
// extended: true,
// wait: true
// })
// // a.createTask(task)
// .then(_ => {
// console.log('res', _);
// })
// .catch(err => {
// console.log(err);
// })


let form = new Form();

// form.add(new Form.TextField('Label of the field', 'Some text...'));
// form.add(new Form.TextareaField(['Enter some text', 'For example your story'], 'nameOfArea', {
// placeholder: 'Placeholder for texarea'
// }));
// form.add(new Form.SelectField('Select HEX', 'nameOfSelect', {
// red: '#F00',
// black: '#000',
// white: '#FFF'
// }));

form.add(new Form.TextareaField('Describe car', 'desc', {
// placeholder: 'Placeholder for texarea'
}));
form.add(new Form.SelectField('Select color', 'color', {
red: 'red',
black: 'black',
white: 'white'
}));
form.add(new Form.CheckboxField('Is it car?', 'isCar', {
text: 'Yes',
value: 'yes'
}));
form.add(new Form.CheckboxField('Is it car?', 'isCar2', {
text: 'Yes'
}));

form.add(new Form.CheckboxField('Is it bus?', 'isBus', {
text: 'Yes',
value: 'no'
}));

form.add(new Form.TextboxField('Do not touch it', 'text', {
placeholder: 'DO NOT TOUCH'
}));

// a.getTaskResult(122284760, {extended: false, wait:true})
a.solve(task)
// console.dir(form.toJSON(), {depth:null});

// form.add(new Form.CheckboxField('Is it ?', 'isBus', {
// text: 'Yes',
// value: 'yes'
// }));


/*
[ { label: 'Describe car',
name: 'desc',
value: undefined,
inputType: 'textarea',
inputOptions: {} },
{ label: 'Select color',
name: 'color',
value: undefined,
inputType: 'select',
inputOptions:
[ { value: 'red', caption: 'red' },
{ value: 'black', caption: 'black' },
{ value: 'white', caption: 'white' } ] },
{ label: 'Is it car?',
name: 'isCar',
value: 'yes',
inputType: 'checkbox',
inputOptions: { label: 'Yes' } },
{ label: 'Is it car?',
name: 'isCar2',
value: undefined,
inputType: 'checkbox',
inputOptions: { label: 'Yes' } },
{ label: 'Is it bus?',
name: 'isBus',
value: 'no',
inputType: 'checkbox',
inputOptions: { label: 'Yes' } },
{ label: 'Do not touch it',
name: 'text',
value: 'DO NOT TOUCH PLEASE',
inputType: 'text',
inputOptions: { placeHolder: 'DO NOT TOUCH' } } ]
*/

let task2 = new Anticaptcha.CustomCaptchaTask({url:'https://www.drivespark.com/car-image/640x480x100/car/300x225x46701008-audi_a3_cabriolet.jpg.pagespeed.ic.drG8tpM8fT.jpg_', assignment: 'Select color of the car and upload any file', forms: [ { label: 'Describe car',
name: 'desc',
value: undefined,
inputType: 'textarea',
inputOptions: {} },
{ label: 'Select color',
name: 'color',
value: undefined,
inputType: 'select',
inputOptions:
[ { value: 'red', caption: 'red' },
{ value: 'black', caption: 'black' },
{ value: 'white', caption: 'white' } ] },
{ label: 'Is it car?',
name: 'isCar',
value: 'yes',
inputType: 'checkbox',
inputOptions: { label: 'Yes' } },
{ label: 'Is it car?',
name: 'isCar2',
value: false,
inputType: 'checkbox',
inputOptions: { label: 'Yes' } },
{ label: 'Is it bus?',
name: 'isBus',
value: false,
inputType: 'checkbox',
inputOptions: { label: 'Yes' } } ]});



// 26433
a.getTaskResult(10524514, {
extended: true,
wait: true
})
// a.createTask(task2)
.then(_ => {
console.log('res', _);
})
Expand Down

0 comments on commit be6c8ac

Please sign in to comment.