forked from Ivasoft/opds-proxy
This change adds a child logger with request information to the http request context. Also improved the log format for clarity. - Unescaped the query string - Use JSON log format when not in dev mode. - Added request ip to the request child logger. - The child logger is passed to the converter so we can associate any errors with a specific request / file. - Add book file name as a logger attribute - Add user agent header as a logger attribute - Log the "X-Forwarded-For" header, falling back to RemoteAddr
38 lines
701 B
Go
38 lines
701 B
Go
package convert
|
|
|
|
import (
|
|
"log/slog"
|
|
"os/exec"
|
|
"strings"
|
|
"sync"
|
|
)
|
|
|
|
type KepubConverter struct {
|
|
mutex sync.Mutex
|
|
available bool
|
|
availableOnce sync.Once
|
|
}
|
|
|
|
func (kc *KepubConverter) Available() bool {
|
|
kc.availableOnce.Do(func() {
|
|
path, err := exec.LookPath("kepubify")
|
|
kc.available = err == nil && path != ""
|
|
})
|
|
|
|
return kc.available
|
|
}
|
|
|
|
func (kc *KepubConverter) Convert(_ *slog.Logger, input string) (string, error) {
|
|
kc.mutex.Lock()
|
|
defer kc.mutex.Unlock()
|
|
|
|
kepubFile := strings.Replace(input, ".epub", ".kepub.epub", 1)
|
|
|
|
cmd := exec.Command("kepubify", "-v", "-u", "-o", kepubFile, input)
|
|
if err := cmd.Run(); err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return kepubFile, nil
|
|
}
|