forked from thecodingmachine/gotenberg-go-client
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add flatten route * chore: update client compatibility table --------- Co-authored-by: Alexander Pikeev <[email protected]>
- Loading branch information
Showing
9 changed files
with
97 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package gotenberg | ||
|
||
import "github.com/starwalkn/gotenberg-go-client/v8/document" | ||
|
||
type FlattenRequest struct { | ||
pdfs []document.Document | ||
|
||
*baseRequest | ||
} | ||
|
||
func NewFlattenRequest(pdfs ...document.Document) *FlattenRequest { | ||
return &FlattenRequest{ | ||
pdfs: pdfs, | ||
baseRequest: newBaseRequest(), | ||
} | ||
} | ||
|
||
func (req *FlattenRequest) endpoint() string { | ||
return "/forms/pdfengines/flatten" | ||
} | ||
|
||
func (req *FlattenRequest) formDocuments() map[string]document.Document { | ||
files := make(map[string]document.Document) | ||
|
||
for _, pdf := range req.pdfs { | ||
files[pdf.Filename()] = pdf | ||
} | ||
|
||
return files | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package gotenberg | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/starwalkn/gotenberg-go-client/v8/document" | ||
"github.com/starwalkn/gotenberg-go-client/v8/test" | ||
) | ||
|
||
func TestFlatten(t *testing.T) { | ||
c, err := NewClient("http://localhost:3000", http.DefaultClient) | ||
require.NoError(t, err) | ||
|
||
doc, err := document.FromPath("gotenberg1.pdf", test.PDFTestFilePath(t, "gotenberg.pdf")) | ||
require.NoError(t, err) | ||
|
||
r := NewFlattenRequest(doc) | ||
r.Trace("testFlatten") | ||
r.UseBasicAuth("foo", "bar") | ||
|
||
dirPath := t.TempDir() | ||
dest := fmt.Sprintf("%s/foo.pdf", dirPath) | ||
|
||
err = c.Store(context.Background(), r, dest) | ||
require.NoError(t, err) | ||
assert.FileExists(t, dest) | ||
|
||
isPDF, err := test.IsPDF(dest) | ||
require.NoError(t, err) | ||
assert.True(t, isPDF) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters