feat: kepub conversions

Working *.epub to *.kepub.epub file conversions when
using a Kobo reader. Updated docker file to include
`kepubify` to convert to kepub. If not available the
file is just sent without conversion.
This commit is contained in:
Evan Buss
2024-07-08 22:20:25 -04:00
parent 7e066fafee
commit 85c497f70c
8 changed files with 183 additions and 11 deletions

14
convert/convert.go Normal file
View File

@@ -0,0 +1,14 @@
package convert
const (
MOBI_MIME = "application/x-mobipocket-ebook"
EPUB_MIME = "application/epub+zip"
)
type Converter interface {
// Whether or not the converter is available
// Usually based on the availability of the underlying tool
Available() bool
// Convert the input file to the output file
Convert(input string, output string) error
}

29
convert/kepub.go Normal file
View File

@@ -0,0 +1,29 @@
package convert
import (
"os/exec"
"sync"
)
type KepubConverter struct {
mutex sync.Mutex
}
func (kc *KepubConverter) Available() bool {
path, err := exec.LookPath("kepubify")
if err != nil {
return false
}
return path != ""
}
func (kc *KepubConverter) Convert(input string, output string) error {
kc.mutex.Lock()
defer kc.mutex.Unlock()
cmd := exec.Command("kepubify", "-v", "-u", "-o", output, input)
if err := cmd.Run(); err != nil {
return err
}
return nil
}

25
convert/mobi.go Normal file
View File

@@ -0,0 +1,25 @@
package convert
import (
"os/exec"
"sync"
)
type MobiConverter struct {
mutex sync.Mutex
}
func (mc *MobiConverter) Available() bool {
path, err := exec.LookPath("kindlegen")
if err != nil {
return false
}
return path != ""
}
func (mc *MobiConverter) Convert(input string, output string) error {
mc.mutex.Lock()
defer mc.mutex.Unlock()
return nil
}