|
|
|
@@ -136,14 +136,15 @@ func (m *uploadsOnDisk) convertExcelTo(format string) (e error) { |
|
|
|
} |
|
|
|
defer os.RemoveAll(dir) |
|
|
|
|
|
|
|
libreOfficeMutex.Lock() //ensure only one libreoffice is running |
|
|
|
|
|
|
|
// Create a new context and add a timeout to it |
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) |
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
|
|
|
defer cancel() // The cancel should be deferred so resources are cleaned up |
|
|
|
|
|
|
|
// Create the command with our context |
|
|
|
cmd := exec.CommandContext(ctx, "libreoffice", "--convert-to", format, "--outdir", dir, m.filePath()) |
|
|
|
|
|
|
|
libreOfficeMutex.Lock() //ensure only one libreoffice is running |
|
|
|
// This time we can simply use Output() to get the result. |
|
|
|
out, e := cmd.Output() |
|
|
|
libreOfficeMutex.Unlock() |
|
|
|
@@ -204,6 +205,7 @@ func (m *uploadsOnDisk) convertExcelTo(format string) (e error) { |
|
|
|
|
|
|
|
// first page to thumbnail |
|
|
|
// all page to single jpg |
|
|
|
var convertPDFMutex sync.Mutex // make sure we only have one convert running at a time |
|
|
|
func (m *uploadsOnDisk) convertPDFToJpg() (e error) { |
|
|
|
|
|
|
|
if fileExists(m.jpgPath()) { |
|
|
|
@@ -219,6 +221,7 @@ func (m *uploadsOnDisk) convertPDFToJpg() (e error) { |
|
|
|
} |
|
|
|
defer os.RemoveAll(dir) |
|
|
|
|
|
|
|
convertPDFMutex.Lock() |
|
|
|
// convert -density 3000 abc.pdf path/tmp/result.png |
|
|
|
// could be path/tmp/result-0, result-1, result-2, ... png |
|
|
|
target := dir + string(os.PathSeparator) + "result.jpg" //.jpg suffix is important |
|
|
|
@@ -226,6 +229,8 @@ func (m *uploadsOnDisk) convertPDFToJpg() (e error) { |
|
|
|
strCmd := cmd.String() |
|
|
|
log.Debug("command is ", strCmd) |
|
|
|
out, e := cmd.Output() |
|
|
|
convertPDFMutex.Unlock() |
|
|
|
|
|
|
|
if e != nil { |
|
|
|
log.Error("cannot create png file for PDF", m.Upload, e) |
|
|
|
_, e = copyFile(config.UploadsDir.JpgDefault, m.jpgPath()) |