fix: add X-Api-Key header for captcha OCR requests
ci/woodpecker/push/build Pipeline was canceled
ci/woodpecker/tag/build Pipeline was successful

The captcha OCR service now requires X-Api-Key authentication.
Add captcha.apiKey config option and pass it as header in all
OCR-related API calls (ocr, semiOcr, calc).
This commit is contained in:
becomer
2026-07-01 20:22:03 +08:00
parent 2879336ce4
commit ecfa50359b
3 changed files with 8 additions and 3 deletions
+1
View File
@@ -38,6 +38,7 @@ mode = "dev"
[captcha] [captcha]
#baseUrl = "http://captcha-resolver.out" #baseUrl = "http://captcha-resolver.out"
baseUrl = "http://likedream-go-captcha:8890" baseUrl = "http://likedream-go-captcha:8890"
apiKey = "baca122..."
[redis] [redis]
url = "redis://:jhkdjhkjdhsIUTYURTU_pEGmFP@database.out:56379" url = "redis://:jhkdjhkjdhsIUTYURTU_pEGmFP@database.out:56379"
+6 -3
View File
@@ -16,13 +16,14 @@ func ApiSemiOCRVerification(bytes []byte, shape1, shape2 int64) string {
data := Bytes2Base64(bytes) data := Bytes2Base64(bytes)
ctx := gctx.GetInitCtx() ctx := gctx.GetInitCtx()
baseUrl := g.Config().MustGetWithEnv(ctx, cst.ConfigCaptchaBaseUrl).String() + "/semiOcr" baseUrl := g.Config().MustGetWithEnv(ctx, cst.ConfigCaptchaBaseUrl).String() + "/semiOcr"
apiKey := g.Config().MustGetWithEnv(ctx, cst.ConfigCaptchaApiKey).String()
client := httpclient.Cpdaily.Clone(ctx) client := httpclient.Cpdaily.Clone(ctx)
client.SetDoNotParseResponse(false) client.SetDoNotParseResponse(false)
post, err := client.R().SetBody(map[string]any{ post, err := client.R().SetBody(map[string]any{
"base64": data, "base64": data,
"shape1": shape1, "shape1": shape1,
"shape2": shape2, "shape2": shape2,
}).Post(baseUrl) }).SetHeader("X-Api-Key", apiKey).Post(baseUrl)
utils.OkOrPanic(err, func(err error) error { utils.OkOrPanic(err, func(err error) error {
return oops. return oops.
With("SemiOCRVerification", baseUrl). With("SemiOCRVerification", baseUrl).
@@ -37,11 +38,12 @@ func ApiAutoOCRVerification(bytes []byte) string {
data := Bytes2Base64(bytes) data := Bytes2Base64(bytes)
ctx := gctx.GetInitCtx() ctx := gctx.GetInitCtx()
baseUrl := g.Config().MustGetWithEnv(ctx, cst.ConfigCaptchaBaseUrl).String() + "/ocr" baseUrl := g.Config().MustGetWithEnv(ctx, cst.ConfigCaptchaBaseUrl).String() + "/ocr"
apiKey := g.Config().MustGetWithEnv(ctx, cst.ConfigCaptchaApiKey).String()
client := httpclient.Cpdaily.Clone(ctx) client := httpclient.Cpdaily.Clone(ctx)
client.SetDoNotParseResponse(false) client.SetDoNotParseResponse(false)
post, err := client.R().SetBody(map[string]any{ post, err := client.R().SetBody(map[string]any{
"base64": data, "base64": data,
}).Post(baseUrl) }).SetHeader("X-Api-Key", apiKey).Post(baseUrl)
utils.OkOrPanic(err, func(err error) error { utils.OkOrPanic(err, func(err error) error {
return oops. return oops.
With("AutoOCRVerification", baseUrl). With("AutoOCRVerification", baseUrl).
@@ -55,11 +57,12 @@ func ApiAutoOCRVerification(bytes []byte) string {
func ApiAutoCalcVerification(b64 string) string { func ApiAutoCalcVerification(b64 string) string {
ctx := gctx.GetInitCtx() ctx := gctx.GetInitCtx()
baseUrl := g.Config().MustGetWithEnv(ctx, cst.ConfigCaptchaBaseUrl).String() + "/calc" baseUrl := g.Config().MustGetWithEnv(ctx, cst.ConfigCaptchaBaseUrl).String() + "/calc"
apiKey := g.Config().MustGetWithEnv(ctx, cst.ConfigCaptchaApiKey).String()
client := httpclient.Cpdaily.Clone(ctx) client := httpclient.Cpdaily.Clone(ctx)
client.SetDoNotParseResponse(false) client.SetDoNotParseResponse(false)
post, err := client.R().SetBody(map[string]any{ post, err := client.R().SetBody(map[string]any{
"base64": b64, "base64": b64,
}).Post(baseUrl) }).SetHeader("X-Api-Key", apiKey).Post(baseUrl)
utils.OkOrPanic(err, func(err error) error { utils.OkOrPanic(err, func(err error) error {
return oops. return oops.
With("AutoOCRVerification", baseUrl). With("AutoOCRVerification", baseUrl).
+1
View File
@@ -15,6 +15,7 @@ const (
ConfigAuthorizationKey = "server.authorization" ConfigAuthorizationKey = "server.authorization"
ConfigJwtKey = "server.jwt" ConfigJwtKey = "server.jwt"
ConfigCaptchaBaseUrl = "captcha.baseUrl" ConfigCaptchaBaseUrl = "captcha.baseUrl"
ConfigCaptchaApiKey = "captcha.apiKey"
ConfigS3AccessKey = "s3.accessKey" ConfigS3AccessKey = "s3.accessKey"
ConfigS3SecretKey = "s3.secretKey" ConfigS3SecretKey = "s3.secretKey"
ConfigS3BaseUrl = "s3.baseUrl" ConfigS3BaseUrl = "s3.baseUrl"