mirror of
https://github.com/Direct-Dev-Ru/go-lcg.git
synced 2025-11-16 01:29:55 +00:00
add https server functionality - befor auth functionality implementation
This commit is contained in:
37
serve/api.go
37
serve/api.go
@@ -10,6 +10,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/direct-dev-ru/linux-command-gpt/config"
|
||||
"github.com/direct-dev-ru/linux-command-gpt/validation"
|
||||
)
|
||||
|
||||
// SaveResultRequest представляет запрос на сохранение результата
|
||||
@@ -62,6 +63,20 @@ func handleSaveResult(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
// Валидация длины полей
|
||||
if err := validation.ValidateUserMessage(req.Prompt); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if err := validation.ValidateCommand(req.Command); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if err := validation.ValidateExplanation(req.Explanation); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
// Создаем папку результатов если не существует
|
||||
if err := os.MkdirAll(config.AppConfig.ResultFolder, 0755); err != nil {
|
||||
apiJsonResponse(w, SaveResultResponse{
|
||||
@@ -124,6 +139,28 @@ func handleAddToHistory(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
// Валидация длины полей
|
||||
if err := validation.ValidateUserMessage(req.Prompt); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if err := validation.ValidateCommand(req.Command); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if err := validation.ValidateCommand(req.Response); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if err := validation.ValidateExplanation(req.Explanation); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if err := validation.ValidateSystemPrompt(req.System); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
// Проверяем, есть ли уже такой запрос в истории
|
||||
entries, err := Read(config.AppConfig.ResultHistory)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user