diff --git a/.env.example b/.env.example index 462dd22..62f348e 100644 --- a/.env.example +++ b/.env.example @@ -4,4 +4,5 @@ SEED_DB=true IS_RATE_LIMITER_ENABLED=true THREADS_MAX_COUNT=50 POSTGRES_URL=postgres://localhost/micrach?pool_max_conns=5 -THREAD_BUMP_LIMIT=500 \ No newline at end of file +THREAD_BUMP_LIMIT=500 +IS_CAPTCHA_ACTIVE=true \ No newline at end of file diff --git a/config/config.go b/config/config.go index baaddf4..1124423 100644 --- a/config/config.go +++ b/config/config.go @@ -14,6 +14,7 @@ type AppConfig struct { IsRateLimiterEnabled bool ThreadsMaxCount int ThreadBumpLimit int + IsCaptchaActive bool } type DbConfig struct { @@ -52,6 +53,7 @@ func getAppConfig() AppConfig { isRateLimiterEnabled := getValueOrDefaultBoolean(os.Getenv("IS_RATE_LIMITER_ENABLED"), true) threadsMaxCount := getValueOrDefaultInt(os.Getenv("THREADS_MAX_COUNT"), 50) threadBumpLimit := getValueOrDefaultInt(os.Getenv("THREAD_BUMP_LIMIT"), 500) + isCaptchaActive := getValueOrDefaultBoolean(os.Getenv("IS_CAPTCHA_ACTIVE"), true) return AppConfig{ Env: env, @@ -60,6 +62,7 @@ func getAppConfig() AppConfig { IsRateLimiterEnabled: isRateLimiterEnabled, ThreadsMaxCount: threadsMaxCount, ThreadBumpLimit: threadBumpLimit, + IsCaptchaActive: isCaptchaActive, } } diff --git a/controllers/threads_controller.go b/controllers/threads_controller.go index 7b38b25..a357da3 100644 --- a/controllers/threads_controller.go +++ b/controllers/threads_controller.go @@ -58,7 +58,8 @@ func GetThreads(c *gin.Context) { PagesCount: pagesCount, Page: page, FormData: Repositories.HtmlFormData{ - CaptchaID: captchaID, + CaptchaID: captchaID, + IsCaptchaActive: Config.App.IsCaptchaActive, }, } c.HTML(http.StatusOK, "index.html", htmlData) @@ -87,8 +88,9 @@ func GetThread(c *gin.Context) { htmlData := Repositories.GetThreadHtmlData{ Thread: thread, FormData: Repositories.HtmlFormData{ - FirstPostID: firstPost.ID, - CaptchaID: captchaID, + FirstPostID: firstPost.ID, + CaptchaID: captchaID, + IsCaptchaActive: Config.App.IsCaptchaActive, }, } c.HTML(http.StatusOK, "thread.html", htmlData) diff --git a/repositories/structs.go b/repositories/structs.go index 66fee40..38cda47 100644 --- a/repositories/structs.go +++ b/repositories/structs.go @@ -34,8 +34,9 @@ type File struct { // post-form.html type HtmlFormData struct { - FirstPostID int - CaptchaID string + FirstPostID int + CaptchaID string + IsCaptchaActive bool } // thread.html diff --git a/templates/post-form.html b/templates/post-form.html index b40e232..8c7bea9 100644 --- a/templates/post-form.html +++ b/templates/post-form.html @@ -15,11 +15,13 @@ + {{ if .IsCaptchaActive }}