@@ -3,13 +3,9 @@ package service
3
3
import (
4
4
"context"
5
5
"encoding/base64"
6
- "errors"
7
- "regexp"
8
- "strings"
9
6
10
7
"github.com/aaabhilash97/aadhaar_scrapper_apis/pkg/aadhaarapi"
11
8
api "github.com/aaabhilash97/aadhaar_scrapper_apis/pkg/api/v1"
12
- "github.com/otiai10/gosseract"
13
9
"go.uber.org/zap"
14
10
)
15
11
@@ -225,91 +221,90 @@ func (s AadhaarService) fetchAadhaarResFromCache(
225
221
}, nil
226
222
}
227
223
228
- func (s AadhaarService ) AutoVerifyCaptcha (ctx context.Context , req * api.AutoVerifyCaptchaRequest ) (res * api.AutoVerifyCaptchaResponse , err error ) {
229
- fn := "AutoVerifyCaptcha"
230
- if err = req .Validate (); err != nil {
231
- s .log .Error (fn , zap .Any ("req" , req ), zap .Error (err ))
232
- if err , ok := err .(api.AutoVerifyCaptchaRequestValidationError ); ok {
233
- if status := validationErrToStaus (ctx , err ); status != nil {
234
- return & api.AutoVerifyCaptchaResponse {
235
- Status : status ,
236
- }, nil
237
- }
238
- }
239
- return
240
- }
224
+ // func (s AadhaarService) AutoVerifyCaptcha(ctx context.Context, req *api.AutoVerifyCaptchaRequest) (res *api.AutoVerifyCaptchaResponse, err error) {
225
+ // fn := "AutoVerifyCaptcha"
226
+ // if err = req.Validate(); err != nil {
227
+ // s.log.Error(fn, zap.Any("req", req), zap.Error(err))
228
+ // if err, ok := err.(api.AutoVerifyCaptchaRequestValidationError); ok {
229
+ // if status := validationErrToStaus(ctx, err); status != nil {
230
+ // return &api.AutoVerifyCaptchaResponse{
231
+ // Status: status,
232
+ // }, nil
233
+ // }
234
+ // }
235
+ // return
236
+ // }
241
237
242
- var result aadhaarapi.VerifyCaptchaResult
243
- var sessionCookie string
244
- for i := 0 ; i <= 3 ; i ++ {
245
- s .log .Info (fn , zap .String ("info" , "fetching new captcha" ))
246
- var captchaImg []byte
247
- captchaImg , sessionCookie , err = aadhaarapi .GetCaptcha ()
248
- if err != nil {
249
- if aadhaarapi .IsRetryableError (err ) {
250
- s .log .Info (fn , zap .NamedError ("retrying_error" , err ))
251
- continue
252
- }
253
- break
254
- } else {
255
- s .log .Info (fn , zap .String ("info" , "captcha image fetch success" ))
256
- client := gosseract .NewClient ()
257
- defer client .Close ()
258
- err = client .SetImageFromBytes (captchaImg )
259
- if err != nil {
260
- s .log .Info (fn , zap .NamedError ("retrying_error" , err ))
261
- continue
262
- }
263
- var securityCode string
264
- securityCode , err = client .Text ()
265
- if err != nil {
266
- s .log .Info (fn , zap .NamedError ("retrying_error" , err ))
267
- continue
268
- }
269
- // Normalize security code
270
- securityCode = strings .ReplaceAll (securityCode , " " , "" )
271
- securityCode = strings .ReplaceAll (securityCode , "," , "I" )
272
- if re := regexp .MustCompile (`^[a-zA-Z0-9]+$` ); ! re .Match ([]byte (securityCode )) {
273
- err = errors .New ("Invalid captcha detected" )
274
- s .log .Info (fn , zap .String ("un_processable_security_code" , securityCode ))
275
- continue
276
- }
238
+ // var result aadhaarapi.VerifyCaptchaResult
239
+ // var sessionCookie string
240
+ // for i := 0; i <= 3; i++ {
241
+ // s.log.Info(fn, zap.String("info", "fetching new captcha"))
242
+ // var captchaImg []byte
243
+ // captchaImg, sessionCookie, err = aadhaarapi.GetCaptcha()
244
+ // if err != nil {
245
+ // if aadhaarapi.IsRetryableError(err) {
246
+ // s.log.Info(fn, zap.NamedError("retrying_error", err))
247
+ // continue
248
+ // }
249
+ // break
250
+ // } else {
251
+ // s.log.Info(fn, zap.String("info", "captcha image fetch success"))
252
+ // client := gosseract.NewClient()
253
+ // defer client.Close()
254
+ // err = client.SetImageFromBytes(captchaImg)
255
+ // if err != nil {
256
+ // s.log.Info(fn, zap.NamedError("retrying_error", err))
257
+ // continue
258
+ // }
259
+ // var securityCode string
260
+ // securityCode, err = client.Text()
261
+ // if err != nil {
262
+ // s.log.Info(fn, zap.NamedError("retrying_error", err))
263
+ // continue
264
+ // }
265
+ // // Normalize security code
266
+ // securityCode = strings.ReplaceAll(securityCode, " ", "")
267
+ // if re := regexp.MustCompile(`^[a-zA-Z0-9]+$`); !re.Match([]byte(securityCode)) {
268
+ // err = errors.New("Invalid captcha detected")
269
+ // s.log.Info(fn, zap.String("un_processable_security_code", securityCode))
270
+ // continue
271
+ // }
277
272
278
- result , err = aadhaarapi .VerifyCaptcha (aadhaarapi.VerifyCaptchaOpt {
279
- SessionId : sessionCookie ,
280
- UidNo : req .UidNo ,
281
- SecurityCode : securityCode ,
282
- })
283
- if aadhaarapi .IsInvalidCaptcha (err ) {
284
- s .log .Info (fn , zap .NamedError ("retrying_error" , err ))
285
- continue
286
- }
287
- s .log .Info (fn , zap .Any ("result" , result ))
288
- break
289
- }
290
- }
273
+ // result, err = aadhaarapi.VerifyCaptcha(aadhaarapi.VerifyCaptchaOpt{
274
+ // SessionId: sessionCookie,
275
+ // UidNo: req.UidNo,
276
+ // SecurityCode: securityCode,
277
+ // })
278
+ // if aadhaarapi.IsInvalidCaptcha(err) {
279
+ // s.log.Info(fn, zap.String("securityCode", securityCode) , zap.NamedError("retrying_error", err))
280
+ // continue
281
+ // }
282
+ // s.log.Info(fn, zap.Any("result", result))
283
+ // break
284
+ // }
285
+ // }
291
286
292
- if err != nil {
293
- s .log .Error (fn , zap .Any ("req" , req ), zap .Error (err ))
294
- return & api.AutoVerifyCaptchaResponse {
295
- Status : mapAadhaarErrToStatus (ctx , err ),
296
- }, nil
297
- }
298
- hash , err := s .aadhaarCacheStore .SaveSession (sessionCookie )
299
- if err != nil {
300
- s .log .Error (fn , zap .Any ("req" , req ), zap .Error (err ))
301
- return & api.AutoVerifyCaptchaResponse {
302
- Status : mapToStatus (ctx , ApiUnknownError , "" ),
303
- }, nil
304
- }
287
+ // if err != nil {
288
+ // s.log.Error(fn, zap.Any("req", req), zap.Error(err))
289
+ // return &api.AutoVerifyCaptchaResponse{
290
+ // Status: mapAadhaarErrToStatus(ctx, err),
291
+ // }, nil
292
+ // }
293
+ // hash, err := s.aadhaarCacheStore.SaveSession(sessionCookie)
294
+ // if err != nil {
295
+ // s.log.Error(fn, zap.Any("req", req), zap.Error(err))
296
+ // return &api.AutoVerifyCaptchaResponse{
297
+ // Status: mapToStatus(ctx, ApiUnknownError, ""),
298
+ // }, nil
299
+ // }
305
300
306
- return & api.AutoVerifyCaptchaResponse {
307
- Status : & api.ResponseStatus {
308
- Code : ApiSuccessCode ,
309
- Message : result .Msg ,
310
- },
311
- Data : & api.AutoVerifyCaptchaResponse_Data {
312
- SessionId : hash ,
313
- },
314
- }, nil
315
- }
301
+ // return &api.AutoVerifyCaptchaResponse{
302
+ // Status: &api.ResponseStatus{
303
+ // Code: ApiSuccessCode,
304
+ // Message: result.Msg,
305
+ // },
306
+ // Data: &api.AutoVerifyCaptchaResponse_Data{
307
+ // SessionId: hash,
308
+ // },
309
+ // }, nil
310
+ // }
0 commit comments