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-06-26 23:53:52 +04:00
|
|
|
var captchaDb captcha.CaptchaDB = captcha.CaptchaDB{
|
|
|
|
DB: make(map[captcha.ID]captcha.ICaptcha)}
|
2022-06-24 23:09:46 +04:00
|
|
|
|
2022-06-26 20:53:48 +04:00
|
|
|
func Init(expiry time.Duration) {
|
|
|
|
captchaDb.SetExpiry(expiry)
|
2022-06-24 23:09:46 +04:00
|
|
|
}
|
|
|
|
|
2022-06-26 23:53:52 +04:00
|
|
|
func New(data string, captcha captcha.ICaptcha) (captcha.ICaptcha, captcha.ID) {
|
2022-06-24 23:09:46 +04:00
|
|
|
return captchaDb.New(data, captcha)
|
|
|
|
}
|
|
|
|
|
2022-06-27 01:20:36 +04:00
|
|
|
func Image(id captcha.ID, style string) (*image.Image, error) {
|
|
|
|
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
|
|
|
}
|