status.go 716 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package geolite
  2. import (
  3. "net/http"
  4. "os"
  5. "time"
  6. "github.com/0xJacky/Nginx-UI/internal/geolite"
  7. "github.com/gin-gonic/gin"
  8. "github.com/uozi-tech/cosy"
  9. )
  10. type StatusResp struct {
  11. Exists bool `json:"exists"`
  12. Path string `json:"path"`
  13. Size int64 `json:"size"`
  14. LastModified string `json:"last_modified"`
  15. }
  16. func GetStatus(c *gin.Context) {
  17. dbPath := geolite.GetDBPath()
  18. resp := StatusResp{
  19. Exists: geolite.DBExists(),
  20. Path: dbPath,
  21. }
  22. if resp.Exists {
  23. fileInfo, err := os.Stat(dbPath)
  24. if err != nil {
  25. cosy.ErrHandler(c, err)
  26. return
  27. }
  28. resp.Size = fileInfo.Size()
  29. resp.LastModified = fileInfo.ModTime().Format(time.RFC3339)
  30. }
  31. c.JSON(http.StatusOK, resp)
  32. }