add tui
This commit is contained in:
parent
25eef75018
commit
f1c08e5a36
8 changed files with 337 additions and 23 deletions
|
@ -87,7 +87,7 @@ func DownloadBook(outDir string, size string, id string, logger Logger) error {
|
|||
return err
|
||||
}
|
||||
|
||||
pdfPath := path.Join(outDir, fmt.Sprintf("%s.pdf", strings.ReplaceAll(id, "/", "_")))
|
||||
pdfPath := path.Join(outDir, fmt.Sprintf("%s-%s.pdf", strings.ReplaceAll(id, "/", "_"), size))
|
||||
logger.Info.Printf("Saving pdf to %s...", pdfPath)
|
||||
|
||||
return ImgDirToPdf(dir, pdfPath)
|
||||
|
|
|
@ -52,7 +52,7 @@ func downloadToFile(filename string, dir string, pageUrl string) error {
|
|||
defer res.Body.Close()
|
||||
|
||||
if res.StatusCode != 200 {
|
||||
return fmt.Errorf("status code error: %d %s", res.StatusCode, res.Status)
|
||||
return fmt.Errorf("status code error: %s", res.Status)
|
||||
}
|
||||
|
||||
_, err = io.Copy(out, res.Body)
|
||||
|
|
|
@ -4,7 +4,10 @@
|
|||
|
||||
package ecload
|
||||
|
||||
import "log"
|
||||
import (
|
||||
"io"
|
||||
"log"
|
||||
)
|
||||
|
||||
type Logger struct {
|
||||
Trace *log.Logger
|
||||
|
@ -12,3 +15,17 @@ type Logger struct {
|
|||
Warning *log.Logger
|
||||
Error *log.Logger
|
||||
}
|
||||
|
||||
func InitLogger(
|
||||
traceHandle io.Writer,
|
||||
infoHandle io.Writer,
|
||||
warningHandle io.Writer,
|
||||
errorHandle io.Writer) Logger {
|
||||
|
||||
return Logger{
|
||||
Trace: log.New(traceHandle, "TRACE: ", log.Ldate|log.Ltime),
|
||||
Info: log.New(infoHandle, "INFO: ", log.Ldate|log.Ltime),
|
||||
Warning: log.New(warningHandle, "WARNING: ", log.Ldate|log.Ltime),
|
||||
Error: log.New(errorHandle, "ERROR: ", log.Ldate|log.Ltime|log.Lshortfile),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue