Skip to content

Commit f237b83

Browse files
mxschmittclaude
andcommitted
refactor: use slices.Contains for MIME type validation
Replace verbose chain of != comparisons with slices.Contains for cleaner, more maintainable code. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 9b94909 commit f237b83

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

file-service/main.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"os"
1212
"os/signal"
1313
"path/filepath"
14+
"slices"
1415
"syscall"
1516
"time"
1617

@@ -35,6 +36,13 @@ type server struct {
3536

3637
const BUCKET_NAME = "file-uploads"
3738

39+
var allowedMimeTypes = []string{
40+
"application/pdf",
41+
"image/png",
42+
"video/webm",
43+
"application/zip",
44+
}
45+
3846
func newServer() (*server, error) {
3947
err := sentry.Init(sentry.ClientOptions{
4048
Dsn: os.Getenv("FILE_SERVICE_SENTRY_DSN"),
@@ -127,7 +135,7 @@ func (s *server) processUploadedFile(ctx context.Context, fh *multipart.FileHead
127135
if err != nil {
128136
return publicFile{}, fmt.Errorf("could not detect mime-type: %w", err)
129137
}
130-
if mimeType.MIME.Value != "application/pdf" && mimeType.MIME.Value != "image/png" && mimeType.MIME.Value != "video/webm" && mimeType.MIME.Value != "application/zip" {
138+
if !slices.Contains(allowedMimeTypes, mimeType.MIME.Value) {
131139
return publicFile{}, fmt.Errorf("not allowed mime-type (%s): %s", mimeType.MIME.Value, fh.Filename)
132140
}
133141

0 commit comments

Comments
 (0)