mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-08 08:32:16 +01:00
fix(pdfcpu): correct sorting for the output paths of the split method
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
@@ -128,11 +129,25 @@ func (engine *PdfCpu) Split(ctx context.Context, logger *zap.Logger, mode gotenb
|
||||
return nil, fmt.Errorf("split PDFs with pdfcpu: %w", err)
|
||||
}
|
||||
|
||||
outputPaths, err := gotenberg.WalkDir(outputDirPath, ".pdf")
|
||||
var outputPaths []string
|
||||
err = filepath.Walk(outputDirPath, func(path string, info os.FileInfo, pathErr error) error {
|
||||
if pathErr != nil {
|
||||
return pathErr
|
||||
}
|
||||
if info.IsDir() {
|
||||
return nil
|
||||
}
|
||||
if strings.EqualFold(filepath.Ext(info.Name()), ".pdf") {
|
||||
outputPaths = append(outputPaths, path)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("walk directory to find resulting PDFs from split with pdfcpu: %w", err)
|
||||
}
|
||||
|
||||
sort.Sort(gotenberg.AlphanumericSort(outputPaths))
|
||||
|
||||
return outputPaths, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -230,15 +230,15 @@ func TestPdfCpu_Split(t *testing.T) {
|
||||
scenario: "success (intervals)",
|
||||
ctx: context.TODO(),
|
||||
mode: gotenberg.SplitMode{Mode: gotenberg.SplitModeIntervals, Span: "1"},
|
||||
inputPath: "/tests/test/testdata/pdfengines/sample1.pdf",
|
||||
inputPath: "/tests/test/testdata/pdfengines/sample4.pdf",
|
||||
expectError: false,
|
||||
expectOutputPathsCount: 3,
|
||||
expectOutputPathsCount: 20,
|
||||
},
|
||||
{
|
||||
scenario: "success (pages)",
|
||||
ctx: context.TODO(),
|
||||
mode: gotenberg.SplitMode{Mode: gotenberg.SplitModePages, Span: "1"},
|
||||
inputPath: "/tests/test/testdata/pdfengines/sample1.pdf",
|
||||
inputPath: "/tests/test/testdata/pdfengines/sample4.pdf",
|
||||
expectError: false,
|
||||
expectOutputPathsCount: 1,
|
||||
},
|
||||
@@ -246,7 +246,7 @@ func TestPdfCpu_Split(t *testing.T) {
|
||||
scenario: "success (pages & unify)",
|
||||
ctx: context.TODO(),
|
||||
mode: gotenberg.SplitMode{Mode: gotenberg.SplitModePages, Span: "1-2", Unify: true},
|
||||
inputPath: "/tests/test/testdata/pdfengines/sample1.pdf",
|
||||
inputPath: "/tests/test/testdata/pdfengines/sample4.pdf",
|
||||
expectError: false,
|
||||
expectOutputPathsCount: 1,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user