mirror of
https://github.com/usememos/memos.git
synced 2024-12-21 10:11:42 +03:00
chore: update db filesize access control (#493)
This commit is contained in:
parent
878e0eabc8
commit
477130aa85
@ -55,15 +55,12 @@ func aclMiddleware(s *Server, next echo.HandlerFunc) echo.HandlerFunc {
|
|||||||
return func(c echo.Context) error {
|
return func(c echo.Context) error {
|
||||||
ctx := c.Request().Context()
|
ctx := c.Request().Context()
|
||||||
path := c.Path()
|
path := c.Path()
|
||||||
|
|
||||||
// Skip auth.
|
// Skip auth.
|
||||||
if common.HasPrefixes(path, "/api/auth") {
|
if common.HasPrefixes(path, "/api/auth") {
|
||||||
return next(c)
|
return next(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
if common.HasPrefixes(path, "/api/ping", "/api/status", "/api/user/:id") && c.Request().Method == http.MethodGet {
|
|
||||||
return next(c)
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
{
|
||||||
// If there is openId in query string and related user is found, then skip auth.
|
// If there is openId in query string and related user is found, then skip auth.
|
||||||
openID := c.QueryParam("openId")
|
openID := c.QueryParam("openId")
|
||||||
@ -104,7 +101,7 @@ func aclMiddleware(s *Server, next echo.HandlerFunc) echo.HandlerFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if common.HasPrefixes(path, "/api/memo/all", "/api/memo/:memoId", "/api/memo/amount") && c.Request().Method == http.MethodGet {
|
if common.HasPrefixes(path, "/api/ping", "/api/status", "/api/user/:id", "/api/memo/all", "/api/memo/:memoId", "/api/memo/amount") && c.Request().Method == http.MethodGet {
|
||||||
return next(c)
|
return next(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,6 +42,7 @@ func (s *Server) registerSystemRoutes(g *echo.Group) {
|
|||||||
systemStatus := api.SystemStatus{
|
systemStatus := api.SystemStatus{
|
||||||
Host: hostUser,
|
Host: hostUser,
|
||||||
Profile: s.Profile,
|
Profile: s.Profile,
|
||||||
|
DBSize: 0,
|
||||||
AllowSignUp: false,
|
AllowSignUp: false,
|
||||||
AdditionalStyle: "",
|
AdditionalStyle: "",
|
||||||
AdditionalScript: "",
|
AdditionalScript: "",
|
||||||
@ -67,11 +68,22 @@ func (s *Server) registerSystemRoutes(g *echo.Group) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
userID, ok := c.Get(getUserIDContextKey()).(int)
|
||||||
|
if ok {
|
||||||
|
user, err := s.Store.FindUser(ctx, &api.UserFind{
|
||||||
|
ID: &userID,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find user").SetInternal(err)
|
||||||
|
}
|
||||||
|
if user != nil && user.Role == api.Host {
|
||||||
fi, err := os.Stat(s.Profile.DSN)
|
fi, err := os.Stat(s.Profile.DSN)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to read database fileinfo").SetInternal(err)
|
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to read database fileinfo").SetInternal(err)
|
||||||
}
|
}
|
||||||
systemStatus.DBSize = fi.Size()
|
systemStatus.DBSize = fi.Size()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
|
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
|
||||||
if err := json.NewEncoder(c.Response().Writer).Encode(composeResponse(systemStatus)); err != nil {
|
if err := json.NewEncoder(c.Response().Writer).Encode(composeResponse(systemStatus)); err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user