Skip to content

Commit

Permalink
Add support for fb2converter
Browse files Browse the repository at this point in the history
  • Loading branch information
shemanaev committed Jan 27, 2024
1 parent 9f11096 commit d4f0b25
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion inpxer-example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ full_url = "http://localhost:8080"
#to = "epub"
## converter executable
#command = "fb2epub"
## converter arguments. {from} becomes source file path, {to} - output file path
## converter arguments. {from} becomes source file path, {to} - output file path, {to_dir} - output directory (for fb2converter)
#arguments = "{from} {to}"
9 changes: 8 additions & 1 deletion internal/server/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,16 @@ func (h *DownloadHandler) DownloadConverted(w http.ResponseWriter, r *http.Reque
}
}

outFilename := filepath.Join(os.TempDir(), book.LibId+"."+converter.To)
outDir := os.TempDir()
outFilename := filepath.Join(outDir, book.LibId+"."+converter.To)
if strings.Contains(converter.Arguments, "{to_dir}") {
baseFilename := filepath.Base(filename)
outFilename = filepath.Join(outDir, strings.TrimSuffix(baseFilename, filepath.Ext(baseFilename))+"."+converter.To)
}

args := strings.Replace(converter.Arguments, "{from}", filename, -1)
args = strings.Replace(args, "{to}", outFilename, -1)
args = strings.Replace(args, "{to_dir}", outDir, -1)
cmd := exec.Command(converter.Command, strings.Split(args, " ")...)

log.Printf("Waiting for converter to finish. %s %s", converter.Command, args)
Expand Down

0 comments on commit d4f0b25

Please sign in to comment.