lab4: исправления по ревью

This commit is contained in:
Vladislav Kunetskiy
2026-10-21 23:25:11 +03:00
parent 3389c6c900
commit e9f0fde6f2
32 changed files with 451 additions and 131 deletions
+12 -4
View File
@@ -207,7 +207,11 @@ func (s *Service) Presign(ctx context.Context, request domain.PresignRequest) (d
return domain.PresignResult{}, fmt.Errorf("%w: content type %q", domain.ErrUnsupportedMedia, request.ContentType)
}
if request.SizeBytes < 1 || request.SizeBytes > s.config.MaxUploadBytes {
if request.SizeBytes < 1 {
return domain.PresignResult{}, fmt.Errorf("%w: size %d", domain.ErrValidation, request.SizeBytes)
}
if request.SizeBytes > s.config.MaxUploadBytes {
return domain.PresignResult{}, fmt.Errorf("%w: size %d", domain.ErrTooLarge, request.SizeBytes)
}
@@ -244,7 +248,7 @@ func (s *Service) Presign(ctx context.Context, request domain.PresignRequest) (d
return domain.PresignResult{}, err
}
url, expiresAt, err := s.store.PresignPut(ctx, stagingKey, s.config.PresignTTL)
url, expiresAt, err := s.store.PresignPut(ctx, stagingKey, request.SizeBytes, s.config.PresignTTL)
if err != nil {
s.cleanupPending(ctx, id, "")
@@ -346,8 +350,8 @@ func (s *Service) Complete(
}
if requestSHA != attachment.SHA256 {
s.cleanupPending(ctx, id, attachment.ObjectKey)
// The object is valid; only the completion request is inconsistent.
// Keep the pending row and staging object so a retry can succeed.
return domain.Attachment{}, fmt.Errorf("%w: completion checksum mismatch", domain.ErrConflict)
}
@@ -454,6 +458,10 @@ func ValidateFilename(name string) error {
return fmt.Errorf("%w: filename length is %d, want 1-255 code points", domain.ErrValidation, length)
}
if strings.TrimSpace(name) == "" {
return fmt.Errorf("%w: filename consists of whitespace only", domain.ErrValidation)
}
if strings.ContainsAny(name, "/\\\x00") {
return fmt.Errorf("%w: filename contains a path separator or NUL", domain.ErrValidation)
}