@@ -277,22 +277,29 @@ func antiCaptchaMethods(solver *Solver, preferredDomain string) *solveMethods {
277277 "isInvisible" : o .Invisible ,
278278 }
279279
280- applyProxy (taskData , o .Proxy , "HCaptchaTask" )
280+ baseTask := "HCaptchaTask"
281+ if solver .service == CapSolver {
282+ baseTask = "HCaptchaTurboTask"
283+ }
284+
285+ applyProxy (taskData , o .Proxy , baseTask )
281286
282287 if o .UserAgent != "" {
283288 taskData ["userAgent" ] = o .UserAgent
284289 }
285290
286291 if o .EnterprisePayload != nil {
292+ ep := o .EnterprisePayload
293+
287294 // some apis are slightly different
288- if o . EnterprisePayload .RQData != "" {
295+ if ep .RQData != "" {
289296 taskData ["data" ] = o .EnterprisePayload .RQData
290297 }
291298
292- ep := o . EnterprisePayload
299+ payload := map [ string ] interface {}{}
293300
294- payload := map [ string ] interface {} {
295- "sentry" : ep .Sentry ,
301+ if ep . Sentry {
302+ payload [ "sentry" ] = ep .Sentry
296303 }
297304
298305 if ep .RQData != "" {
@@ -422,6 +429,74 @@ func antiCaptchaMethods(solver *Solver, preferredDomain string) *solveMethods {
422429 UserAgent : userAgent ,
423430 }, nil
424431 }
432+
433+ methods .Cloudflare = func (o CloudflareOptions ) (* Solution , error ) {
434+ if o .Proxy == nil {
435+ return nil , errors .New ("proxy is required" )
436+ }
437+
438+ if o .Metadata == nil {
439+ o .Metadata = map [string ]string {}
440+ }
441+
442+ // only set metadata type if one wasn't provided
443+ if _ , ok := o .Metadata ["type" ]; ! ok {
444+ switch o .Type {
445+ case CloudflareTypeChallenge :
446+ o .Metadata ["type" ] = "challenge"
447+ case CloudflareTypeTurnstile :
448+ o .Metadata ["type" ] = "turnstile"
449+ default :
450+ o .Metadata ["type" ] = ""
451+ }
452+ }
453+
454+ if _ , ok := o .Metadata ["action" ]; ! ok && o .Action != "" {
455+ o .Metadata ["action" ] = o .Action
456+ }
457+
458+ if _ , ok := o .Metadata ["cdata" ]; ! ok && o .CData != "" {
459+ o .Metadata ["cdata" ] = o .CData
460+ }
461+
462+ taskData := map [string ]interface {}{
463+ "websiteURL" : o .PageURL ,
464+ "metadata" : o .Metadata ,
465+ }
466+
467+ if o .SiteKey != "" {
468+ taskData ["websiteKey" ] = o .SiteKey
469+ }
470+
471+ applyProxy (taskData , o .Proxy , "AntiCloudflareTask" )
472+
473+ return createResponse (taskData )
474+ }
475+ } else {
476+ methods .Cloudflare = func (o CloudflareOptions ) (* Solution , error ) {
477+ if o .Type == CloudflareTypeChallenge {
478+ return nil , errors .New ("cloudflare challenge type is not supported by this solver" )
479+ }
480+
481+ taskData := map [string ]interface {}{
482+ "websiteURL" : o .PageURL ,
483+ "websiteKey" : o .SiteKey ,
484+ }
485+
486+ if o .Action != "" {
487+ taskData ["action" ] = o .Action
488+ }
489+
490+ if o .Metadata != nil {
491+ for k , v := range o .Metadata {
492+ taskData [k ] = v
493+ }
494+ }
495+
496+ applyProxy (taskData , o .Proxy , "TurnstileTask" )
497+
498+ return createResponse (taskData )
499+ }
425500 }
426501
427502 return methods
0 commit comments