fix
All checks were successful
Deploy / CreateImage (push) Successful in 2m10s
Deploy / DeployService (push) Successful in 24s

This commit is contained in:
Pasha 2025-04-23 18:39:15 +03:00
parent ac54bf45ee
commit 2e7d9fb5ee
4 changed files with 57 additions and 31 deletions

@ -7,6 +7,7 @@ import (
"gitea.pena/PenaSide/common/log_mw" "gitea.pena/PenaSide/common/log_mw"
"gitea.pena/PenaSide/hlog" "gitea.pena/PenaSide/hlog"
"gitea.pena/PenaSide/trashlog/wrappers/zaptrashlog" "gitea.pena/PenaSide/trashlog/wrappers/zaptrashlog"
"gitea.pena/SQuiz/answerer/clients"
dalBS "gitea.pena/SQuiz/answerer/dal" dalBS "gitea.pena/SQuiz/answerer/dal"
"gitea.pena/SQuiz/answerer/models" "gitea.pena/SQuiz/answerer/models"
"gitea.pena/SQuiz/answerer/savewc" "gitea.pena/SQuiz/answerer/savewc"
@ -19,7 +20,6 @@ import (
"github.com/go-redis/redis/v8" "github.com/go-redis/redis/v8"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
"github.com/minio/minio-go/v7" "github.com/minio/minio-go/v7"
"gitea.pena/SQuiz/answerer/clients"
"github.com/minio/minio-go/v7/pkg/credentials" "github.com/minio/minio-go/v7/pkg/credentials"
"github.com/skeris/appInit" "github.com/skeris/appInit"
"go.uber.org/zap" "go.uber.org/zap"
@ -175,6 +175,16 @@ func New(ctx context.Context, opts interface{}, ver appInit.Version) (appInit.Co
go saveClientWorker.Start(ctx) go saveClientWorker.Start(ctx)
app := fiber.New(fiber.Config{BodyLimit: 70 * 1024 * 1024}) app := fiber.New(fiber.Config{BodyLimit: 70 * 1024 * 1024})
app.Use(func(c *fiber.Ctx) error {
defer func() {
if err := recover(); err != nil {
c.Status(fiber.StatusInternalServerError).SendString("internal server error")
}
}()
return c.Next()
})
app.Use(middleware.AnswererChain()) app.Use(middleware.AnswererChain())
app.Use(log_mw.ContextLogger(loggerHlog)) app.Use(log_mw.ContextLogger(loggerHlog))
app.Get("/liveness", healthchecks.Liveness) app.Get("/liveness", healthchecks.Liveness)

4
go.mod

@ -18,8 +18,10 @@ require (
) )
require ( require (
gitea.pena/PenaSide/linters-golang v0.0.0-20241207122018-933207374735 // indirect
github.com/ClickHouse/clickhouse-go v1.5.4 // indirect github.com/ClickHouse/clickhouse-go v1.5.4 // indirect
github.com/andybalholm/brotli v1.1.0 // indirect github.com/andybalholm/brotli v1.1.0 // indirect
github.com/caarlos0/env/v8 v8.0.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58 // indirect github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
@ -36,6 +38,7 @@ require (
github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/minio/md5-simd v1.1.2 // indirect github.com/minio/md5-simd v1.1.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/rivo/uniseg v0.2.0 // indirect github.com/rivo/uniseg v0.2.0 // indirect
github.com/tealeg/xlsx v1.0.5 // indirect github.com/tealeg/xlsx v1.0.5 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect
@ -50,4 +53,5 @@ require (
google.golang.org/genproto/googleapis/rpc v0.0.0-20240610135401-a8a62080eff3 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240610135401-a8a62080eff3 // indirect
google.golang.org/grpc v1.64.0 // indirect google.golang.org/grpc v1.64.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/tucnak/telebot.v2 v2.5.0 // indirect
) )

5
go.sum

@ -2,6 +2,10 @@ gitea.pena/PenaSide/common v0.0.0-20250103085335-91ea31fee517 h1:EgBe8VcdPwmxbSz
gitea.pena/PenaSide/common v0.0.0-20250103085335-91ea31fee517/go.mod h1:91EuBCgcqgJ6mG36n2pds8sPwwfaJytLWOzY3h2YFKU= gitea.pena/PenaSide/common v0.0.0-20250103085335-91ea31fee517/go.mod h1:91EuBCgcqgJ6mG36n2pds8sPwwfaJytLWOzY3h2YFKU=
gitea.pena/PenaSide/hlog v0.0.0-20241125221102-a54c29c002a9 h1:tBkXWNIt8icmkMMnq8MA421RWkUy4OZh5P7C3q8uCu4= gitea.pena/PenaSide/hlog v0.0.0-20241125221102-a54c29c002a9 h1:tBkXWNIt8icmkMMnq8MA421RWkUy4OZh5P7C3q8uCu4=
gitea.pena/PenaSide/hlog v0.0.0-20241125221102-a54c29c002a9/go.mod h1:sanhSL8aEsfcq21P+eItYiAnKAre+B67nGJmDfk2cf0= gitea.pena/PenaSide/hlog v0.0.0-20241125221102-a54c29c002a9/go.mod h1:sanhSL8aEsfcq21P+eItYiAnKAre+B67nGJmDfk2cf0=
gitea.pena/PenaSide/linters-golang v0.0.0-20241119212350-2759fa93724a h1:UySqMgaOKNsR42Y6GQXoM2wn/waYNc9cakMUSvbEEAg=
gitea.pena/PenaSide/linters-golang v0.0.0-20241119212350-2759fa93724a/go.mod h1:gdd+vOT6up9STkEbxa2qESLIMZFjCmRbkcheFQCVgZU=
gitea.pena/PenaSide/linters-golang v0.0.0-20241207122018-933207374735 h1:jDVeUhGBTXBibmW5dmtJg2m2+z5z2Rf6J4G0LpjVoJ0=
gitea.pena/PenaSide/linters-golang v0.0.0-20241207122018-933207374735/go.mod h1:gdd+vOT6up9STkEbxa2qESLIMZFjCmRbkcheFQCVgZU=
gitea.pena/PenaSide/trashlog v0.0.0-20250224122049-ddb4d72e9d07 h1:bUIUgzXQt16aBqSccI//BaODpRCTIaqlddSepM98QSc= gitea.pena/PenaSide/trashlog v0.0.0-20250224122049-ddb4d72e9d07 h1:bUIUgzXQt16aBqSccI//BaODpRCTIaqlddSepM98QSc=
gitea.pena/PenaSide/trashlog v0.0.0-20250224122049-ddb4d72e9d07/go.mod h1:GRfWJerTUlgy82CiYAxE4tVYSVV54zEJJQy17Fx46E4= gitea.pena/PenaSide/trashlog v0.0.0-20250224122049-ddb4d72e9d07/go.mod h1:GRfWJerTUlgy82CiYAxE4tVYSVV54zEJJQy17Fx46E4=
gitea.pena/SQuiz/common v0.0.0-20250207214652-9994f2d4d43f h1:458FCN98jVkjAqg3yyspgkUdJnKz3BNMiZosrVtPpv8= gitea.pena/SQuiz/common v0.0.0-20250207214652-9994f2d4d43f h1:458FCN98jVkjAqg3yyspgkUdJnKz3BNMiZosrVtPpv8=
@ -107,6 +111,7 @@ github.com/skeris/appInit v1.0.2/go.mod h1:4ElEeXWVGzU3dlYq/eMWJ/U5hd+LKisc1z3+y
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/tealeg/xlsx v1.0.5 h1:+f8oFmvY8Gw1iUXzPk+kz+4GpbDZPK1FhPiQRd+ypgE= github.com/tealeg/xlsx v1.0.5 h1:+f8oFmvY8Gw1iUXzPk+kz+4GpbDZPK1FhPiQRd+ypgE=

@ -4,7 +4,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"gitea.pena/PenaSide/common/log_mw" "gitea.pena/PenaSide/common/log_mw"
"gitea.pena/SQuiz/answerer/clients" "gitea.pena/SQuiz/answerer/clients"
"gitea.pena/SQuiz/answerer/dal" "gitea.pena/SQuiz/answerer/dal"
"gitea.pena/SQuiz/answerer/models" "gitea.pena/SQuiz/answerer/models"
quizdal "gitea.pena/SQuiz/common/dal" quizdal "gitea.pena/SQuiz/common/dal"
@ -13,10 +13,10 @@ import (
"gitea.pena/SQuiz/common/utils" "gitea.pena/SQuiz/common/utils"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
"net/url" "net/url"
"strconv"
"strings" "strings"
"sync" "sync"
"time" "time"
"strconv"
"github.com/rs/xid" "github.com/rs/xid"
) )
@ -95,7 +95,7 @@ type ShavedQuiz struct {
DueTo uint64 `json:"due"` DueTo uint64 `json:"due"`
TimeOfPassing uint64 `json:"delay"` TimeOfPassing uint64 `json:"delay"`
Pausable bool `json:"pausable"` Pausable bool `json:"pausable"`
Status string `json:"status"` Status string `json:"status"`
} }
// ShavedQuestion shortened struct for delivery data to customer // ShavedQuestion shortened struct for delivery data to customer
@ -239,33 +239,40 @@ func (s *Service) GetQuizData(c *fiber.Ctx) error {
fp = cfp fp = cfp
} }
answers, errs := s.dal.AnswerRepo.CreateAnswers(c.Context(), []model.Answer{{ if req.NeedConfig {
Content: "start", if len(questions) == 0 {
QuestionId: questions[0].Id, return c.Status(fiber.StatusNotFound).SendString("question not found")
QuizId: quiz.Id, }
Start: true,
DeviceType: deviceType, answers, errs := s.dal.AnswerRepo.CreateAnswers(c.Context(), []model.Answer{{
Device: device, Content: "start",
Browser: browser, QuestionId: questions[0].Id,
IP: ip, QuizId: quiz.Id,
OS: os, Start: true,
Utm: utmData, DeviceType: deviceType,
}}, cs, fp, quiz.Id) Device: device,
if len(errs) != 0 { Browser: browser,
return c.Status(fiber.StatusInternalServerError).SendString(errs[0].Error()) IP: ip,
OS: os,
Utm: utmData,
}}, cs, fp, quiz.Id)
if len(errs) != 0 {
return c.Status(fiber.StatusInternalServerError).SendString(errs[0].Error())
}
hlogger.Emit(models.InfoQuizOpen{
KeyOS: os,
KeyDevice: device,
KeyDeviceType: deviceType,
KeyBrowser: browser,
CtxQuiz: req.QuizId,
CtxQuizID: int64(quiz.Id),
CtxReferrer: referrer,
CtxIDInt: int64(answers[0].Id),
CtxSession: cs,
})
} }
hlogger.Emit(models.InfoQuizOpen{
KeyOS: os,
KeyDevice: device,
KeyDeviceType: deviceType,
KeyBrowser: browser,
CtxQuiz: req.QuizId,
CtxQuizID: int64(quiz.Id),
CtxReferrer: referrer,
CtxIDInt: int64(answers[0].Id),
CtxSession: cs,
})
fmt.Println("SETTIIIIII", cnt <= req.Limit, result) fmt.Println("SETTIIIIII", cnt <= req.Limit, result)
if cnt <= req.Limit { if cnt <= req.Limit {
@ -298,7 +305,7 @@ func dao2dtoQuiz(quiz model.Quiz) ShavedQuiz {
DueTo: quiz.DueTo, DueTo: quiz.DueTo,
TimeOfPassing: quiz.TimeOfPassing, TimeOfPassing: quiz.TimeOfPassing,
Pausable: quiz.Pausable, Pausable: quiz.Pausable,
Status: quiz.Status, Status: quiz.Status,
} }
} }
@ -396,7 +403,7 @@ func (s *Service) PutAnswersOnePiece(c *fiber.Ctx) error {
_, err = s.dal.QuestionRepo.CreateQuestion(c.Context(), &model.Question{ _, err = s.dal.QuestionRepo.CreateQuestion(c.Context(), &model.Question{
QuizId: quiz.Id, QuizId: quiz.Id,
Title: questionText, Title: questionText,
Type: model.TypeText, Type: model.TypeText,
Session: cs, Session: cs,
}) })
if err != nil { if err != nil {