add events for trash log and add todo for event InfoContactForm
This commit is contained in:
parent
248a980867
commit
97403e763c
2
go.mod
2
go.mod
@ -10,7 +10,7 @@ require (
|
||||
github.com/skeris/appInit v1.0.2
|
||||
github.com/themakers/hlog v0.0.0-20191205140925-235e0e4baddf
|
||||
go.uber.org/zap v1.27.0
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240601161453-70b7251bc7ee
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240601180932-af93405efbcf
|
||||
penahub.gitlab.yandexcloud.net/external/trashlog.git v0.1.2-0.20240523172059-9bbe8a9faa31
|
||||
)
|
||||
|
||||
|
6
go.sum
6
go.sum
@ -272,9 +272,7 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh
|
||||
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
|
||||
penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240527160654-bd1c2126bc6c h1:jxnyIeC2CNDNmfdFx2qnLS4Qd0v5ocYrY9X+OL9qsvc=
|
||||
penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240527160654-bd1c2126bc6c/go.mod h1:lTmpjry+8evVkXWbEC+WMOELcFkRD1lFMc7J09mOndM=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240601123735-e90b104b54f0 h1:ztVuVJPh8gh+kAN4my9qONM/iCNa1SyOO/H+y6yOVNI=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240601123735-e90b104b54f0/go.mod h1:G1ZAWaQq6WW1wG9Shy57K4ZIezuhaBckQgsqQ+lhe94=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240601161453-70b7251bc7ee h1:LpTVCBZglGRQuhVADzJmQ2fdqD2uJjm9M2OxCHu/ZGQ=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240601161453-70b7251bc7ee/go.mod h1:n66zm88Dh12+idyfqh0vU5nd9BZYxM6Pv0XYnmy0398=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240601180932-af93405efbcf h1:BnzAkKXo6CksQTqpVzsCTSMdWNwMpkBKb8eS/DDDHBI=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240601180932-af93405efbcf/go.mod h1:n66zm88Dh12+idyfqh0vU5nd9BZYxM6Pv0XYnmy0398=
|
||||
penahub.gitlab.yandexcloud.net/external/trashlog.git v0.1.2-0.20240523172059-9bbe8a9faa31 h1:WlRVJnzU0sti+qBq/JTCgFPU0RoxIqGHu7hzDirxE2k=
|
||||
penahub.gitlab.yandexcloud.net/external/trashlog.git v0.1.2-0.20240523172059-9bbe8a9faa31/go.mod h1:3ml0dAGT8U8RhpevKBfRgG6yKZum8EI2uJxAb2WCIy4=
|
||||
|
@ -11,10 +11,10 @@ type AllFields struct {
|
||||
KeyBrowser string
|
||||
CtxQuiz string
|
||||
CtxReferrer string
|
||||
CtxID int64
|
||||
CtxID uint64
|
||||
CtxSession string
|
||||
CtxQuizID int64
|
||||
CtxQuestionID string
|
||||
CtxQuizID uint64
|
||||
CtxQuestionID uint64
|
||||
}
|
||||
|
||||
type InfoQuizOpen struct { // при получении настроек квиза
|
||||
@ -24,9 +24,9 @@ type InfoQuizOpen struct { // при получении настроек кви
|
||||
KeyPath string
|
||||
KeyOS, KeyDevice, KeyDeviceType, KeyBrowser string // то самое, что получается из заголовков и складывается в модель ответа. на самом деле, ему место тут
|
||||
CtxQuiz string // айдишник квиза, который qid
|
||||
CtxQuizID int64 // айдишник квиза
|
||||
CtxQuizID uint64 // айдишник квиза
|
||||
CtxReferrer string // тоже из заголовков
|
||||
CtxID int64 // айдишник ответа
|
||||
CtxID uint64 // айдишник ответа
|
||||
CtxSession string // сессия
|
||||
}
|
||||
|
||||
@ -37,10 +37,10 @@ type InfoAnswer struct { // при любом ответе на вопрос
|
||||
KeyPath string
|
||||
KeyOS, KeyDevice, KeyDeviceType, KeyBrowser string // то самое, что получается из заголовков и складывается в модель ответа. на самом деле, ему место тут
|
||||
CtxQuiz string // айдишник квиза, который qid
|
||||
CtxQuizID int64 // айдишник квиза
|
||||
CtxQuizID uint64 // айдишник квиза
|
||||
CtxReferrer string // тоже из заголовков
|
||||
CtxQuestionID string // айдишник вопроса, на который отвечено
|
||||
CtxID int64 // айдишник ответа
|
||||
CtxQuestionID uint64 // айдишник вопроса, на который отвечено
|
||||
CtxID uint64 // айдишник ответа
|
||||
CtxSession string // сессия
|
||||
}
|
||||
|
||||
@ -51,13 +51,14 @@ type InfoResult struct { // если ответ на вопрос с типом
|
||||
KeyPath string
|
||||
KeyOS, KeyDevice, KeyDeviceType, KeyBrowser string // то самое, что получается из заголовков и складывается в модель ответа. на самом деле, ему место тут
|
||||
CtxQuiz string // айдишник квиза, который qid
|
||||
CtxQuizID int64 // айдишник квиза
|
||||
CtxQuizID uint64 // айдишник квиза
|
||||
CtxReferrer string // тоже из заголовков
|
||||
CtxQuestionID string // айдишник вопроса, на который отвечено
|
||||
CtxID int64 // айдишник ответа
|
||||
CtxQuestionID uint64 // айдишник вопроса, на который отвечено
|
||||
CtxID uint64 // айдишник ответа
|
||||
CtxSession string // сессия
|
||||
}
|
||||
|
||||
// todo понять для чего это событие вроде как контакты приходят в ответахс с result = true там парситься контент с контактной информацией
|
||||
type InfoContactForm struct { // если ответ на вопрос с типом result, без result == true (возможно перепутал с предыдущим. в этом ответе приходят контактные данные респондента)
|
||||
CtxUserIP string
|
||||
CtxUserPort string
|
||||
@ -65,9 +66,9 @@ type InfoContactForm struct { // если ответ на вопрос с тип
|
||||
KeyPath string
|
||||
KeyOS, KeyDevice, KeyDeviceType, KeyBrowser string // то самое, что получается из заголовков и складывается в модель ответа. на самом деле, ему место тут
|
||||
CtxQuiz string // айдишник квиза, который qid
|
||||
CtxQuizID int64 // айдишник квиза
|
||||
CtxQuizID uint64 // айдишник квиза
|
||||
CtxReferrer string // тоже из заголовков
|
||||
CtxQuestionID string // айдишник вопроса, на который отвечено
|
||||
CtxID int64 // айдишник ответа
|
||||
CtxQuestionID uint64 // айдишник вопроса, на который отвечено
|
||||
CtxID uint64 // айдишник ответа
|
||||
CtxSession string // сессия
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/answerer.git/dal"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/answerer.git/models"
|
||||
quizdal "penahub.gitlab.yandexcloud.net/backend/quiz/common.git/dal"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/middleware"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
|
||||
@ -87,6 +88,7 @@ type ShavedQuestion struct {
|
||||
|
||||
// GetQuizData handler for obtaining data for quiz front rendering
|
||||
func (s *Service) GetQuizData(c *fiber.Ctx) error {
|
||||
hlogger := middleware.GetLogger(c)
|
||||
var req GetQuizDataReq
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
return c.Status(fiber.StatusBadRequest).SendString("Invalid request data")
|
||||
@ -193,6 +195,8 @@ func (s *Service) GetQuizData(c *fiber.Ctx) error {
|
||||
os := c.Get("OS")
|
||||
browser := c.Get("Browser")
|
||||
ip := c.IP()
|
||||
device := c.Get("Device")
|
||||
referrer := c.Get("Referer")
|
||||
fp := ""
|
||||
if cfp := c.Cookies(fingerprintCookie); cfp != "" {
|
||||
fp = cfp
|
||||
@ -202,20 +206,38 @@ func (s *Service) GetQuizData(c *fiber.Ctx) error {
|
||||
return c.Status(fiber.StatusUnauthorized).SendString("no session in cookie")
|
||||
}
|
||||
|
||||
if _, err := s.dal.AnswerRepo.CreateAnswers(c.Context(), []model.Answer{{
|
||||
answers, errs := s.dal.AnswerRepo.CreateAnswers(c.Context(), []model.Answer{{
|
||||
Content: "start",
|
||||
QuestionId: questions[0].Id,
|
||||
QuizId: quiz.Id,
|
||||
Start: true,
|
||||
DeviceType: deviceType,
|
||||
Device: device,
|
||||
Browser: browser,
|
||||
IP: ip,
|
||||
OS: os,
|
||||
Utm: utmData,
|
||||
}}, cs, fp, quiz.Id); len(err) != 0 {
|
||||
return c.Status(fiber.StatusInternalServerError).SendString(err[0].Error())
|
||||
}}, cs, fp, quiz.Id)
|
||||
if len(errs) != 0 {
|
||||
return c.Status(fiber.StatusInternalServerError).SendString(errs[0].Error())
|
||||
}
|
||||
|
||||
hlogger.Emit(models.InfoQuizOpen{
|
||||
CtxUserIP: c.IP(),
|
||||
CtxUserPort: c.Port(),
|
||||
KeyDomain: strings.Join(c.Subdomains(), "/"),
|
||||
KeyPath: c.Path(),
|
||||
KeyOS: os,
|
||||
KeyDevice: device,
|
||||
KeyDeviceType: deviceType,
|
||||
KeyBrowser: browser,
|
||||
CtxQuiz: req.QuizId,
|
||||
CtxQuizID: quiz.Id,
|
||||
CtxReferrer: referrer,
|
||||
CtxID: answers[0].Id,
|
||||
CtxSession: cs,
|
||||
})
|
||||
|
||||
if cnt <= req.Limit {
|
||||
return c.Status(fiber.StatusOK).JSON(result)
|
||||
} else {
|
||||
@ -269,6 +291,8 @@ func (s *Service) PutAnswersOnePiece(c *fiber.Ctx) error {
|
||||
return c.Status(fiber.StatusUnauthorized).SendString("no session in cookie")
|
||||
}
|
||||
|
||||
hlogger := middleware.GetLogger(c)
|
||||
|
||||
form, err := c.MultipartForm()
|
||||
if err != nil || form == nil || form.File == nil {
|
||||
return c.Status(fiber.StatusBadRequest).SendString("expecting multipart form file")
|
||||
@ -288,6 +312,8 @@ func (s *Service) PutAnswersOnePiece(c *fiber.Ctx) error {
|
||||
os := c.Get("OS")
|
||||
browser := c.Get("Browser")
|
||||
ip := c.IP()
|
||||
device := c.Get("Device")
|
||||
referrer := c.Get("Referer")
|
||||
|
||||
if err := json.Unmarshal([]byte(answersStr[0]), &answersRaw); err != nil {
|
||||
return c.Status(fiber.StatusBadRequest).SendString("not valid answers string")
|
||||
@ -316,6 +342,7 @@ func (s *Service) PutAnswersOnePiece(c *fiber.Ctx) error {
|
||||
ans.OS = os
|
||||
ans.Browser = browser
|
||||
ans.IP = ip
|
||||
ans.Device = device
|
||||
if strings.HasPrefix(ans.Content, filePrefix) {
|
||||
filekey := strings.TrimPrefix(ans.Content, filePrefix)
|
||||
filenameparts := strings.Split(filekey, ".")
|
||||
@ -379,10 +406,49 @@ func (s *Service) PutAnswersOnePiece(c *fiber.Ctx) error {
|
||||
|
||||
return c.Status(fiber.StatusInternalServerError).SendString("some errors are casualted: " + fmt.Sprint(ers))
|
||||
}
|
||||
var questionIDs []uint64
|
||||
for _, ans := range stored {
|
||||
questionIDs = append(questionIDs, ans.QuestionId)
|
||||
if ans.Result {
|
||||
hlogger.Emit(models.InfoResult{
|
||||
CtxUserIP: c.IP(),
|
||||
CtxUserPort: c.Port(),
|
||||
KeyDomain: strings.Join(c.Subdomains(), "/"),
|
||||
KeyPath: c.Path(),
|
||||
KeyOS: os,
|
||||
KeyDevice: device,
|
||||
KeyDeviceType: deviceType,
|
||||
KeyBrowser: browser,
|
||||
CtxQuiz: quizID[0],
|
||||
CtxQuizID: quiz.Id,
|
||||
CtxReferrer: referrer,
|
||||
CtxQuestionID: ans.QuestionId,
|
||||
CtxID: ans.Id,
|
||||
CtxSession: cs,
|
||||
})
|
||||
continue
|
||||
}
|
||||
hlogger.Emit(models.InfoAnswer{
|
||||
CtxUserIP: c.IP(),
|
||||
CtxUserPort: c.Port(),
|
||||
KeyDomain: strings.Join(c.Subdomains(), "/"),
|
||||
KeyPath: c.Path(),
|
||||
KeyOS: os,
|
||||
KeyDevice: device,
|
||||
KeyDeviceType: deviceType,
|
||||
KeyBrowser: browser,
|
||||
CtxQuiz: quizID[0],
|
||||
CtxQuizID: quiz.Id,
|
||||
CtxReferrer: referrer,
|
||||
CtxQuestionID: ans.QuestionId,
|
||||
CtxID: ans.Id,
|
||||
CtxSession: cs,
|
||||
})
|
||||
}
|
||||
|
||||
response := PutAnswersResponse{
|
||||
FileIDMap: fileIDMap,
|
||||
Stored: stored,
|
||||
Stored: questionIDs,
|
||||
}
|
||||
|
||||
return c.Status(fiber.StatusOK).JSON(response)
|
||||
|
Loading…
Reference in New Issue
Block a user