2022-03-29 20:53:43 +08:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2022-05-15 10:57:54 +08:00
|
|
|
"memos/api"
|
2022-03-29 20:53:43 +08:00
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/labstack/echo/v4"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (s *Server) registerSystemRoutes(g *echo.Group) {
|
|
|
|
g.GET("/ping", func(c echo.Context) error {
|
|
|
|
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
|
|
|
|
if err := json.NewEncoder(c.Response().Writer).Encode(composeResponse(s.Profile)); err != nil {
|
|
|
|
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to compose system profile").SetInternal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
2022-05-15 10:57:54 +08:00
|
|
|
|
|
|
|
g.GET("/status", func(c echo.Context) error {
|
|
|
|
ownerUserType := api.Owner
|
|
|
|
ownerUserFind := api.UserFind{
|
|
|
|
Role: &ownerUserType,
|
|
|
|
}
|
2022-05-16 07:37:23 +08:00
|
|
|
ownerUser, err := s.Store.FindUser(&ownerUserFind)
|
2022-05-15 10:57:54 +08:00
|
|
|
if err != nil {
|
|
|
|
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find owner user").SetInternal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
systemStatus := api.SystemStatus{
|
2022-05-17 21:21:13 +08:00
|
|
|
Owner: ownerUser,
|
|
|
|
Profile: s.Profile,
|
2022-05-15 10:57:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
|
|
|
|
if err := json.NewEncoder(c.Response().Writer).Encode(composeResponse(systemStatus)); err != nil {
|
|
|
|
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to encode system status response").SetInternal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
2022-03-29 20:53:43 +08:00
|
|
|
}
|