fixing issue with merge endpoint: was not returning file

This commit is contained in:
Julien Neuhart
2018-12-10 18:42:23 +01:00
parent 8a652761a3
commit 7aeb072cc3

View File

@@ -25,22 +25,25 @@ func merge(c echo.Context) error {
return fmt.Errorf("getting result file name: %v", err) return fmt.Errorf("getting result file name: %v", err)
} }
filename := fmt.Sprintf("%s.pdf", baseFilename) filename := fmt.Sprintf("%s.pdf", baseFilename)
dest := fmt.Sprintf("%s/%s", r.dirPath, filename) fpath := fmt.Sprintf("%s/%s", r.dirPath, filename)
if r.webhookURL() == "" { if r.webhookURL() == "" {
// if no webhook URL given, run merge // if no webhook URL given, run merge
// and directly return the resulting PDF file // and directly return the resulting PDF file
// or and error. // or and error.
return printer.Merge(fpaths, dest) if err := printer.Merge(fpaths, fpath); err != nil {
return err
}
return c.Attachment(fpath, filename)
} }
// as a webhook URL has been given, we // as a webhook URL has been given, we
// run the following lines in a goroutine so that // run the following lines in a goroutine so that
// it doesn't block. // it doesn't block.
go func() { go func() {
if err := printer.Merge(fpaths, dest); err != nil { if err := printer.Merge(fpaths, fpath); err != nil {
c.Logger().Errorf("%v", err) c.Logger().Errorf("%v", err)
return return
} }
f, err := os.Open(dest) f, err := os.Open(fpath)
if err != nil { if err != nil {
c.Logger().Errorf("%v", err) c.Logger().Errorf("%v", err)
return return