feat(pdfengines): apply multiple stamps and watermarks on every route

This commit is contained in:
Julien Neuhart
2026-08-14 16:36:40 +02:00
parent e9a67132ec
commit 3de6932279
8 changed files with 302 additions and 248 deletions

View File

@@ -494,6 +494,21 @@ func (form *FormData) Stamps(target *[]string) *FormData {
return form
}
// Watermarks binds the absolute paths of every file uploaded with the
// "watermark" field name, in submission order. Unlike [FormData.Watermark], it
// keeps all of them so a route can apply several watermarks in a single request.
func (form *FormData) Watermarks(target *[]string) *FormData {
if form.errors != nil {
return form
}
if paths, ok := form.filesByField[WatermarkFormField]; ok {
*target = paths
}
return form
}
// Strings binds every value submitted for key, in submission order. A field
// repeated in the multipart body (e.g. multiple "stampSource") contributes one
// entry per occurrence, which lets a route read parallel field arrays.

View File

@@ -1880,3 +1880,18 @@ func TestFormData_Stamps(t *testing.T) {
t.Errorf("expected nil when no stamp file was uploaded, got %+v", none)
}
}
func TestFormData_Watermarks(t *testing.T) {
form := &FormData{
filesByField: map[string][]string{
WatermarkFormField: {"/tmp/abc/a.png"},
},
}
var got []string
form.Watermarks(&got)
if want := []string{"/tmp/abc/a.png"}; !reflect.DeepEqual(got, want) {
t.Errorf("expected %+v, got %+v", want, got)
}
}