chore: update db connection params (#1960)

This commit is contained in:
boojack 2023-07-15 10:26:19 +08:00 committed by GitHub
parent 6b17a27a13
commit 40a30d46af
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 4 deletions

View file

@ -113,12 +113,13 @@ func JWTMiddleware(server *APIV1Service, next echo.HandlerFunc, secret string) e
})
if !accessToken.Valid {
auth.RemoveTokensAndCookies(c)
return echo.NewHTTPError(http.StatusUnauthorized, "Invalid access token.")
}
if !audienceContains(claims.Audience, auth.AccessTokenAudienceName) {
return echo.NewHTTPError(http.StatusUnauthorized, fmt.Sprintf("Invalid access token, audience mismatch, got %q, expected %q.", claims.Audience, auth.AccessTokenAudienceName))
}
generateToken := time.Until(claims.ExpiresAt.Time) < auth.RefreshThresholdDuration
if err != nil {
var ve *jwt.ValidationError
@ -129,6 +130,7 @@ func JWTMiddleware(server *APIV1Service, next echo.HandlerFunc, secret string) e
generateToken = true
}
} else {
auth.RemoveTokensAndCookies(c)
return echo.NewHTTPError(http.StatusUnauthorized, errors.Wrap(err, "Invalid or expired access token"))
}
}

View file

@ -77,6 +77,7 @@ func (s *APIV1Service) registerSystemRoutes(g *echo.Group) {
// data desensitize
systemStatus.Host.OpenID = ""
systemStatus.Host.Email = ""
systemStatus.Host.AvatarURL = ""
}
systemSettingList, err := s.Store.ListSystemSettings(ctx, &store.FindSystemSetting{})

View file

@ -75,7 +75,7 @@ func NewServer(ctx context.Context, profile *profile.Profile, store *store.Store
serverID, err := s.getSystemServerID(ctx)
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to retrieve system server ID: %w", err)
}
s.ID = serverID
@ -85,7 +85,7 @@ func NewServer(ctx context.Context, profile *profile.Profile, store *store.Store
if profile.Mode == "prod" {
secret, err = s.getSystemSecretSessionName(ctx)
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to retrieve system secret session name: %w", err)
}
}
s.Secret = secret

View file

@ -43,7 +43,7 @@ func (db *DB) Open(ctx context.Context) (err error) {
}
// Connect to the database without foreign_key.
sqliteDB, err := sql.Open("sqlite", db.profile.DSN+"?cache=shared&_foreign_keys=0&_journal_mode=WAL")
sqliteDB, err := sql.Open("sqlite", db.profile.DSN+"?cache=private&_foreign_keys=0&_busy_timeout=10000&_journal_mode=WAL")
if err != nil {
return fmt.Errorf("failed to open db with dsn: %s, err: %w", db.profile.DSN, err)
}