mirror of
https://github.com/pocket-id/pocket-id.git
synced 2025-12-13 16:53:01 +03:00
fix: ensure file descriptors are closed + other bugs (#413)
This commit is contained in:
committed by
GitHub
parent
980780e48b
commit
2f7646105e
@@ -54,7 +54,7 @@ func (s *UserService) GetUser(userID string) (model.User, error) {
|
||||
return user, err
|
||||
}
|
||||
|
||||
func (s *UserService) GetProfilePicture(userID string) (io.Reader, int64, error) {
|
||||
func (s *UserService) GetProfilePicture(userID string) (io.ReadCloser, int64, error) {
|
||||
// Validate the user ID to prevent directory traversal
|
||||
if err := uuid.Validate(userID); err != nil {
|
||||
return nil, 0, &common.InvalidUUIDError{}
|
||||
@@ -99,7 +99,7 @@ func (s *UserService) GetProfilePicture(userID string) (io.Reader, int64, error)
|
||||
}
|
||||
|
||||
// Save the default picture for future use (in a goroutine to avoid blocking)
|
||||
defaultPictureCopy := bytes.NewBuffer(defaultPicture.Bytes())
|
||||
defaultPictureBytes := defaultPicture.Bytes()
|
||||
go func() {
|
||||
// Ensure the directory exists
|
||||
err = os.MkdirAll(defaultProfilePicturesDir, os.ModePerm)
|
||||
@@ -107,12 +107,12 @@ func (s *UserService) GetProfilePicture(userID string) (io.Reader, int64, error)
|
||||
log.Printf("Failed to create directory for default profile picture: %v", err)
|
||||
return
|
||||
}
|
||||
if err := utils.SaveFileStream(defaultPictureCopy, defaultPicturePath); err != nil {
|
||||
if err := utils.SaveFileStream(bytes.NewReader(defaultPictureBytes), defaultPicturePath); err != nil {
|
||||
log.Printf("Failed to cache default profile picture for initials %s: %v", user.Initials(), err)
|
||||
}
|
||||
}()
|
||||
|
||||
return defaultPicture, int64(defaultPicture.Len()), nil
|
||||
return io.NopCloser(bytes.NewReader(defaultPictureBytes)), int64(defaultPicture.Len()), nil
|
||||
}
|
||||
|
||||
func (s *UserService) GetUserGroups(userID string) ([]model.UserGroup, error) {
|
||||
|
||||
Reference in New Issue
Block a user