fix(pdfengines): only preserve filenames in zip archive

This commit is contained in:
Julien Neuhart
2024-02-18 18:27:34 +01:00
parent 376a7db545
commit 25ce0b9aee
2 changed files with 6 additions and 2 deletions

View File

@@ -158,7 +158,12 @@ func convertRoute(engine gotenberg.PdfEngine) api.Route {
outputPaths := make([]string, len(inputPaths))
for i, inputPath := range inputPaths {
outputPaths[i] = ctx.GeneratePath(strings.TrimSuffix(filepath.Base(inputPath), filepath.Ext(inputPath)), ".pdf")
if len(outputPaths) > 1 {
// If .zip archive, keep the original filenames.
outputPaths[i] = ctx.GeneratePath(strings.TrimSuffix(filepath.Base(inputPath), filepath.Ext(inputPath)), ".pdf")
} else {
outputPaths[i] = ctx.GeneratePath("", ".pdf")
}
err = engine.Convert(ctx, ctx.Log(), pdfFormats, inputPath, outputPaths[i])
if err != nil {

View File

@@ -418,7 +418,6 @@ func TestConvertHandler(t *testing.T) {
expectError: false,
expectHttpError: false,
expectOutputPathsCount: 1,
expectOutputPaths: []string{"/file.pdf"},
},
{
scenario: "success with PDF/A & PDF/UA form fields (many files)",