mirror of
https://github.com/truewhile/MeBox.git
synced 2026-09-29 19:36:36 +08:00
fix: allow login during sqlite write pressure
This commit is contained in:
@@ -19,7 +19,15 @@ func activeUserRequired(svc *service.Container) gin.HandlerFunc {
|
||||
return
|
||||
}
|
||||
u, err := svc.Repo.User.FindByID(c.Request.Context(), userID)
|
||||
if err != nil || u == nil {
|
||||
if err != nil {
|
||||
if service.IsTransientDatabaseLock(err) {
|
||||
c.Next()
|
||||
return
|
||||
}
|
||||
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"code": 40101, "message": "user not found"})
|
||||
return
|
||||
}
|
||||
if u == nil {
|
||||
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"code": 40101, "message": "user not found"})
|
||||
return
|
||||
}
|
||||
@@ -40,7 +48,19 @@ func activeEmbyUserRequired(svc *service.Container) gin.HandlerFunc {
|
||||
uid, _ := c.Get(middleware.CtxUserID)
|
||||
userID, _ := uid.(string)
|
||||
u, err := svc.Repo.User.FindByID(c.Request.Context(), userID)
|
||||
if userID == "" || err != nil || u == nil {
|
||||
if userID == "" {
|
||||
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"Code": 40101, "Message": "User not found"})
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
if service.IsTransientDatabaseLock(err) {
|
||||
c.Next()
|
||||
return
|
||||
}
|
||||
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"Code": 40101, "Message": "User not found"})
|
||||
return
|
||||
}
|
||||
if u == nil {
|
||||
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"Code": 40101, "Message": "User not found"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -116,6 +116,21 @@ func (h *PermissionHandler) GetMyPermissions(c *gin.Context) {
|
||||
|
||||
perms, err := h.svc.Permissions.Effective(c.Request.Context(), currentUserID)
|
||||
if err != nil {
|
||||
if service.IsTransientDatabaseLock(err) {
|
||||
role := middleware.GetUserRole(c)
|
||||
tier := middleware.GetUserTier(c)
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 0,
|
||||
"message": "ok",
|
||||
"data": gin.H{
|
||||
"permissions": service.FallbackPermissions(currentUserID, role),
|
||||
"role": role,
|
||||
"tier": tier,
|
||||
"is_super": role == "admin" || tier == "plus",
|
||||
},
|
||||
})
|
||||
return
|
||||
}
|
||||
h.log.Error("get my permissions failed", zap.Error(err))
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"code": 50001, "message": "internal error", "data": nil})
|
||||
return
|
||||
|
||||
@@ -47,6 +47,11 @@ func myPermissionsHandler(svc *service.Container) gin.HandlerFunc {
|
||||
uid, _ := c.Get(middleware.CtxUserID)
|
||||
row, err := svc.Permissions.Effective(c.Request.Context(), toString(uid))
|
||||
if err != nil {
|
||||
if service.IsTransientDatabaseLock(err) {
|
||||
role, _ := c.Get(middleware.CtxUserRole)
|
||||
c.JSON(http.StatusOK, service.FallbackPermissions(toString(uid), toString(role)))
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user