start create controllers and structs

This commit is contained in:
Pasha 2025-05-22 18:49:56 +03:00
parent 0c6e9a4b4c
commit 988df9d658

@ -36,6 +36,8 @@ type Service struct {
encrypt *utils.Encrypt
redirectURl string
aiClient *clients.AIClient
script scriptTemplate
}
type ServiceDeps struct {
@ -48,6 +50,12 @@ type ServiceDeps struct {
AiClient *clients.AIClient
}
type scriptTemplate struct {
prefix []byte
suffix []byte
mu sync.RWMutex
}
func New(deps ServiceDeps) *Service {
return &Service{
store: deps.Store,
@ -66,6 +74,9 @@ func (s *Service) Register(app *fiber.App) *fiber.App {
app.Post("/answer", s.PutAnswersOnePiece)
app.Post("/settings", s.GetQuizData)
app.Get("/logo", s.MiniPart)
app.Put("/pub.js", s.UploadScriptTemplate)
app.Get("/pub.js", s.GetScriptTemplate)
return app
}
@ -563,3 +574,25 @@ func (s *Service) MiniPart(ctx *fiber.Ctx) error {
return ctx.Redirect(s.redirectURl, fiber.StatusFound)
}
func (s *Service) UploadScriptTemplate(ctx *fiber.Ctx) error {
body := ctx.Body()
const marker = "THINKING"
pos := strings.Index(string(body), marker)
if pos == -1 {
return ctx.Status(fiber.StatusBadRequest).SendString("marker not found")
}
s.script.mu.Lock()
defer s.script.mu.Unlock()
s.script.prefix = body[:pos]
s.script.suffix = body[pos+len(marker):]
return ctx.SendStatus(fiber.StatusNoContent)
}
func (s *Service) GetScriptTemplate(ctx *fiber.Ctx) error {
return nil
}