From 1498473495d7aacfc45f0bd212d76c470ad67934 Mon Sep 17 00:00:00 2001 From: Julien Neuhart Date: Tue, 2 Jun 2026 19:31:25 +0200 Subject: [PATCH] feat(api): add FileCount accessor to request Context --- pkg/modules/api/context.go | 5 +++++ pkg/modules/api/context_test.go | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/pkg/modules/api/context.go b/pkg/modules/api/context.go index 2d93da14..8c9f840d 100644 --- a/pkg/modules/api/context.go +++ b/pkg/modules/api/context.go @@ -536,6 +536,11 @@ func (ctx *Context) FormData() *FormData { } } +// FileCount returns the number of files received in the request. +func (ctx *Context) FileCount() int { + return len(ctx.files) +} + // OriginalFilename returns the original filename associated with a disk path. // If no mapping exists, it falls back to [filepath.Base]. func (ctx *Context) OriginalFilename(diskPath string) string { diff --git a/pkg/modules/api/context_test.go b/pkg/modules/api/context_test.go index 8a13ab6e..7f4bcc6e 100644 --- a/pkg/modules/api/context_test.go +++ b/pkg/modules/api/context_test.go @@ -206,3 +206,19 @@ func TestSanitizeFilename(t *testing.T) { }) } } + +func TestContext_FileCount(t *testing.T) { + ctx := &Context{} + if got := ctx.FileCount(); got != 0 { + t.Errorf("expected 0 files, got %d", got) + } + + ctx.files = map[string]string{ + "index.html": "/work/index.html", + "header.html": "/work/header.html", + "styles.css": "/work/styles.css", + } + if got := ctx.FileCount(); got != 3 { + t.Errorf("expected 3 files, got %d", got) + } +}