2022-06-24 23:09:46 +04:00
|
|
|
package captcha
|
|
|
|
|
|
|
|
import (
|
|
|
|
"image"
|
2022-06-26 23:53:52 +04:00
|
|
|
"justcaptcha/pkg/captcha"
|
2022-06-24 23:09:46 +04:00
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2022-08-19 02:09:01 +04:00
|
|
|
var captchaDb captcha.CaptchaDB
|
2022-06-24 23:09:46 +04:00
|
|
|
|
2022-06-26 20:53:48 +04:00
|
|
|
func Init(expiry time.Duration) {
|
2022-08-19 02:09:01 +04:00
|
|
|
captchaDb = captcha.NewInMemoryCaptchaDB(expiry)
|
2022-06-24 23:09:46 +04:00
|
|
|
}
|
|
|
|
|
2022-08-19 02:09:01 +04:00
|
|
|
func New(data string) (captcha.Captcha, captcha.ID) {
|
|
|
|
dc := NewDwellingCaptcha(captchaDb.GetExpiry())
|
|
|
|
return captchaDb.New(data, dc)
|
2022-06-24 23:09:46 +04:00
|
|
|
}
|
|
|
|
|
2022-08-17 21:47:27 +04:00
|
|
|
func Image(id captcha.ID, style string) (*image.Image, error) {
|
2022-06-27 01:20:36 +04:00
|
|
|
return captchaDb.Image(id, style)
|
2022-06-24 23:09:46 +04:00
|
|
|
}
|
|
|
|
|
2022-06-26 23:53:52 +04:00
|
|
|
func Solve(id captcha.ID, answer captcha.Answer) (bool, error) {
|
2022-06-24 23:09:46 +04:00
|
|
|
return captchaDb.Solve(id, answer)
|
|
|
|
}
|
|
|
|
|
2022-06-26 23:53:52 +04:00
|
|
|
func IsSolved(id captcha.ID) (bool, error) {
|
2022-06-24 23:09:46 +04:00
|
|
|
return captchaDb.IsSolved(id)
|
|
|
|
}
|
2022-06-26 15:46:23 +04:00
|
|
|
|
2022-06-26 20:53:48 +04:00
|
|
|
func GetExpiry() time.Duration {
|
2022-06-27 01:10:52 +04:00
|
|
|
return captchaDb.GetExpiry()
|
2022-06-26 15:46:23 +04:00
|
|
|
}
|