record.go 643 B

12345678910111213141516171819202122232425262728293031
  1. package openai
  2. import (
  3. "net/http"
  4. "github.com/0xJacky/Nginx-UI/internal/helper"
  5. "github.com/0xJacky/Nginx-UI/internal/nginx"
  6. "github.com/0xJacky/Nginx-UI/query"
  7. "github.com/gin-gonic/gin"
  8. "github.com/uozi-tech/cosy"
  9. )
  10. func GetChatGPTRecord(c *gin.Context) {
  11. absPath := c.Query("path")
  12. if !helper.IsUnderDirectory(absPath, nginx.GetConfPath()) {
  13. c.JSON(http.StatusForbidden, gin.H{
  14. "message": "path is not under the nginx conf path",
  15. })
  16. return
  17. }
  18. g := query.ChatGPTLog
  19. chatgpt, err := g.Where(g.Name.Eq(absPath)).FirstOrCreate()
  20. if err != nil {
  21. cosy.ErrHandler(c, err)
  22. return
  23. }
  24. c.JSON(http.StatusOK, chatgpt)
  25. }