1
1
mirror of https://github.com/usememos/memos.git synced 2024-12-25 12:23:09 +03:00
memos/server/system.go

50 lines
1.3 KiB
Go
Raw Normal View History

2022-03-29 15:53:43 +03:00
package server
import (
"encoding/json"
"net/http"
2022-06-27 17:09:06 +03:00
"github.com/usememos/memos/api"
2022-03-29 15:53:43 +03:00
"github.com/labstack/echo/v4"
)
func (s *Server) registerSystemRoutes(g *echo.Group) {
g.GET("/ping", func(c echo.Context) error {
2022-06-22 14:16:31 +03:00
data := s.Profile
2022-03-29 15:53:43 +03:00
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
2022-06-22 14:16:31 +03:00
if err := json.NewEncoder(c.Response().Writer).Encode(composeResponse(data)); err != nil {
2022-03-29 15:53:43 +03:00
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to compose system profile").SetInternal(err)
}
return nil
})
g.GET("/status", func(c echo.Context) error {
ownerUserType := api.Owner
ownerUserFind := api.UserFind{
Role: &ownerUserType,
}
2022-05-16 02:37:23 +03:00
ownerUser, err := s.Store.FindUser(&ownerUserFind)
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find owner user").SetInternal(err)
}
if ownerUser != nil {
// data desensitize
ownerUser.OpenID = ""
}
2022-06-22 14:16:31 +03:00
systemStatus := api.SystemStatus{
2022-05-17 16:21:13 +03:00
Owner: ownerUser,
Profile: s.Profile,
}
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 15:53:43 +03:00
}