mirror of
https://github.com/usememos/memos.git
synced 2024-12-19 00:51:30 +03:00
bdc9632b5b
* chore: rename user role to `host` * chore: related frontend changes * chore: fix migration file * chore: use tricky sql
50 lines
1.3 KiB
Go
50 lines
1.3 KiB
Go
package server
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
|
|
"github.com/usememos/memos/api"
|
|
|
|
"github.com/labstack/echo/v4"
|
|
)
|
|
|
|
func (s *Server) registerSystemRoutes(g *echo.Group) {
|
|
g.GET("/ping", func(c echo.Context) error {
|
|
data := s.Profile
|
|
|
|
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
|
|
if err := json.NewEncoder(c.Response().Writer).Encode(composeResponse(data)); err != nil {
|
|
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to compose system profile").SetInternal(err)
|
|
}
|
|
return nil
|
|
})
|
|
|
|
g.GET("/status", func(c echo.Context) error {
|
|
hostUserType := api.Host
|
|
hostUserFind := api.UserFind{
|
|
Role: &hostUserType,
|
|
}
|
|
hostUser, err := s.Store.FindUser(&hostUserFind)
|
|
if err != nil {
|
|
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find host user").SetInternal(err)
|
|
}
|
|
|
|
if hostUser != nil {
|
|
// data desensitize
|
|
hostUser.OpenID = ""
|
|
}
|
|
|
|
systemStatus := api.SystemStatus{
|
|
Host: hostUser,
|
|
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
|
|
})
|
|
}
|