mirror of
https://github.com/usememos/memos.git
synced 2024-12-21 02:01:55 +03:00
f1cca0f298
* feat: add user role field * chore: fix typo * feat: update signup api
43 lines
1.2 KiB
Go
43 lines
1.2 KiB
Go
package server
|
|
|
|
import (
|
|
"encoding/json"
|
|
"memos/api"
|
|
"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
|
|
})
|
|
|
|
g.GET("/status", func(c echo.Context) error {
|
|
ownerUserType := api.Owner
|
|
ownerUserFind := api.UserFind{
|
|
Role: &ownerUserType,
|
|
}
|
|
ownerUser, err := s.UserService.FindUser(&ownerUserFind)
|
|
if err != nil {
|
|
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find owner user").SetInternal(err)
|
|
}
|
|
|
|
systemStatus := api.SystemStatus{
|
|
Owner: ownerUser,
|
|
}
|
|
|
|
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
|
|
})
|
|
}
|