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-07-30 15:31:47 +04:00
|
|
|
var captchaDb captcha.InMemoryCaptchaDB = captcha.InMemoryCaptchaDB{
|
|
|
|
DB: make(map[captcha.ID]captcha.Captcha)}
|
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-07-30 15:31:47 +04:00
|
|
|
func New(data string, captcha captcha.Captcha) (captcha.Captcha, captcha.ID) {
|
2022-06-24 23:09:46 +04:00
|
|
|
return captchaDb.New(data, captcha)
|
|
|
|
}
|
|
|
|
|
2022-07-30 15:31:47 +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
|
|
|
}
|