mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-11 18:02:14 +01:00
feat(pdfengines): preserve filenames in convert route
This commit is contained in:
@@ -23,10 +23,10 @@ func TestConvertRoute(t *testing.T) {
|
||||
engine gotenberg.PdfEngine
|
||||
expectOptions libreofficeapi.Options
|
||||
expectError bool
|
||||
expectOutpoutPaths []string
|
||||
expectHttpError bool
|
||||
expectHttpStatus int
|
||||
expectOutputPathsCount int
|
||||
expectOutputPaths []string
|
||||
}{
|
||||
{
|
||||
scenario: "missing at least one mandatory file",
|
||||
@@ -277,7 +277,7 @@ func TestConvertRoute(t *testing.T) {
|
||||
expectError: false,
|
||||
expectHttpError: false,
|
||||
expectOutputPathsCount: 1,
|
||||
expectOutpoutPaths: []string{"/document.docx.pdf"},
|
||||
expectOutputPaths: []string{"/document.docx.pdf"},
|
||||
},
|
||||
{
|
||||
scenario: "success (many files)",
|
||||
@@ -301,7 +301,7 @@ func TestConvertRoute(t *testing.T) {
|
||||
expectError: false,
|
||||
expectHttpError: false,
|
||||
expectOutputPathsCount: 3,
|
||||
expectOutpoutPaths: []string{"/document.docx.pdf", "/document2.docx.pdf", "/document2.doc.pdf"},
|
||||
expectOutputPaths: []string{"/document.docx.pdf", "/document2.docx.pdf", "/document2.doc.pdf"},
|
||||
},
|
||||
{
|
||||
scenario: "success with non-native PDF/A & PDF/UA (many files)",
|
||||
@@ -340,7 +340,7 @@ func TestConvertRoute(t *testing.T) {
|
||||
expectError: false,
|
||||
expectHttpError: false,
|
||||
expectOutputPathsCount: 2,
|
||||
expectOutpoutPaths: []string{"/document.docx.pdf", "/document2.docx.pdf"},
|
||||
expectOutputPaths: []string{"/document.docx.pdf", "/document2.docx.pdf"},
|
||||
},
|
||||
{
|
||||
scenario: "success with native PDF/A & PDF/UA (many files)",
|
||||
@@ -376,7 +376,7 @@ func TestConvertRoute(t *testing.T) {
|
||||
expectError: false,
|
||||
expectHttpError: false,
|
||||
expectOutputPathsCount: 2,
|
||||
expectOutpoutPaths: []string{"/document.docx.pdf", "/document2.docx.pdf"},
|
||||
expectOutputPaths: []string{"/document.docx.pdf", "/document2.docx.pdf"},
|
||||
},
|
||||
{
|
||||
scenario: "ErrMaximumQueueSizeExceeded (merge)",
|
||||
@@ -759,7 +759,7 @@ func TestConvertRoute(t *testing.T) {
|
||||
t.Errorf("expected %d output paths but got %d", tc.expectOutputPathsCount, len(tc.ctx.OutputPaths()))
|
||||
}
|
||||
|
||||
for _, path := range tc.expectOutpoutPaths {
|
||||
for _, path := range tc.expectOutputPaths {
|
||||
if !slices.Contains(tc.ctx.OutputPaths(), path) {
|
||||
t.Errorf("expected '%s' in output paths %v", path, tc.ctx.OutputPaths())
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
|
||||
@@ -152,11 +154,11 @@ func convertRoute(engine gotenberg.PdfEngine) api.Route {
|
||||
)
|
||||
}
|
||||
|
||||
// Alright, let's convert the PDFs.
|
||||
// Alright, let's convert the PDFs.s
|
||||
outputPaths := make([]string, len(inputPaths))
|
||||
|
||||
for i, inputPath := range inputPaths {
|
||||
outputPaths[i] = ctx.GeneratePath("", ".pdf")
|
||||
outputPaths[i] = ctx.GeneratePath(strings.TrimSuffix(filepath.Base(inputPath), filepath.Ext(inputPath)), ".pdf")
|
||||
|
||||
err = engine.Convert(ctx, ctx.Log(), pdfFormats, inputPath, outputPaths[i])
|
||||
if err != nil {
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"slices"
|
||||
"testing"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
@@ -273,6 +274,7 @@ func TestConvertHandler(t *testing.T) {
|
||||
expectHttpError bool
|
||||
expectHttpStatus int
|
||||
expectOutputPathsCount int
|
||||
expectOutputPaths []string
|
||||
}{
|
||||
{
|
||||
scenario: "missing at least one mandatory file",
|
||||
@@ -416,6 +418,7 @@ 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)",
|
||||
@@ -443,6 +446,7 @@ func TestConvertHandler(t *testing.T) {
|
||||
expectError: false,
|
||||
expectHttpError: false,
|
||||
expectOutputPathsCount: 2,
|
||||
expectOutputPaths: []string{"/file.pdf", "/file2.pdf"},
|
||||
},
|
||||
} {
|
||||
t.Run(tc.scenario, func(t *testing.T) {
|
||||
@@ -481,6 +485,12 @@ func TestConvertHandler(t *testing.T) {
|
||||
if tc.expectOutputPathsCount != len(tc.ctx.OutputPaths()) {
|
||||
t.Errorf("expected %d output paths but got %d", tc.expectOutputPathsCount, len(tc.ctx.OutputPaths()))
|
||||
}
|
||||
|
||||
for _, path := range tc.expectOutputPaths {
|
||||
if !slices.Contains(tc.ctx.OutputPaths(), path) {
|
||||
t.Errorf("expected '%s' in output paths %v", path, tc.ctx.OutputPaths())
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user