mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-08 00:22:14 +01:00
feat(api): add FileCount accessor to request Context
This commit is contained in:
@@ -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.
|
// OriginalFilename returns the original filename associated with a disk path.
|
||||||
// If no mapping exists, it falls back to [filepath.Base].
|
// If no mapping exists, it falls back to [filepath.Base].
|
||||||
func (ctx *Context) OriginalFilename(diskPath string) string {
|
func (ctx *Context) OriginalFilename(diskPath string) string {
|
||||||
|
|||||||
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user